I’ve seen people using min() and max() css functions instead max-width or min-width props like that:
width: min(440px, 100%);
Instead of classic:
width: 440px;
max-width: 100%;
Which is better? I mean, is any performance caveat using min() or max() or is it good to use?
In my case, I think the max-width
way is more understandable than min()
function, what do you think?
Thanks
2
Answers
In the first case,
min()
is a function will let you "set the smallest (most negative) value from a list of comma-separated expressions as the value of a CSS property value." (MDN).This can be applied to different properties to select the minimum value across a set of values – in particular useful if you want to set an absolute to a property, that will be updated with a relative value under specific conditions.
In the second case, if width is smaller than
min-width
or larger thanmax-width
, then this option (min/max-width
) will be applied as value. It is a property concerning width specifically, setting an arbitrary value for that matter.They are two different things. Using for instance
min()
to implicitly definemin/max-width
, does not make them the same thing.As far as I can see, they give the same result.