Variants and sizes
Adding custom variants
Most of Mantine components support variant
prop, it can be used in CSS variables resolver,
and it is also exposed as data-variant="{value}"
attribute on the root element of the component.
The easiest way to add custom variants is to add styles that use [data-variant="{value}"]
.
Example of adding a new variant to the Input component:
underline
variant styles are addedfilled
variant is a default variant – you do not need to define any additional styles for it
Note that you can add custom variants to every Mantine component that supports Styles API even if there are no variants defined on the library side.
Overriding existing variants styles
Apart from adding new variants, you can also override existing ones, for example, you can change the
filled
variant of the Input component with.input[data-variant="filled"]
selector.
variantColorResolver
Button, Badge, ActionIcon and other
components support custom variants with variantColorResolver
– it supports both changing colors and adding new variants. Note that theme.variantColorResolver
is
responsible only for colors, if you need to change other properties, use data-variant
attribute.
Sizes with components CSS variables
You can add custom sizes to any component that supports size
prop by providing a custom
CSS variables resolver, usually it is done in theme.components
:
Sizes with data-size attribute
Every component that supports size
prop exposes it as data-size="{value}"
attribute on the root element.
You can use it to add custom sizes:
Sizes with static CSS variables
Mantine components sizes are defined with CSS variables (usually on root element), for example, ActionIcon component has the following CSS variables:
You can override these values with Styles API or add new sizes values:
Note that some components have more than one CSS variable for size, for example, the Button component has the following CSS variables:
Usually, it is more convenient to use data-size
attribute or vars
on theme
to customize sizes in this case.