Theme functions
Mantine theme provides several functions that can be used to simplify writing styles.
All functions available at fn object: theme.fn.functionName()
.
Accessing theme functions
You can use theme functions wherever Mantine theme is available. There are 4 main ways to work with theme:
- createStyles function
sx
component prop
styles
component prop
useMantineTheme
hook
focusStyles
All Mantine components have custom focus ring styles which are based on :focus-visible
pseudo-class. It is important to keep styles consistent across all of your application components and you should
include Mantine focus styles to your custom interactive elements. focusStyles
function lets you spread Mantine focus styles
without providing any additional parameters:
fontStyles
With fontStyles
function you can add font styles from your Mantine theme to any element.
Function returns font-family and font-smoothing styles:
smallerThan and largerThan
smallerThan
and largerThan
function can help you write responsive styles with theme.breakpoints
:
You can use both functions as a replacement for regular media query syntax in createStyles
function, styles
and sx
props:
linearGradient and radialGradient
linearGradient
and radialGradient
can be used to generate simple gradients with equal colors distributions.
If you need anything more complex – you will need to write it from scratch:
cover
cover
function returns styles to fully cover parent element:
lighten and darken
lighten
and darken
functions can be used to lighten or darken a color by a given percentage.
Both functions work with hex, rgb and rgba formats and always return color in rgba format:
rgba
rgba
function converts color to rgba format with given alpha channel: