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
Use progressive maxWidth scale #701
Conversation
565b8db
to
4ed557e
Compare
I usually find that the current values for the maxWidth scale aren't too useful for me, and the image you posted demonstrates why pretty well. It's hard to design things that scale relationally when the scale is constant - I often find that I can't fine-tune or find the necessary values with the existing, constant, scale requiring me to add my own maxWidth values. I'm not sure that the proposed 1.x scale would solve all of my problems, but I do believe it is definitely a more sensible default as I could see myself adding fewer custom values than I do now. This has my non-authoritative approval ;) |
I'm super new to Tailwind here (so forgive me if this is crazytalk!), but is this something that it might make sense to make user-configurable? For example, user sets some kind of So, doing nothing will make whatever the current setup is available, specifying If made generic enough, maybe this would be applicable to all things that supported range sizing like fonts and such? |
If scale ratio will be predefined, then it's too opinionated and doesn't make sense to me. Why I should stick with particular predefined settings, and how to remember them? It's ok for Typography, but not clear why |
The max width I usually need most often is something like |
These would just be the default values, and of course can be completely customized just like everything else in Tailwind by specifying the values you want for your own project in your config file: module.exports = {
theme: {
maxWidth: {
// Your values go here...
},
},
} |
I noticed this morning that this maxWidth scale actually already includes every default breakpoint except I've opened another PR proposing changing that breakpoint back to 576px to match this new maxWidth scale, but I'm still not sure it's the best solution. Here's what I wrote there as I think it's equally relevant to this conversation:
Would love any input/ideas 👍 |
@michaelmoussa Hey and welcome! Definitely an interesting idea, but I think the most flexible approach is to allow people to customize the entire scale directly and arbitrarily like we already do vs. trying to create an abstraction around it that tries to generate values. Appreciate the input though 👍 |
I think this is a strong case for using numeric naming system and free up the t-shirt size names to map directly to screen sizes. For example:
Then, there's no need to specify Only downside is that this might lead to some confusion with the numbered width utilities. For example Remember also that if anyone changes their base font-size while max-widths are in |
@AlexVipond Thanks so much for the well-considered feedback 👍 I agree in a perfect world a linear numeric scale is a really nice idea, I like that idea even for the regular margin/padding scales too but have opted not to explore it for 1.0 because there are advantages to the proportional scale too, and the cost of that breaking change would be pretty high 😕
This is a really great point! I think for this reason there's really no point in trying to have the maxWidth scale contain the default breakpoints, it makes a lot more sense for them to exist as extra values on top of the scale 👍 The only question then is how does that affect the scale 🤔 Do we really need values all the way up to 1280/1440 if we aren't concerned about matching breakpoints anymore? Maybe we only need stuff in the ~300-900 range? Going to study some existing interfaces and see what sort of examples I can find. |
@AlexVipond I actually really like the idea of having the numeric scale and the breakpoint scale separate like that. @adamwathan couldn't this also automatically populate the breakpoint scales based on the configured breakpoints that Tailwind already knows about? Seems like it could be an elegant solution. |
Yeah we can autopopulate based on the breakpoints easily, that's no problem. I hesitate to use a linear numeric scale because we don't do that anywhere else in Tailwind. The internal rule has always sort of been "numeric scales are proportional, t-shirt size scales are progressive". For that reason I would probably still stick with |
Somehow I skipped 6xl? I'm an idiot.
Now that I plan to add max-w-screen-* variations, I don't think these huge options provide any real value.
Removed the largest two options (7xl and 8xl) since I plan to add screen-* variations and don't want things to get bloated, especially since I don't think those values are really valuable with Also fixed a dumb error where I went straight from 5xl to 7xl, so now the scale goes from xs to 6xl. New scale: |
@adamwathan thanks! To be clear, I'm suggesting using proportional numeric naming for max-width, just like you do with width and height. Mostly because it just feels a little awkward to get all the way up to 9xl (that's one hell of a t-shirt!) and whenever I add values, stuff like (To be even clearer I'm probably going to customize my config to use linear numeric naming on everything 🤫) |
LGTM although I'd go with a numeric proportional scale. Even if it doesn't include all values the |
@AlexVipond Sorry I think we are probably using the word proportional differently — in your example you listed these values: maxWidth: {
'1': '20rem',
'2': '24rem',
'3': '28rem',
'4': '32rem',
} ...which in my mind aren't proportional, at least not in the way that the spacing/width/height scale is.
@hacknug Do you mean something like this? maxWidth: {
80: '20rem',
96: '24rem',
112: '28rem',
128: '32rem',
144: '36rem',
168: '42rem',
192: '48rem',
224: '56rem',
256: '64rem',
288: '72rem',
}, It would be consistent with the spacing scale but seems really hard to learn those numbers |
Yup, you're right. Don't mind me 😄 |
When do you plan to work in the screen-* variations? |
@wjthomas9 and anyone else watching this—with the new config file, you can easily create breakpoint utilities on your own:
|
This PR changes the default maxWidth scale from a linear (jumps of 10rem) scale to a progressive scale, where the values towards the bottom end are closer together and the values towards the top are more spread out.
It also increases the total number of values from 9 to 12.
Old scale on left, new scale on right (click to zoom):
You can also see the values at their actual size in this CodePen:
Preview the new maxWidth scale in the browser
The maxWidth utilities are pretty important to get right because they are (IMO) the best way to create "fixed" width blocks in a UI, like the first card in this screenshot from Netlify:
...or this sign in form taken from Baremetrics:
They are also useful for constraining a block of content, like this paragraph from Stripe's homepage:
I think the values in this new scale are pretty good, but one thing I'm unsure about is if we should have values that match all of the default breakpoints as well, and if so, should they just be part of the scale, or given different names?
I find it is very common in my own projects to create utilities like
max-w-screen-md
that sets an element's max width to match the medium screen size for example. In fact, if those values existed, thecontainer
component would really just be a shortcut for:...so I think it kind of makes sense for those values to exist if you ever needed to break out of some of the behavior provided by the container and drop to a lower level primitive.
So I'm wondering if people have opinions on that, how useful they would find it based on what they've done on previous projects, and how adding those would impact this new scale. Does this new scale really need to go all the way up to 9xl if we are adding the screen size options?
Any input and examples of when/how you use max-width utilities would be much appreciated.