Spacing utilities to px instead of rem by default #13323
Replies: 5 comments 10 replies
-
One of possible use cases for rem — scaling ui on huge screens. :root {
font-size: max(calc(12px + 1vmin), 18px);
} depends on design and other stuff, but sometimes it makes site more usable |
Beta Was this translation helpful? Give feedback.
-
This issue has exactly nil chance of being resolved purely because it will be an enormous breaking change. Because Tailwind supports arbitrary values ( Even though I don't agree with some of your points, I can understand why you're frustrated about it. My suggestion would be to use a custom config that suits your needs. All tools are built based on the authors' preferences, and the beauty of open source is that if you don't like it - you can always change it locally. |
Beta Was this translation helpful? Give feedback.
-
If the user has a huge screen, they should probably change the scale of everything either in some display settings in their operating system or as a default zoom in the browser. if you really need to use font-size based zoom on your website, you can revert back to rem spacing units in ~2 minutes. We're talking about the defaults, so the point is, that if you find 100 random websites which use Tailwind, my proposed change is going to improve at least 99 of them without the need to touch anything (other than a tailwind update of course). |
Beta Was this translation helpful? Give feedback.
-
I don't think it would be a breaking change at all. Using
I doubt this 2px padding difference can be considered a breaking change. Also this is what users should expect to happen when they change the default font-size. And this is what developers who know what rem units were invented for should expect to happen with tailwind. And if you're really bothered by this change, you can revert back to rem spacing units in about 2 minutes or better yet, just change Edit: forgot to reply to this part
I use a custom config of course but this is not the point. The point is, that there is an important accessibility setting in all browsers, the default font-size, but because most webdevelopers misuse the rem units this setting is pretty much useless and users don't even change it because of it. If you plan to use rem units for scaling elements other than font-sizes, you should be the one who has to change the default config. Edit 2: Also your If we stay with the icon button example, the correct way to create it is to either use an svg inside with a width and height of 1em, or to use an icon font. In both cases the size of the icon will depend on its parent's font-size which hopefuly is using rem units. |
Beta Was this translation helpful? Give feedback.
-
Lots of good feedback here and I appreciate it! This is something I've thought about a lot and I worry it's just pretty complicated to come up with a universal approach that's going to work for everyone. I really liked this post on the topic: https://www.joshwcomeau.com/css/surprising-truth-about-pixels-and-accessibility/ The thing that stood out to me was the point that the margin between paragraphs should likely be But in other cases margin makes more sense to be Similarly sometimes There are also situations where you have a sidebar built with So I dunno, I don't know how to wave a magic wand here and make it easy for every user to always do the best thing without being deliberate about it themselves. That combined with the fact that this would be a breaking change leaves me inclined to just leave things as they are by default, and let the people who are inclined to really go deep with this stuff handle that themselves in their own projects. Everything in the framework is customizable so you can totally switch to pixels if you want by changing your spacing scale. Again I agree with all your points generally and value the feedback, I just don't think it's as simple of a change to get right on a framework level as it sounds on the surface. |
Beta Was this translation helpful? Give feedback.
-
Discussed in #13098
Originally posted by KocsisGabor March 6, 2024
Relevant but closed issue on this topic. #800
I'm honestly surprised, I must assume there's something I don't know because choosing rem for spacing does not make any sense to me.
Apparently rem was chosen because it allows proportional resizing of everything, in other words, it allows us to zoom, exactly like how every browser allows their every user to zoom.
Is there a website which relies on the root font-size to change the zoom? I doubt it, it seems pointless to me.
Why do we have rem units?
If the websites are using rem units for font-sizes, then the users can change the default browser font-size in case they have poor eyesight, which allows them to consume content easier on the internet. This is literally the only reason we have rem units!
Most web developers probably have perfect eyesight because changing the default browser font-size most of the time either has no effect or it zooms the websites. This makes this setting rather useless since pretty much every browser has a dedicated default zoom feature anyway, and the browser zoom can easily be overwritten by the user, for example, with ctrl+wheel.
I don't really understand why most developers use this unit incorrectly. The only change needed when the rem units became supported was to change some font-size to rem instead of pixels. This is pretty much a ~30 line change in CSS for complex websites. Instead, the developers decided to either overwrite the root font-size so they can pointlessly use rem units just because they read somewhere that they should, or they don't overwrite it but use rem everywhere again just to lose its intended functionality.
Why did the Tailwind developers think that it would be a good idea to change the border width on a button, a shadow under a card, or the distance between nav items just because the user has changed the default font-size?
What would be the effect of this change?
Currently, changing the browser default font-size just zooms exactly like how the browser can zoom.
If the spacing units were to change to pixels, nothing would change if the user didn't touch the default font-size. Pretty much every Tailwind website would look exactly the same. However, if the user has changed the default font-size, for example, to 20 pixels, this would mean that most Tailwind websites would show text in 125% size instead of zooming the websites to 125%. This should be the intended effect of changing the default font-size, not a redundant zoom.
Tailwind is popular, so if the spacing units were to change to pixels instead of rem in Tailwind, that would instantly solve this problem on countless websites.
Would this break websites? Maybe, there are surely websites where the root font-size has been overwritten for some reason, but pretty much all of these websites use rem incorrectly. There are probably also websites where they overwrite the root font-size but also allow the user to change it with a button or something. Currently, this button in these websites zooms the content, and after the change, it would have the probably intended effect of changing the font-size (this is a positive effect in my opinion).
The users who decide to change the default font-size would have a better experience on the internet.
What needs to be changed?
The default config should have this theme.spacing property:
Most Tailwind users need to change nothing if this change goes live. Those developers who have actually affected website needs to change their Tailwind config to have the rem spacing values.
Conclusion
Even if we assume that for some reason an unreasonable amount of websites need their interface to zoom when a user has changed the default font-size, this change would still be a positive change because the default should be what's best in most cases, not what can be useful in some weird edge cases especially when it takes about ~1 minute to change the pixel values to rem for a developer in their own config file.
Important: This change would not affect font-sizes and some few other properties like max-w-md, which would still use rem units. This change would only affect the spacing properties like margin and some other properties like border-width.
Sorry if this was a bit aggressive, I'm just really frustrated that I needed to make this issue at all.
Beta Was this translation helpful? Give feedback.
All reactions