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 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>
)
} This page is Chakra UI v3. extendTheme, colorScheme, Modal, and useToast are the v2 names. Node 20 or newer is required. 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> 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> Breakpoints: base 0, sm 30rem (~480px), md 48rem (~768px), lg 62rem (~992px), xl 80rem (~1280px), 2xl 96rem (~1536px). 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> 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> 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> 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,
}) 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 Wrap next-themes inside ChakraProvider. A provider with only defaultSystem never writes the dark class, so the toggle looks broken. 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. |