How to style HTML5 calendar icon

Asked

Viewed 223 times

2

I have an HTML5 input with type="date", thus:

<input type="date">

Is there any way to change the color of the calendar icon it brings natively? I’ve tried properties like -webkit-calendar-picker-indicator but does not change the icon color, only the font or background.

1 answer

2


OBS: The solution below does not work in the Firefox browser. Check for compatibility in other browsers for this solution. Tests have been done and worked on Google Chrome and Brave browsers.

Thanking @Guilhermenascimento for the observation comment :)


There is a possibility of using the filter and change the colors of the icon in question.

This response is based on that one and that one question and on Soen, which allows you to make a combinations using filter and properties such as invert, sepia, saturate, brightness and hue-rotate. In the example below, changing the values of hue-rotate, can result in different colors.

Examples:

  • To the hue-rotate(20deg), we will have a reddish color:

input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  filter: invert(0.8) brightness(50%) sepia(100%) saturate(10000%) hue-rotate(20deg);
}
<input type="date">

  • To the hue-rotate(240deg), we will have a bluish color for the icon:

input[type="date"]::-webkit-calendar-picker-indicator {
  cursor: pointer;
  filter: invert(0.8) brightness(50%) sepia(100%) saturate(10000%) hue-rotate(240deg);
}
<input type="date">

You can still generate different combinations by changing the properties invert, sepia, saturate, brightness and hue-rotate.

  • 2

    Note that this works on Chrome and probably on Safari, but does not work on Firefox, of course Firefox does not have such an icon, so the solution applied to Chromium/Webklit will work well. So I leave the +1

  • 1

    @Guilhermenascimento did, but since he used the Webkit, I thought the AP might already be aware of that. But I think it’s worth highlighting your observation in the answer.

  • 2

    Has Webkit prefixes that work in Firefox (because "historical questions"). So it’s always good to detail a few things :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.