Theme
The theme object is where you define your application's color palette, type scale, font stacks, breakpoints, border radius values, and more.
Theming with Chakra UI is based on the Styled System Theme Specification
Colors#
Add a theme.colors
object to provide colors for your project. By default these
colors can be referenced by the color
, borderColor
, and backgroundColor
,
fill
, stroke
, styles.
We recommend adding palette that go from 50
- 900
. Use tools like
Smart Swatch, Coolors or Palx to generate
these palette.
Chakra provide a sensible default theme inspired by Tailwind CSS, but you can customize it to fit your design.
Black & White#
Gray#
Red#
Orange#
Yellow#
Green#
Teal#
Blue#
Cyan#
Purple#
Pink#
Typography#
To manage Typography options, the theme object supports the following keys:
fonts
(font families)fontSizes
fontWeights
lineHeights
letterSpacings
Breakpoints#
To configure the default breakpoints used in responsive array values, add a breakpoints array to your theme. These values will be used to generate mobile-first (i.e. min-width) media queries, which can then be used to apply responsive styles.
For example, you can write <Box fontSize={["14px", "16px"]}/>
to make the
fontSize responsive.
Spacing#
The space
key allows you to customize the global spacing and sizing scale for
your project. By default these spacing value can be referenced by the padding
,
margin
, and top
, left
, right
, bottom
styles.
By default, Chakra includes a comprehensive numeric spacing scale inspired by
Tailwind CSS. The values are proportional, so 1 spacing unit is equal to
0.25rem
, which translates to 4px
by default in common browsers.
Mental model: If you need a spacing of 40px
, divide it by 4
. That'll
give you 10
. Then use it in your component.
Name | Space (in rem ) | Pixels | |
---|---|---|---|
0 | 0 | 0px | |
px | 1px | 1px | |
1 | 0.25rem | 4px | |
2 | 0.5rem | 8px | |
3 | 0.75rem | 12px | |
4 | 1rem | 16px | |
5 | 1.25rem | 20px | |
6 | 1.5rem | 24px | |
8 | 2rem | 32px | |
10 | 2.5rem | 40px | |
12 | 3rem | 48px | |
16 | 4rem | 64px | |
20 | 5rem | 80px | |
24 | 6rem | 96px | |
32 | 8rem | 128px | |
40 | 10rem | 160px | |
48 | 12rem | 192px | |
56 | 14rem | 224px | |
64 | 16rem | 256px |
Note: This is rem
units are relative to the root or html font size which
is 16px
by default. Chakra leaves this value unaltered.
Changing the root font size will make the pixel
values above altered and
you'll need to calculate the corresponding pixel value yourself.
The simple calcuation is remValue * rootFontSize = pixelValue
Sizes#
The sizes
key allows you to customize the global sizeing of components you
build for your project. By default these spacing value can be referenced by the
width
, height
, and maxWidth
, minWidth
, maxHeight
, minHeight
styles.
For a component like this: <Box w={4} h={3} />
will generate an empty div
with width set to 1rem
or 16px
and height set to 0.75rem
or 12px
Z-Index#
Chakra provides some zIndex values out of the box to control the stacking order of components.
Icons#
All Chakra icons are stored in the theme object under the icons
key.
See the icons.
You can extend this object to add your own icons. Here are the steps:
- Export the icon's
svg
from Figma, Sketch, etc. - Use a tool like SvgOmg to reduce the size and minify the markup.
- Add the icon to the theme object.
Add the fill=currentColor
attribute to the path
or g
so that when you
this <Icon color="gray.200"/>
, it works correctly.
Configuration reference#
Except for breakpoints, colors, and spacing, all of the keys in the theme object map to one of Chakra's core theme. All of these keys can be replaced or extended.
See the full reference table of properties.