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
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 a palette that ranges from 50
to 900
. Tools like
Smart Swatch,
Coolors or Palx are
available to generate these palettes.
Chakra provides a sensible default theme inspired by Tailwind CSS, but you can customize it to fit your design.
To manage Typography options, the theme object supports the following keys:
fonts
(font families)fontSizes
fontWeights
lineHeights
letterSpacings
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 will be responsive.
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 by4
. That'll give you10
. Then use it in your component.
Name | Space | 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 | |
7 | 1.75rem | 28px | |
8 | 2rem | 32px | |
9 | 2.25rem | 36px | |
10 | 2.5rem | 40px | |
12 | 3rem | 48px | |
14 | 3.5rem | 56px | |
16 | 4rem | 64px | |
20 | 5rem | 80px | |
24 | 6rem | 96px | |
28 | 7rem | 112px | |
32 | 8rem | 128px | |
36 | 9rem | 144px | |
40 | 10rem | 160px | |
44 | 11rem | 176px | |
48 | 12rem | 192px | |
56 | 14rem | 224px | |
60 | 15rem | 240px | |
64 | 16rem | 256px | |
72 | 18rem | 288px | |
80 | 20rem | 320px | |
96 | 24rem | 344px |
The sizes
key allows you to customize the global sizing 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
Chakra provides a set of smooth corner radius values
We recommend trying to solve stacking issues without z-index
. You can read our
recommendations and learn more about
stacking contexts and z-index here.
Chakra provides a minimal set of z-indeces out of the box to help control the stacking order of components.
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.