Change styles based on device and viewport.
Every Sfumato utility class can be applied conditionally at different media breakpoints, which makes it easy to build responsive interfaces right in your HTML.
To ensure things work across breakpoints (e.g. on mobile), make sure you've configured the viewport meta tag in the <head> block of your document:
To add a style that only takes effect at a specific breakpoint, just prefix the utility name with the breakpoint name, followed by a colon:
These work for every utility class in the Sfumato framework, which means you can change any styles at a given breakpoint.
There are five default breakpoints with width values representing common device resolutions:
Styles applied by rules like md:grid-cols-3
will apply at that breakpoint and stay applied at wider breakpoints.
If you need to apply a utility for a specific breakpoint range, stack a responsive variant like md
with a max-*
variant to limit that style to a specific range:
There are seven default adaptive breakpoints with aspect-ratio values representing common device aspect ratios, for more specific targeting:
Container queries are a newer addition to CSS that allow you to apply styles depending on the dimensions of a parent element rather than the whole browser window. This means you can create components that adapt their appearance to the specific space they occupy, making them more flexible and easier to reuse in different layouts.
You can also name your containers for more specific targeting, like when nested.
Container queries can also be specified with ranges:
The supports-[...]
variant is used to style elements based on whether a certain feature is supported in the user's browser.
Use the starting
variant to set the style of an element when it is first rendered in the DOM, or transitions from display: none
to visible:
Similar to arbitrary values, arbitrary variants let you create custom selector variants.
Arbitrary variants are simply formatted strings that represent the selector, wrapped in square brackets.
You can also use at-rules like @supports in arbitrary variants:
For times when you're using the same arbitrary variant more than once, you should consider creating a custom variant using the @custom-variant
directive:
Following are all available standard @media query variants, including max varieties:
Following are all available adaptive design @media query variants, including max varieties:
Following are all available @container
query variants, including max varieties: