Skip to main content
Quick Reference

Chakra UI Cheatsheet

Chakra UI v3 on one page — the provider, tokens, style props, Stack and Grid, buttons, fields, dialogs, toasts, color mode, and the v2 names that interviews still ask about.

10 sections 10 tables 15 code snippets

Install & wrap the app

Packages

npm i @chakra-ui/react @emotion/react

One provider at the root

import { ChakraProvider, defaultSystem } from "@chakra-ui/react"

export default function App() {
  return (
    <ChakraProvider value={defaultSystem}>
      <Button colorPalette="teal">Save</Button>
    </ChakraProvider>
  )
}

What you actually added

PieceRole
@chakra-ui/reactThe components. Button, Input, Dialog, Stack
@emotion/reactThe runtime style engine. @emotion/styled is not part of a v3 install
ChakraProviderPuts the styling system on context. The prop is value, not theme
defaultSystemThe built-in tokens, recipes, and breakpoints
Snippet CLInpx @chakra-ui/cli snippet add writes a Provider, a toaster, and a color-mode helper

This page is Chakra UI v3. extendTheme, colorScheme, Modal, and useToast are the v2 names. Node 20 or newer is required.

Tokens

A brand color

import { createSystem, defaultConfig } from "@chakra-ui/react"

const system = createSystem(defaultConfig, {
  theme: {
    tokens: {
      colors: {
        brand: {
          500: { value: "#319795" },
        },
      },
    },
  },
})

<ChakraProvider value={system}>
  <Button bg="brand.500" color="white">Save</Button>
</ChakraProvider>

Names you will look up

TokenMeaning
{ value: "..." }Every custom token is an object. A bare string is the v2 shape
brand.500A palette step. Use it in bg or color
colorPaletteA component prop. teal paints solid, contrast, and hover from that palette
bg.muted / fg.mutedSemantic colors. They follow light and dark
p="4"A spacing token. On the default scale, 4 is 1rem
Semantic keysA custom palette used as colorPalette also needs solid, contrast, fg, muted, subtle, emphasized, and focusRing

Style props

Props, then a breakpoint

<Box
  p={{ base: "2", md: "6" }}
  bg="bg.muted"
  color="fg"
  rounded="md"
  _hover={{ bg: "bg.emphasized" }}
>
  Books
</Box>

A variant that does not leak

<Button variant={{ smDown: "solid", md: "outline" }}>
  Save
</Button>

The scale

PropEffect
p, px, m, gapSpacing tokens. An object makes the value responsive
bg, colorA palette path such as teal.500, or a semantic path such as fg.muted
roundedA radius token. md, lg, full
_hover, _focusPseudo styles. The underscore is the condition
{ base, md }Mobile first. md applies from that breakpoint up
smDown, md, lgOnlyA bounded range. Prefer this on variant so the small-screen recipe does not leak upward

Breakpoints: base 0, sm 30rem (~480px), md 48rem (~768px), lg 62rem (~992px), xl 80rem (~1280px), 2xl 96rem (~1536px).

Stack, Box & Grid

A row, then two columns

<Stack direction={{ base: "column", md: "row" }} gap="4">
  <Button>Save</Button>
  <Button variant="outline">Cancel</Button>
</Stack>

<Grid templateColumns={{ base: "1fr", md: "1fr 1fr" }} gap="4">
  <Box p="4" bg="bg.muted" rounded="md">One</Box>
  <Box p="4" bg="bg.muted" rounded="md">Two</Box>
</Grid>

Layout pieces

ComponentUse
BoxA styled div. Style props land here
StackFlex plus gap. direction is column by default
HStack / VStackA Stack locked to a row or a column
gapThe space between children. The v2 prop was spacing
GridtemplateColumns and gap. Responsive values are objects
ContainerA centered column with a max width

Buttons

Looks and a loading state

<Button colorPalette="teal">Save</Button>
<Button variant="outline">Cancel</Button>
<Button variant="ghost">Later</Button>
<Button variant="plain">Details</Button>
<Button loading colorPalette="teal">Saving</Button>

Props that changed in v3

v3v2 name
colorPalette="teal"colorScheme. The default palette is gray
variant="solid"The default. Also subtle, surface, outline, ghost, plain
variant="plain"The old variant="link"
loadingisLoading. The spinner sits in the button
disabledisDisabled
Icon as a childleftIcon and rightIcon. Put the icon next to the label

Fields

Label, input, and the error

const [title, setTitle] = useState("")

<Field.Root invalid={title.length === 0} required>
  <Field.Label>Title</Field.Label>
  <Input
    value={title}
    onChange={(event) => setTitle(event.target.value)}
  />
  <Field.HelperText>Shown on the card.</Field.HelperText>
  <Field.ErrorText>Title is required.</Field.ErrorText>
</Field.Root>

The rename

v3v2 name
Field.RootFormControl
Field.LabelFormLabel
Field.HelperTextFormHelperText
Field.ErrorTextFormErrorMessage. It renders only while invalid is true
invalid / requiredisInvalid / isRequired. Put them on Field.Root
Fieldset.RootA group of radios or checkboxes. The old pattern was FormControl as="fieldset"

Dialog

Open is yours

<Dialog.Root
  open={open}
  onOpenChange={(details) => setOpen(details.open)}
>
  <Portal>
    <Dialog.Backdrop />
    <Dialog.Positioner>
      <Dialog.Content>
        <Dialog.Header>
          <Dialog.Title>Delete book</Dialog.Title>
        </Dialog.Header>
        <Dialog.Body>This cannot be undone.</Dialog.Body>
        <Dialog.Footer>
          <Dialog.ActionTrigger asChild>
            <Button variant="outline">Cancel</Button>
          </Dialog.ActionTrigger>
          <Button colorPalette="red">Delete</Button>
        </Dialog.Footer>
      </Dialog.Content>
    </Dialog.Positioner>
  </Portal>
</Dialog.Root>

The pieces

PartRole
Dialog.RootThe v2 Modal. open replaces isOpen
onOpenChangeReceives { open }. This replaces onClose
Dialog.BackdropThe overlay. The v2 name was ModalOverlay
Dialog.PositionerPlaces the panel. Content without it has no position
Dialog.ActionTriggerCloses the dialog. asChild merges onto your button
placement="center"The v2 isCentered

Toast

Create one, mount the host once

toaster.create({
  title: "Saved",
  description: "The book is in the catalog.",
  type: "success",
})

Where it sits

const toaster = createToaster({
  placement: "top-end",
  max: 3,
})

How toast works in v3

FactWhy it matters
toaster.createThe call. useToast is gone
<Toaster />Render the snippet host once, near the root. No host means no toast
createToasterPlacement, max, and overlap live here, not on the provider
placementtop-end is the usual corner. Pick one for the app
typesuccess, error, warning, info, or loading
closableAdds a close button on that toast

Color mode & links

The class lives in next-themes

import { useTheme } from "next-themes"

const { resolvedTheme, setTheme } = useTheme()

<Button
  onClick={() =>
    setTheme(resolvedTheme === "dark" ? "light" : "dark")
  }
>
  Toggle
</Button>

A link that keeps its styles

<Link asChild>
  <a href="/books">Books</a>
</Link>

What replaced the v2 helpers

v3v2 name
ThemeProvider from next-themesColorModeProvider. Set attribute="class"
useThemeuseColorMode and useColorModeValue
class="dark" on the rootColorModeScript
asChildThe as prop for swapping in Next.js Link. @chakra-ui/next-js is gone
target and relisExternal on Link

Wrap next-themes inside ChakraProvider. A provider with only defaultSystem never writes the dark class, so the toggle looks broken.

Interview traps

Traps worth memorising

TrapWhat happensPrefer
theme={theme} on the providerv3 has no theme propvalue={system} from createSystem
A token written as a stringThe scale ignores it500: { value: "#319795" }
colorScheme="blue"That name is also a native HTML attribute, so the recipe never sees itcolorPalette="blue"
colorPalette on a custom color with no semantic tokensSolid and contrast stay emptyAdd solid, contrast, fg, and the rest
<Stack spacing="4">spacing is not the v3 propgap="4"
<Modal isOpen>There is no Modal exportDialog.Root with open, plus Backdrop and Positioner
useToast()The hook was removedtoaster.create, and one <Toaster />
useColorModeRemoved with the color-mode packageuseTheme from next-themes
variant={{ base: "solid", md: "outline" }}The base recipe can leak into the larger breakpoint{ smDown: "solid", md: "outline" }
leftIcon={<Icon />}The prop is gone, so the icon never mountsThe icon as a child, before the label
framer-motion in the installv3 does not use it@chakra-ui/react and @emotion/react
Field.ErrorText with no invalidThe message stays unmountedinvalid on Field.Root

The provider prop

<ChakraProvider value={defaultSystem}>

The stack prop

<Stack gap="4">

How to use this page: install the two packages, wrap the root in ChakraProvider, and render one teal button. Then add a Field whose error shows while the title is empty, and open a Dialog from a second button.