-
Notifications
You must be signed in to change notification settings - Fork 226
Style date placeholders to match standard placeholders #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I spent an absolutely ridiculous amount of time looking into this many months ago for a personal project. I came to the conclusion that it's not simple. There are solutions but they all have problems. :/ I created a Tailwind Play with comments in the CSS and a preview of what works and what does not: https://play.tailwindcss.com/IV31S1G6iv?file=css |
Hey! So I just spent more time that I'd like to admit trying to figure this out, and I've ultimately come to the unfortunate conclusion that this can't be fixed in Safari. Let me walk you through what I've learned... What I've come to realize is that browsers don't consider the date input empty state "value" (which is "YYYY-MM-DD" in Chrome and Firefox, and the current date in Safari) to be a placeholder, even though it very much has a placeholder vibe to it. Because it's not a placeholder, it can't be styled using the So, what can we do? Well, before we get into Safari, let's start by looking at Chrome and Firefox. These browsers always show the "YYYY-MM-DD" empty value in the same color as the date input's text color. So, applying a text color like <input type="date" class="text-red-500"> ![]() Trying to apply a placeholder color results in no changes to the "YYYY-MM-DD" empty value: <input type="date" class="placeholder:text-red-500"> ![]() There really isn't any concept of a date input placeholder in Chrome and Firefox. Where this gets complicated is in Safari. Safari doesn't show "YYYY-MM-DD" for the empty state, but instead shows today's date, but in a muted placeholder style: ![]() Like in Chrome and Firefox, adding a placeholder is not possible but adding a text color is: <input type="date" class="text-red-500"> ![]() However, when you set a text color, Safari automatically adjusts the text brightness to make sure that the default date input (today's date) is muted enough, making sure to distinguish it from a real value. However, you have no control over the exact color that Safari chooses here. It has some type of algorithm and metrics it uses to set this, and despite all my best efforts I was unable to get it to use the placeholder color of my choosing. Basically Safari takes whatever color you set for the date input text color, and then reduces it by about 50%. Even if you set it to straight up black, it's still pretty muted: ![]() And what's really weird is that, depending on the color you choose, it might even just straight up throw that away and use blue instead: <input type="date" class="text-slate-950"> ![]() Using the
|
This has been a wild ride, I could feel the "I've got it!" excitement rise and fall reading through all that. Thanks for looking into this and sharing @reinink! |
My solution based on previous work here and more experiments.
The next part requires toggling a 'js' and Here's the pen https://codepen.io/leevigraham/pen/VwRpRpv This is non tailwind example but I'm sure toggling tailwind classes could achieve the same thing. |
Just deal with it looking bad or use a JS-based date picker :/ The web sucks! |
The placeholders on date inputs don't respect the standard placeholder attribute.
It would be great if we could have the pseudo elements styled so they match the placeholder e.g. changing
to
There's a bit more to it (e.g. the firefox placeholders)
The text was updated successfully, but these errors were encountered: