Variants and sizes
Adding custom variants
Most Mantine components support the variant prop. It can be used in CSS variables resolver,
and it is also exposed as a 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:
underlinevariant styles are addedfilledvariant is the 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 the 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
filledvariant of the Input component with.input[data-variant="filled"]selector.
Custom variants types
You can define types for custom variants by creating a mantine.d.ts file
in your project and extending the {x}Props interface with the new variant type.
Example of adding a custom variant type to the Button component:
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 the data-variant attribute.
Sizes with components CSS variables
You can add custom sizes to any component that supports the size prop by providing a custom
CSS variables resolver. Usually this is done in theme.components:
Sizes with data-size attribute
Every component that supports the size prop exposes it as a data-size="{value}" attribute on the root element.
You can use it to add custom sizes:
Sizes with static CSS variables
Mantine component sizes are defined with CSS variables (usually on the root element). For example, the ActionIcon component has the following CSS variables:
You can override these values with the Styles API or add new size 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 the data-size attribute or vars on the theme
to customize sizes in this case.