How Mantine colors are defined and used
New colors are added to the theme.colors
object. Each color must have 10 shades from lightest to darkest.
Colors specified in theme.colors
are available in all components that support
color
prop.
theme.primaryColor
determines which color from theme.colors
is used as default color
in most components that support color
prop.
theme.primaryShade
determines which shade from theme.colors[color]
is used
as default color in components with filled variant.
Why is it required to have 10 shades per color?
Mantine components have different variants and support light and dark color schemes. Having 10 shades per color allows maintaining consistent colors with proper contrast and brightness levels across all variants and color schemes.
For example, Button component has filled
and light
variants which use different shades of theme.colors
depending on
color scheme:
In the above example:
- Filled button:
- background in light color scheme:
blue[6]
- hover background in light color scheme:
blue[7]
- background in dark color scheme:
blue[8]
- hover background in dark color scheme:
blue[9]
- background in light color scheme:
- Light button:
- background in light color scheme:
blue[0]
- hover background in light color scheme:
blue[1]
- text color in light color scheme:
blue[6]
- background in dark color scheme:
color-mix(in srgb, blue[6], transparent 12%)
- hover background in dark color scheme:
color-mix(in srgb, blue[6], transparent 15%)
- text color in dark color scheme:
blue[4]
- background in light color scheme:
Can I have just one shade per color?
If you do not plan to use light variant, support different colors for
light/dark color schemes, and you do not rely on color changes for hover
effects, you can define just one shade per color with colorsTuple
function:
Can I have more that 10 shades per color?
Yes, it is possible to define more than 10 shades per color, but
Mantine components will use only the first 10 of them. Other colors
values will be available in theme.colors
object and as CSS variables,
for example var(--mantine-color-blue-11)
.