Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of Chrome's calendar icon in HTML Date Input

I am having some difficulty styling the HTML 5 Date input in Chrome.

Using mark up such as <input type="date" max="2020-06-03" value="2020-06-01">, with some background and font color styling in CSS, renders in Chrome as:

enter image description here

I would like to make the calendar icon on the right hand side white, so it matches the color of the text.

::-webkit-calendar-picker-indicator looked like a possible candidate. Setting the background color on this changes the color behind the icon (as expected). However I can't find any parameter that has an effect on the icon color itself.

like image 760
peteredhead Avatar asked Jun 02 '20 22:06

peteredhead


People also ask

How do I change the color of my calendar icon?

Change Calendar Color In the list of calendars on the left side of the screen, hover your cursor over the desired calendar > Click the "Options" icon (3 stacked dots). From the resulting menu, choose the desired color from the color palette. the calendar color is changed.

How do I change the color of a calendar in CSS?

One way to change the calendar background color is to choose a different form theme, at Edit Form → Settings → Style → Global. Replace #123456 with the desired hex color.

How do I change the date format in HTML?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.


4 Answers

I've managed to work around it for now using a CSS filter to invert the black color to white

::-webkit-calendar-picker-indicator {
    filter: invert(1);
}

However this feels quite fragile and far from ideal.

like image 84
peteredhead Avatar answered Oct 11 '22 02:10

peteredhead


The Shadow DOM style sets a background-image which can not be interacted with in CSS (except for filter). One option is to replace the whole image where you can set any fill color and this method will be forward-compatible in case Chrome decides to inherit the icon color from color later on, at the cost of having a "hardcoded" icon:

::-webkit-calendar-picker-indicator {
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="15" viewBox="0 0 24 24"><path fill="%23bbbbbb" d="M20 3h-1V1h-2v2H7V1H5v2H4c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 18H4V8h16v13z"/></svg>');
}
like image 22
silverwind Avatar answered Oct 11 '22 03:10

silverwind


Another way, is by setting the "color-scheme" to dark.

input {
  color-scheme: dark;
}
<input type="date" />

FYI: this will also put the popup in dark mode.

like image 56
Nickzn Avatar answered Oct 11 '22 02:10

Nickzn


You can actually get rather creative using the filter property.

  • invert(100%) turns the icon white
  • brightness(50%) makes it gray
  • sepia(100%) saturates it and makes it... sepia
  • saturate(10000%) pumps the saturation up and turns it bright red

After that you can play around with hue-rotate to change the hue. hue-rotate(240deg) turns it blue, hue-rotate(120deg) turns it green etc. If you want to get a really specific color you should check out this question on how to transform black into any given color using only CSS filters.

like image 10
Fredrik Jungstedt Avatar answered Oct 11 '22 03:10

Fredrik Jungstedt