Switch from px to rem for responsive variants? #8378
Replies: 8 comments 3 replies
-
Or maybe ems would be better than rems even? https://danburzo.ro/media-query-units/ |
Beta Was this translation helpful? Give feedback.
-
So I looked into this a lot originally when building Tailwind and at the time, Safari didn’t handle https://adamwathan.me/dont-use-em-for-media-queries/ If that’s all fixed now then we could definitely consider switching for Tailwind CSS v4 some day down the road. If you happen to do some thorough testing I’d definitely be interested in seeing the results 👍🏻 |
Beta Was this translation helpful? Give feedback.
-
Worth noting that if the media-query values were switched to ems by default, then |
Beta Was this translation helpful? Give feedback.
-
Good news, just did some testing and it seems like the bug in Safari is fixed in 15 👍🏻 Here's a demo from Safari 14 (used Browserstack to go back and test): safari-14.mov...and here's the same thing in Safari 15: safari-15.movSo I think we can probably change the defaults to |
Beta Was this translation helpful? Give feedback.
-
There are people who need smaller font sizes (because of limited field of vision) and people who need extremely large font sizes and/or zoom. Respecting users preference of font size is something that is now finally being more widely adopted. But it has its consequences. Using As responsive websites are now standard, there's an easy way to make sure that they look OK with any user font size preference. When you use 🙏 So, please, make the breakpoints use ems in v4 by default. 🙏 I'd also like to add the following personal story and some more information: I actually stopped using ems for media queries for few years and overriding the users font size preference (as having just one is dangerous as I described above) and I was sad about it all the time. I stopped not because of Safari (the observed issue was with rems), but I myself experienced an issue on some notebook with larger pixel density and a touch screen. When using But then I learned how complicated it can be for some users to zoom the site. And by design it¨s per site settings, there is no way how to set a default zoom the browser will use for newly accessed sites. And even if it is acceptable by WCAG that you use px for everything and just zooming works (it would only be an issue with non-responsive site), it's far from optimal. I have no idea if the issue with the In the meantime we have two options.
Also it should be explained on the breakpoints docs page. Keep Up The Good Work! |
Beta Was this translation helpful? Give feedback.
-
Is there a difference between using em and rem in the media queries? |
Beta Was this translation helpful? Give feedback.
-
Do you need someone to open a PR for this change for v4? When is v4 likely to come out? The fact that Tailwind uses px media queries as a default means every site built using the default config could be inaccessible, potentially with critical usability failures (not to mention legal compliance failures) so it needs to be a priority. Let's lead by example and help developers build accessible sites. |
Beta Was this translation helpful? Give feedback.
-
That article is pretty old and is missing the point a bit. The exact pixel
point a layout switches isn’t as relevant. That’s micromanaging. Whereas
using px for media queries means layouts won’t scale correctly for the many
people who change their default font size settings.
More info here:
https://fedmentor.dev/posts/responsive-meaning/
And here:
https://fedmentor.dev/posts/font-size-px/
You can test it out yourself in browser too. See what happens to layouts
when you use px media queries and change font size in browser to 32px or
even 64px then change viewport size.
…On Sat, 11 Jan 2025 at 16:58, Ifeora Okechukwu ***@***.***> wrote:
Hello @adamwathan <https://github.com/adamwathan> , have you taken a look
at this article ?
https://zellwk.com/blog/media-query-units/
—
Reply to this email directly, view it on GitHub
<#8378 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACRDWNZOWK7C3EQKBIW4I232KFEVDAVCNFSM6AAAAABVAEGHZGVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCOBQG42DOOI>
.
You are receiving this because you commented.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Using pixel-values instead of rem-values for media queries often results in a poor experience for people who use text-only zoom (in violation of WCAG Success Criterion 1.4.4). To see an example of what I mean, visit https://tailwindui.com/pricing in Firefox, select "Zoom Text Only" from the View -> Zoom menu, and start zooming in. Here is a screenshot at 150% text-only zoom:
The entire item on the right side is cut off; in fact, it's unreachable because of an ancestor-div with
.overflow-hidden
. Changing the breakpoints'min-width
values to their rem-equivalents fixes this.Should the default
screens
media-queries be changed to rem values? I believe some developers recommend using pixels to sidestep a bug in Safari where normal-zoom doesn't work well with rem-based breakpoints, but A) that was maybe bad advice in the first place, since it comes at the expense of accessibility for all users who zoom text-only (regardless of browser), and B) if I'm not mistaken, that bug has been fixed.Beta Was this translation helpful? Give feedback.
All reactions