Breakpoints
Breakpoints are user-defined key/value pairs that describe the boundaries of screen sizes. There’s no limit to the number of breakpoints; you can define as many as you want.
Register breakpoints
To register your breakpoints, create an object with any keys:
The first breakpoint must start with 0
. This is required to simulate CSS cascading, e.g., everything below 576px (sm
breakoint)
will resolve to xs
breakpoint.
If you use TypeScript you need to override the library’s type:
Finally, to register the breakpoints, call UnistylesRegistry
:
To learn more follow setup guide.
How to use breakpoints?
Any style can change based on breakpoints. To do this, change a value
to an object
:
You can even use it with nested objects like transform
or shadowOffset
:
Breakpoints are also avilable with variants.
Built-in breakpoints landscape
and portrait
Even if you don’t use custom breakpoints, you can still utilize Unistyles’ predefined breakpoints available on mobile devices: portrait
and landscape
.
portrait
will resolve to your device’s width in portrait modelandscape
will resolve to your device’s width in landscape mode
Access the current breakpoint
You can access the current breakpoint with the useStyles
hook:
or with UnistylesRuntime
:
Get registered breakpoints
Access your registered breakpoints object with UnsitylesRuntime
: