# Table of Contents - [Installation | Chakra UI](#installation-chakra-ui) - [Charts | Chakra UI](#charts-chakra-ui) - [Styling | Chakra UI](#styling-chakra-ui) - [Components | Chakra UI](#components-chakra-ui) - [Migration to v3 | Chakra UI](#migration-to-v3-chakra-ui) - [Overview | Chakra UI](#overview-chakra-ui) - [CLI | Chakra UI](#cli-chakra-ui) - [Contributing to Chakra UI | Chakra UI](#contributing-to-chakra-ui-chakra-ui) - [Using Chakra UI in Next.js (App) | Chakra UI](#using-chakra-ui-in-next-js-app-chakra-ui) - [LLMs.txt Documentation | Chakra UI](#llms-txt-documentation-chakra-ui) - [Using Chakra in Remix | Chakra UI](#using-chakra-in-remix-chakra-ui) - [Using Chakra UI in Storybook | Chakra UI](#using-chakra-ui-in-storybook-chakra-ui) - [Using Chakra UI in Next.js (Pages) | Chakra UI](#using-chakra-ui-in-next-js-pages-chakra-ui) - [Using Chakra UI in Shadow DOM | Chakra UI](#using-chakra-ui-in-shadow-dom-chakra-ui) - [Using Chakra in Vite | Chakra UI](#using-chakra-in-vite-chakra-ui) - [useChart | Chakra UI](#usechart-chakra-ui) - [Using Chakra UI in Iframe | Chakra UI](#using-chakra-ui-in-iframe-chakra-ui) - [Chakra Factory | Chakra UI](#chakra-factory-chakra-ui) - [Axis | Chakra UI](#axis-chakra-ui) - [Responsive Design | Chakra UI](#responsive-design-chakra-ui) - [CSS Variables | Chakra UI](#css-variables-chakra-ui) - [Composition | Chakra UI](#composition-chakra-ui) - [Animation | Chakra UI](#animation-chakra-ui) - [Cartesian Grid | Chakra UI](#cartesian-grid-chakra-ui) - [Dark Mode | Chakra UI](#dark-mode-chakra-ui) - [Color opacity modifier | Chakra UI](#color-opacity-modifier-chakra-ui) - [Area Chart | Chakra UI](#area-chart-chakra-ui) - [Conditional Styles | Chakra UI](#conditional-styles-chakra-ui) --- # Installation | Chakra UI Build faster with Premium Chakra UI Components 💎 [Learn more](https://pro.chakra-ui.com?utm_source=chakra-ui.com) Installation ============ How to install and set up Chakra UI in your project [Framework Guide](#framework-guide) ------------------------------------ Chakra UI works in your favorite framework. We've put together step-by-step guides for these frameworks [Next.js\ \ Easily add Chakra UI with Next.js app](/docs/get-started/frameworks/next-app) [Vite\ \ Use Chakra UI in with Vite](/docs/get-started/frameworks/vite) [Stackblitz\ \ Try Chakra UI in Stackblitz sandbox](https://stackblitz.com/edit/chakra-ui-v3) The minimum node version required is Node.20.x [Installation](#installation) ------------------------------ To manually set up Chakra UI in your project, follow the steps below. 1 ### [Install `@chakra-ui/react`](#install-chakra-uireact) npm i @chakra-ui/react @emotion/react 2 ### [Add snippets](#add-snippets) Snippets are pre-built components that you can use to build your UI faster. Using the `@chakra-ui/cli` you can add snippets to your project. npx @chakra-ui/cli snippet add 3 ### [Setup provider](#setup-provider) Wrap your application with the `Provider` component generated in the `components/ui/provider` component at the root of your application. This provider composes the following: * `ChakraProvider` from `@chakra-ui/react` for the styling system * `ThemeProvider` from `next-themes` for color mode import { Provider } from "@/components/ui/provider" function App({ Component, pageProps }) { return ( ) } 4 ### [Update tsconfig](#update-tsconfig) If you're using TypeScript, you need to update the `compilerOptions` in the tsconfig file to include the following options: { "compilerOptions": { "module": "ESNext", "moduleResolution": "Bundler", "skipLibCheck": true, "paths": { "@/*": ["./src/*"] } } } If you're using JavaScript, create a `jsconfig.json` file and add the above code to the file. 5 ### [Enjoy!](#enjoy) With the power of the snippets and the primitive components from Chakra UI, you can build your UI faster. import { Button, HStack } from "@chakra-ui/react" const Demo = () => { return ( ) } [Learn](#learn) ---------------- Watch our official courses and dive into dozens of videos that will teach you everything you need to know about Chakra UI, from basics to advanced concepts. [Contribute](#contribute) -------------------------- Whether you're a beginner or advanced Chakra UI user, joining our community is the best way to connect with like-minded people who build great products with the library. [Next\ \ Migration](/docs/get-started/migration) --- # Charts | Chakra UI Build faster with Premium Chakra UI Components 💎 [Learn more](https://pro.chakra-ui.com?utm_source=chakra-ui.com) Charts ====== Creating beautiful charts with recharts and Chakra UI Charts are designed to look great out of the box, seamlessly integrating with other Chakra UI's theming system. The charts are built on top of [recharts](https://recharts.org) [Installation](#installation) ------------------------------ Run the following command to install the charts and its peer dependencies. npm i @chakra-ui/charts recharts [Usage](#usage) ---------------- 1 ### [Import the charts component](#import-the-charts-component) In most cases, you need to import the `Chart` and `useChart` hook from the `@chakra-ui/charts` package, then combine them with the components `recharts` import { Chart, useChart } from "@chakra-ui/charts" import { Bar, BarChart, XAxis, YAxis } from "recharts" 2 ### [Define chart data](#define-chart-data) Pass the chart data to the `useChart` hook to create a chart instance. Learn more about the [`useChart`](/docs/charts/use-chart) hook. const chart = useChart({ data: [\ { month: "January", value: 100 },\ { month: "February", value: 200 },\ ], }) 3 ### [Render the chart](#render-the-chart) Depending on the chart type you need from the `recharts` library, wrap the chart component within the `Chart.Root` component. {chart.series.map((item) => ( ))} [Customization](#customization) -------------------------------- The charts component is built on top of [Recharts](https://recharts.org) , so you can use all the customization options that Recharts provides. ### [Colors](#colors) The `useChart` hook provides a `color` function that you can use to query semantic colors for the chart component from `recharts`. ### [Formatters](#formatters) The `useChart` hook provides a `formatDate` and `formatNumber` function that you can use to format the date and number respectively. This is useful for formatting the x, y axis labels and tooltips. // format the x-axis labels // format the y-axis labels [Previous\ \ Visually Hidden](/docs/components/visually-hidden) [Next\ \ useChart](/docs/charts/use-chart) --- # Styling | Chakra UI Build faster with Premium Chakra UI Components 💎 [Learn more](https://pro.chakra-ui.com?utm_source=chakra-ui.com) Styling ======= All components are designed to be styled using props. [Concepts](#concepts) ---------------------- After installing Chakra UI, follow these guidelines to learn the key concepts: * [Chakra Factory](/docs/styling/chakra-factory) * [Responsive Design](/docs/styling/responsive-design) * [CSS Variables](/docs/styling/css-variables) * [Dark Mode](/docs/styling/dark-mode) * [Color Opacity Modifier](/docs/styling/color-opacity-modifier) * [Conditional Styles](/docs/styling/conditional-styles) * [Virtual Color](/docs/styling/virtual-color) [Compositions](#compositions) ------------------------------ After understanding the concepts, learn how to use these compositions to avoid repeating styles: * [Text Styles](/docs/styling/text-styles) * [Layer Styles](/docs/styling/layer-styles) * [Animation Styles](/docs/styling/animation-styles) * [Focus Ring](/docs/styling/focus-ring) [Style Props](#style-props) ---------------------------- Style props are the most fundamental way to style your components in Chakra UI. They are basically css styles as props. [Learn more about style props](/docs/styling/style-props/background) [Previous\ \ Sparkline](/docs/charts/sparkline) [Next\ \ Chakra Factory](/docs/styling/chakra-factory) --- # Components | Chakra UI Build faster with Premium Chakra UI Components 💎 [Learn more](https://pro.chakra-ui.com?utm_source=chakra-ui.com) Components ========== Accessible, modern and easy to style UI components. Here's a list of all the components available in the library. [Accordion\ \ Used to show and hide sections of related content on a page](/docs/components/accordion) [Action Bar\ \ Used to display a bottom action bar with a set of actions](/docs/components/action-bar) [Alert\ \ Used to communicate a state that affects a system, feature or page.](/docs/components/alert) [Aspect Ratio\ \ Used to embed responsive videos and maps, etc](/docs/components/aspect-ratio) [Avatar\ \ Used to represent user profile picture or initials](/docs/components/avatar) [Badge\ \ Used to highlight an item's status for quick recognition.](/docs/components/badge) [Bleed\ \ Used to break an element from the boundaries of its container](/docs/components/bleed) [Blockquote\ \ Used to quote text content from an external source](/docs/components/blockquote) [Box\ \ The most abstract styling component in Chakra UI on top of which all other Chakra UI components are built.](/docs/components/box) [Breadcrumb\ \ Used to display a page's location within a site's hierarchical structure](/docs/components/breadcrumb) [Button\ \ Used to trigger an action or event](/docs/components/button) [Card\ \ Used to display content related to a single subject.](/docs/components/card) [Center\ \ Used to center its child within itself.](/docs/components/center) [Checkbox Card\ \ Used to select or deselect options displayed within cards.](/docs/components/checkbox-card) [Checkbox\ \ Used in forms when a user needs to select multiple values from several options](/docs/components/checkbox) [Client Only\ \ Used to render content only on the client side.](/docs/components/client-only) [Clipboard\ \ Used to copy text to the clipboard](/docs/components/clipboard) [Close Button\ \ Used to trigger close functionality](/docs/components/close-button) [Code\ \ Used to display inline code](/docs/components/code) [Collapsible\ \ Used to expand and collapse additional content.](/docs/components/collapsible) [Color Picker\ \ Used to select colors from a color area or a set of defined swatches](/docs/components/color-picker) [Color Swatch\ \ Used to preview a color](/docs/components/color-swatch) [Container\ \ Used to constrain a content's width to the current breakpoint, while keeping it fluid.](/docs/components/container) [DataList\ \ Used to display a list of similar data items.](/docs/components/data-list) [Dialog\ \ Used to display a dialog prompt](/docs/components/dialog) [Drawer\ \ Used to render a content that slides in from the side of the screen.](/docs/components/drawer) [Editable\ \ Used for inline renaming of some text.](/docs/components/editable) [Em\ \ Used to mark text for emphasis.](/docs/components/em) [Empty State\ \ Used to indicate when a resource is empty or unavailable.](/docs/components/empty-state) [Environment Provider\ \ Used to render components in iframes, Shadow DOM, or Electron.](/docs/components/environment-provider) [Field\ \ Used to add labels, help text, and error messages to form fields.](/docs/components/field) [Fieldset\ \ A set of form controls optionally grouped under a common name.](/docs/components/fieldset) [File Upload\ \ Used to select and upload files from their device.](/docs/components/file-upload) [Flex\ \ Used to manage flex layouts](/docs/components/flex) [Float\ \ Used to anchor an element to the edge of a container.](/docs/components/float) [For\ \ Used to loop over an array and render a component for each item.](/docs/components/for) [Format Byte\ \ Used to format bytes to a human-readable format](/docs/components/format-byte) [Format Number\ \ Used to format numbers to a specific locale and options](/docs/components/format-number) [Grid\ \ Used to manage grid layouts](/docs/components/grid) [Group\ \ Used to group and attach elements together](/docs/components/group) [Heading\ \ Used to render semantic HTML heading elements.](/docs/components/heading) [Highlight\ \ Used to highlight substrings of a text.](/docs/components/highlight) [Hover Card\ \ Used to display content when hovering over an element](/docs/components/hover-card) [Icon Button\ \ Used to render an icon within a button](/docs/components/icon-button) [Icon\ \ Used to display an svg icon](/docs/components/icon) [Image\ \ Used to display images](/docs/components/image) [Input\ \ Used to get user input in a text field.](/docs/components/input) [Kbd\ \ Used to show key combinations for an action](/docs/components/kbd) [Link Overlay\ \ Used to stretch a link over a container.](/docs/components/link-overlay) [Link\ \ Used to provide accessible navigation](/docs/components/link) [List\ \ Used to display a list of items](/docs/components/list) [Locale Provider\ \ Used for globally setting the locale](/docs/components/locale-provider) [Mark\ \ Used to mark text for emphasis.](/docs/components/mark) [Menu\ \ Used to create an accessible dropdown menu](/docs/components/menu) [Select (Native)\ \ Used to pick a value from predefined options.](/docs/components/native-select) [Number Input\ \ Used to enter a number, and increment or decrement the value using stepper buttons.](/docs/components/number-input) [Pagination\ \ Used to navigate through a series of pages.](/docs/components/pagination) [Password Input\ \ Used to collect passwords.](/docs/components/password-input) [Pin Input\ \ Used to capture a pin code or otp from the user](/docs/components/pin-input) [Popover\ \ Used to show detailed information inside a pop-up](/docs/components/popover) [Portal\ \ Used to render an element outside the DOM hierarchy.](/docs/components/portal) [Presence\ \ Used to animate the entry and exit of an element while controlled the render behavior](/docs/components/presence) [Progress Circle\ \ Used to display a task's progress in a circular form.](/docs/components/progress-circle) [Progress\ \ Used to display the progress status for a task.](/docs/components/progress) [Prose\ \ Used to style remote HTML content](/docs/components/prose) [QR Code\ \ A component that generates a QR code based on the provided data.](/docs/components/qr-code) [Radio Card\ \ Used to select an option from list](/docs/components/radio-card) [Radio\ \ Used to select one option from several options](/docs/components/radio) [Rating\ \ Used to show reviews and ratings in a visual format.](/docs/components/rating) [Segmented Control\ \ Used to pick one choice from a linear set of options](/docs/components/segmented-control) [Select\ \ Used to pick a value from predefined options.](/docs/components/select) [Separator\ \ Used to visually separate content](/docs/components/separator) [Show\ \ Used to conditional render part of the view based on a condition.](/docs/components/show) [SimpleGrid\ \ SimpleGrid provides a friendly interface to create responsive grid layouts with ease.](/docs/components/simple-grid) [Skeleton\ \ Used to render a placeholder while the content is loading.](/docs/components/skeleton) [Slider\ \ Used to allow users to make selections from a range of values.](/docs/components/slider) [Spinner\ \ Used to provide a visual cue that an action is processing](/docs/components/spinner) [Stack\ \ Used to layout its children in a vertical or horizontal stack.](/docs/components/stack) [Stat\ \ Used to display a statistic with a title and value.](/docs/components/stat) [Status\ \ Used to indicate the status of a process or state](/docs/components/status) [Steps\ \ Used to indicate progress through a multi-step process](/docs/components/steps) [Switch\ \ Used to capture a binary state](/docs/components/switch) [Table\ \ Used to display data in a tabular format.](/docs/components/table) [Tabs\ \ Used to display content in a tabbed interface](/docs/components/tabs) [Tag\ \ Used for categorizing or labeling content](/docs/components/tag) [Text\ \ Used to render text and paragraphs within an interface.](/docs/components/text) [Textarea\ \ Used to enter multiple lines of text.](/docs/components/textarea) [Theme\ \ Used to force a part of the tree to light or dark mode.](/docs/components/theme) [Timeline\ \ Used to display a list of events in chronological order](/docs/components/timeline) [Toast\ \ Used to display a temporary message to the user](/docs/components/toast) [Toggle Tip\ \ Looks like a tooltip, but works like a popover.](/docs/components/toggle-tip) [Tooltip\ \ Used to display additional information when a user hovers over an element.](/docs/components/tooltip) [Visually Hidden\ \ Used to hide content visually but keep it accessible to screen readers.](/docs/components/visually-hidden) [Wrap\ \ Used to add space between elements and wraps automatically if there isn't enough space.](/docs/components/wrap) [Previous\ \ Iframe](/docs/get-started/environments/iframe) [Next\ \ Composition](/docs/components/concepts/composition) --- # Migration to v3 | Chakra UI Build faster with Premium Chakra UI Components 💎 [Learn more](https://pro.chakra-ui.com?utm_source=chakra-ui.com) Migration to v3 =============== How to migrate to Chakra UI v3.x from v2.x [![Migration Guide](/_next/image?url=%2Fimage.png&w=3840&q=75)\ \ Watch the migration livestream (1)](https://www.youtube.com/live/eU0n9egYGzU?si=ejMOxn1pgUH_6Ox-) [![Migration Guide](/_next/image?url=%2Fimage.png&w=3840&q=75)\ \ Watch the migration livestream (2)](https://www.youtube.com/live/Ia9CZS3it4g?si=QfWnChbkHy_qwXJm) warning We recommend using the [LLMs.txt](/docs/get-started/llms) files to make the Chakra UI v3 documentation available to large language models. [Steps](#steps) ---------------- The minimum node version required is Node.20.x 1 ### [Update Packages](#update-packages) Remove the unused packages: `@emotion/styled` and `framer-motion`. These packages are no longer required in Chakra UI. npm uninstall @emotion/styled framer-motion Install updated versions of the packages: `@chakra-ui/react` and `@emotion/react`. npm install @chakra-ui/react@latest @emotion/react@latest Next, install component snippets using the CLI snippets. Snippets provide pre-built compositions of Chakra components to save you time and put you in charge. npx @chakra-ui/cli snippet add 2 ### [Refactor Custom Theme](#refactor-custom-theme) Move your custom theme to a dedicated `theme.js` or `theme.ts` file. Use `createSystem` and `defaultConfig` to configure your theme. **Before** import { extendTheme } from "@chakra-ui/react" export const theme = extendTheme({ fonts: { heading: `'Figtree', sans-serif`, body: `'Figtree', sans-serif`, }, }) **After** import { createSystem, defaultConfig } from "@chakra-ui/react" export const system = createSystem(defaultConfig, { theme: { tokens: { fonts: { heading: { value: `'Figtree', sans-serif` }, body: { value: `'Figtree', sans-serif` }, }, }, }, }) All token values need to be wrapped in an object with a **value** key. Learn more about tokens [here](/docs/theming/tokens) . 3 ### [Update ChakraProvider](#update-chakraprovider) Update the ChakraProvider import from `@chakra-ui/react` to the one from the snippets. Next, rename the `theme` prop to `value` to match the new system-based theming approach. **Before** import { ChakraProvider } from "@chakra-ui/react" export const App = ({ Component }) => ( ) **After** import { Provider } from "@/components/ui/provider" import { defaultSystem } from "@chakra-ui/react" export const App = ({ Component }) => ( ) import { ColorModeProvider } from "@/components/ui/color-mode" import { ChakraProvider, defaultSystem } from "@chakra-ui/react" export function Provider(props) { return ( ) } If you have a custom theme, replace `defaultSystem` with the custom `system` The Provider component compose the `ChakraProvider` from Chakra and `ThemeProvider` from `next-themes` [Improvements](#improvements) ------------------------------ * **Performance:** Improved reconciliation performance by `4x` and re-render performance by `1.6x` * **Namespaced imports:** Import components using the dot notation for more concise imports import { Accordion } from "@chakra-ui/react" const Demo = () => { return ( ) } * **TypeScript:** Improved IntelliSense and type inference for style props and tokens. * **Polymorphism:** Loosened the `as` prop typings in favor of using the `asChild` prop. This pattern was inspired by Radix Primitives and Ark UI. [Removed Features](#removed-features) -------------------------------------- ### [Color Mode](#color-mode) * `ColorModeProvider` and `useColorMode` have been removed in favor of `next-themes` * `LightMode`, `DarkMode` and `ColorModeScript` components have been removed. You now have to use `className="light"` or `className="dark"` to force themes. * `useColorModeValue` has been removed in favor of `useTheme` from `next-themes` note We provide snippets for color mode via the CLI to help you set up color mode quickly using `next-themes` ### [Hooks](#hooks) We removed the hooks package in favor of using dedicated, robust libraries like `react-use` and `usehooks-ts` The only hooks we ship now are `useBreakpointValue`, `useCallbackRef`, `useDisclosure`, `useControllableState` and `useMediaQuery`. ### [Style Config](#style-config) We removed the `styleConfig` and `multiStyleConfig` concept in favor of recipes and slot recipes. This pattern was inspired by Panda CSS. ### [Next.js package](#nextjs-package) We've removed the `@chakra-ui/next-js` package in favor of using the `asChild` prop for better flexibility. To style the Next.js image component, use the `asChild` prop on the `Box` component. To style the Next.js link component, use the `asChild` prop on the ### [Theme Tools](#theme-tools) We've removed this package in favor using CSS color mix. **Before** We used JS to resolve the colors and then apply the transparency defineStyle({ bg: transparentize("blue.200", 0.16)(theme), // -> rgba(0, 0, 255, 0.16) }) **After** We now use CSS color-mix defineStyle({ bg: "blue.200/16", // -> color-mix(in srgb, var(--chakra-colors-200), transparent 16%) }) ### [forwardRef](#forwardref) Due to the simplification of the `as` prop, we no longer provide a custom `forwardRef`. Prefer to use `forwardRef` from React directly. Before: import { Button as ChakraButton, forwardRef } from "@chakra-ui/react" const Button = forwardRef(function Button(props, ref) { return }) After: import { Button as ChakraButton } from "@chakra-ui/react" import { forwardRef } from "react" const Button = forwardRef( function Button(props, ref) { return }, ) ### [Icons](#icons) Removed `@chakra-ui/icons` package. Prefer to use `lucide-react` or `react-icons` instead. ### [Storybook Addon](#storybook-addon) We're removed the storybook addon in favor of using `@storybook/addon-themes` and `withThemeByClassName` helper. import { ChakraProvider, defaultSystem } from "@chakra-ui/react" import { withThemeByClassName } from "@storybook/addon-themes" import type { Preview, ReactRenderer } from "@storybook/react" const preview: Preview = { decorators: [\ withThemeByClassName({\ defaultTheme: "light",\ themes: {\ light: "",\ dark: "dark",\ },\ }),\ (Story) => (\ \ \ \ ),\ ], } export default preview ### [Removed Components](#removed-components) * **StackItem**: You don't need this anymore. Use `Box` instead. * **FocusLock**: We no longer ship a focus lock component. Install and use `react-focus-lock` directly. * **FormControl**: Replace with the `Field` component * **FormErrorMessage**: Replace with the `Field.ErrorText` component Before: This field is required After: This field is required * **AlertDialog** * Replace with the `Dialog` component and set `role=alertdialog` * Set `leastDestructiveRef` prop to the `initialFocusEl` to the `Dialog.Root` component * **Collapse**: Replace with the `Collapsible` component. Before: Some content After: Some content [Prop Changes](#prop-changes) ------------------------------ ### [Boolean Props](#boolean-props) Changed naming convention for boolean properties from `is` to `` * `isOpen` -> `open` * `defaultIsOpen` -> `defaultOpen` * `isDisabled` -> `disabled` * `isInvalid` -> `invalid` * `isRequired` -> `required` ### [ColorScheme Prop](#colorscheme-prop) The `colorScheme` prop has been changed to `colorPalette` **Before** * You could only use `colorScheme` in a component's theme * `colorScheme` clashes with the native `colorScheme` prop in HTML elements **After** * You can now use `colorPalette` anywhere Usage in any component, you can do something like: Some box Some text If you are using custom colors, you must define two things to make `colorPalette` work: * **tokens**: For the 50-950 color palette * **semanticTokens**: For the `solid`, `contrast`, `fg`, `muted`, `subtle`, `emphasized`, and `focusRing` color keys theme.ts import { createSystem, defaultConfig } from "@chakra-ui/react" export const system = createSystem(defaultConfig, { theme: { tokens: { colors: { brand: { 50: { value: "#e6f2ff" }, 100: { value: "#e6f2ff" }, 200: { value: "#bfdeff" }, 300: { value: "#99caff" }, // ... 950: { value: "#001a33" }, }, }, }, semanticTokens: { colors: { brand: { solid: { value: "{colors.brand.500}" }, contrast: { value: "{colors.brand.100}" }, fg: { value: "{colors.brand.700}" }, muted: { value: "{colors.brand.100}" }, subtle: { value: "{colors.brand.200}" }, emphasized: { value: "{colors.brand.300}" }, focusRing: { value: "{colors.brand.500}" }, }, }, }, }, }) Read more about it [here](/guides/theming-custom-colors) . ### [Gradient Props](#gradient-props) Gradient style prop simplified to `gradient` and `gradientFrom` and `gradientTo` props. This reduces the runtime performance cost of parsing the gradient string, and allows for better type inference. **Before** **After** ### [Color Palette](#color-palette) * Default color palette is now `gray` for all components but you can configure this in your theme. * Default theme color palette size has been increased to 11 shades to allow more color variations. **Before** const colors = { // ... gray: { 50: "#F7FAFC", 100: "#EDF2F7", 200: "#E2E8F0", 300: "#CBD5E0", 400: "#A0AEC0", 500: "#718096", 600: "#4A5568", 700: "#2D3748", 800: "#1A202C", 900: "#171923", }, } **After** const colors = { // ... gray: { 50: { value: "#fafafa" }, 100: { value: "#f4f4f5" }, 200: { value: "#e4e4e7" }, 300: { value: "#d4d4d8" }, 400: { value: "#a1a1aa" }, 500: { value: "#71717a" }, 600: { value: "#52525b" }, 700: { value: "#3f3f46" }, 800: { value: "#27272a" }, 900: { value: "#18181b" }, 950: { value: "#09090b" }, }, } ### [Style Props](#style-props) Changed the naming convention for some style props * `noOfLines` -> `lineClamp` * `truncated` -> `truncate` * `_activeLink` -> `_currentPage` * `_activeStep` -> `_currentStep` * `_mediaDark` -> `_osDark` * `_mediaLight` -> `_osLight` We removed the `apply` prop in favor of `textStyle` or `layerStyles` ### [Nested Styles](#nested-styles) We have changed the way you write nested styles in Chakra UI components. **Before** Write nested styles using the `sx` or `__css` prop, and you sometimes don't get auto-completion for nested styles. **After** Write nested styles using the `css` prop. All nested selectors **require** the use of the ampersand `&` prefix This was done for two reasons: * **Faster style processing:** Before we had to check if a style key is a style prop or a selector which is quite expensive overall. * **Better typings:** This makes it easier to type nested style props are strongly typed [Component Changes](#component-changes) ---------------------------------------- ### [ChakraProvider](#chakraprovider) * Removed `theme` prop in favor of passing the `system` prop instead. Import the `defaultSystem` module instead of `theme` * Removed `resetCss` prop in favor of passing `preflight: false` to the `createSystem` function Before After const system = createSystem(defaultConfig, { preflight: false }) * Removed support for configuring toast options. Pass it to the `createToaster` function in `components/ui/toaster.tsx` file instead. * Renamed to `Dialog` * Remove `isCentered` prop in favor of using the `placement=center` prop * Removed `isOpen` and `onClose` props in favor of using the `open` and `onOpenChange` props ### [Avatar](#avatar) * Remove `max` prop in favor of userland control * Remove excess label part * Move image related props to `Avatar.Image` component * Move fallback icon to `Avatar.Fallback` component * Move `name` prop to `Avatar.Fallback` component ### [Portal](#portal) * Remove `appendToParentPortal` prop in favor of using the `containerRef` * Remove `PortalManager` component ### [Stack](#stack) * Changed `spacing` to `gap` * Removed `StackItem` in favor of using the `Box` component directly ### [Collapse](#collapse) * Rename `Collapse` to `Collapsible` namespace * Rename `in` to `open` * `animateOpacity` has been removed, use keyframes animations `expand-height` and `collapse-height` instead Before Some content After Some content ### [Image](#image) * Now renders a native `img` without any fallback * Remove `fallbackSrc` due to the SSR issues it causes * Remove `useImage` hook * Remove `Img` in favor of using the `Image` component directly ### [PinInput](#pininput) * Changed `value`, `defaultValue` to use `string[]` instead of `string` * `onChange` prop is now called `onValueChange` * Add new `PinInput.Control` and `PinInput.Label` component parts * `PinInput.Root` now renders a `div` element by default. Consider combining with `Stack` or `Group` for better layout control ### [NumberInput](#numberinput) * Rename `NumberInputStepper` to `NumberInput.Control` * Rename `NumberInputStepperIncrement` to `NumberInput.IncrementTrigger` * Rename `NumberInputStepperDecrement` to `NumberInput.DecrementTrigger` * `onChange` prop is now called `onValueChange` * Remove `focusBorderColor` and `errorBorderColor`, consider setting the `--focus-color` and `--error-color` css variables instead Before After ### [Divider](#divider) * Rename to `Separator` * Switch to `div` element for better layout control * Simplify component to rely on `borderTopWidth` and `borderInlineStartWidth` * To change the thickness reliably, set the `--divider-border-width` css variable ### [Input, Select, Textarea](#input-select-textarea) * Removed `invalid` prop in favor of wrapping the component in a `Field` component. This allows for adding a label, error text and asterisk easily. Before After Email This field is required ### [Link](#link) * Removed `isExternal` prop in favor of explicitly setting the `target` and `rel` props Before Click me After Click me ### [IconButton](#iconbutton) * Removed `icon` prop in favor of rendering the `children` prop directly * Removed `isRounded` in favor of using the `borderRadius=full` prop ### [Spinner](#spinner) * Change the `thickness` prop to `borderWidth` * Change the `speed` prop to `animationDuration` Before After [Previous\ \ Installation](/docs/get-started/installation) [Next\ \ CLI](/docs/get-started/cli) --- # Overview | Chakra UI Build faster with Premium Chakra UI Components 💎 [Learn more](https://pro.chakra-ui.com?utm_source=chakra-ui.com) Overview ======== A guide for configuring the Chakra UI theming system. [Architecture](#architecture) ------------------------------ The Chakra UI theming system is built around the API of [Panda CSS](https://panda-css.com/) . Here's a quick overview of how the system is structured to provide a performant and extensible styling system: * Define the styling system configuration using the `defineConfig` function * Create the styling engine using the `createSystem` function * Pass the styling engine to the `ChakraProvider` component import { ChakraProvider, createSystem, defaultConfig, defineConfig, } from "@chakra-ui/react" const config = defineConfig({ theme: { tokens: { colors: {}, }, }, }) const system = createSystem(defaultConfig, config) export default function App() { return ( Hello World ) } [Config](#config) ------------------ The Chakra UI system is configured using the `defineConfig` function. This function accepts a configuration object that allows you to customize the styling system's behavior. After a config is defined, it is passed to the `createSystem` function to create the styling engine. ### [cssVarsRoot](#cssvarsroot) `cssVarsRoot` is the root element where the token CSS variables will be applied. theme.ts const config = defineConfig({ cssVarsRoot: ":where(:root, :host)", }) export default createSystem(defaultConfig, config) ### [cssVarsPrefix](#cssvarsprefix) `cssVarsPrefix` is the prefix used for the token CSS variables. theme.ts const config = defineConfig({ cssVarsPrefix: "ck", }) export default createSystem(defaultConfig, config) ### [globalCss](#globalcss) `globalCss` is used to apply global styles to the system. theme.ts const config = defineConfig({ globalCss: { "html, body": { margin: 0, padding: 0, }, }, }) export default createSystem(defaultConfig, config) ### [theme](#theme) Use the `theme` config property to define the system theme. This property accepts the following properties: * `breakpoints`: for defining breakpoints * `keyframes`: for defining css keyframes animations * `tokens`: for defining tokens * `semanticTokens`: for defining semantic tokens * `textStyles`: for defining typography styles * `layerStyles`: for defining layer styles * `animationStyles`: for defining animation styles * `recipes`: for defining component recipes * `slotRecipes`: for defining component slot recipes theme.ts const config = defineConfig({ theme: { breakpoints: { sm: "320px", md: "768px", lg: "960px", xl: "1200px", }, tokens: { colors: { red: "#EE0F0F", }, }, semanticTokens: { colors: { danger: { value: "{colors.red}" }, }, }, keyframes: { spin: { from: { transform: "rotate(0deg)" }, to: { transform: "rotate(360deg)" }, }, }, }, }) export default createSystem(defaultConfig, config) ### [conditions](#conditions) Use the `conditions` config property to define custom selectors and media query conditions for use in the system. theme.ts const config = defineConfig({ conditions: { cqSm: "@container(min-width: 320px)", child: "& > *", }, }) export default createSystem(defaultConfig, config) Sample usage: Hello World ### [strictTokens](#stricttokens) Use the `strictTokens` config property to enforce the usage of only design tokens. This will throw a TS error if you try to use a token that is not defined in the theme. theme.ts const config = defineConfig({ strictTokens: true, }) export default createSystem(defaultConfig, config) // ❌ This will throw a TS error Hello World // ✅ This will work Hello World [TypeScript](#typescript) -------------------------- When you configure the system properties (like `colors`, `space`, `fonts`, etc.), the CLI can be used to generate type definitions for them. npx @chakra-ui/cli typegen ./theme.ts This will update the internal types in the `@chakra-ui/react` package, and make sure they are in sync with the theme. Providing a type-safe API and delightful experience for developers. [System](#system) ------------------ After a config is defined, it is passed to the `createSystem` function to create the styling engine. The returned `system` is framework-agnostic JavaScript styling engine that can be used to style components. const system = createSystem(defaultConfig, config) The system includes the following properties: ### [token](#token) The token function is used to get a raw token value, or css variable. const system = createSystem(defaultConfig, config) // raw token system.token("colors.red.200") // => "#EE0F0F" // token with fallback system.token("colors.pink.240", "#000") // => "#000" Use the `token.var` function to get the css variable: // css variable system.token.var("colors.red.200") // => "var(--chakra-colors-red-200)" // token with fallback system.token.var("colors.pink.240", "colors.red.200") // => "var(--chakra-colors-red-200)" It's important to note that `semanticTokens` always return a css variable, regardless of whether you use `token` or `token.var`. This is because semantic tokens change based on the theme. // semantic token system.token("colors.danger") // => "var(--chakra-colors-danger)" system.token.var("colors.danger") // => "var(--chakra-colors-danger)" ### [tokens](#tokens) const system = createSystem(defaultConfig, config) system.tokens.getVar("colors.red.200") // => "var(--chakra-colors-red-200)" system.tokens.expandReferenceInValue("3px solid {colors.red.200}") // => "3px solid var(--chakra-colors-red-200)" system.tokens.cssVarMap // => Map { "colors": Map { "red.200": "var(--chakra-colors-red-200)" } } system.tokens.flatMap // => Map { "colors.red.200": "var(--chakra-colors-red-200)" } ### [css](#css) The `css` function is used to convert chakra style objects to CSS style object that can be passed to `emotion` or `styled-components` or any other styling library. const system = createSystem(defaultConfig, config) system.css({ color: "red.200", bg: "blue.200", }) // => { color: "var(--chakra-colors-red-200)", background: "var(--chakra-colors-blue-200)" } ### [cva](#cva) The `cva` function is used to create component recipes. It returns a function that, when called with a set of props, returns a style object. const system = createSystem(defaultConfig, config) const button = system.cva({ base: { color: "white", bg: "blue.500", }, variants: { outline: { color: "blue.500", bg: "transparent", border: "1px solid", }, }, }) button({ variant: "outline" }) // => { color: "blue.500", bg: "transparent", border: "1px solid" } ### [sva](#sva) The `sva` function is used to create component slot recipes. It returns a function that, when called with a set of props, returns a style object for each slot. const system = createSystem(defaultConfig, config) const alert = system.sva({ slots: ["title", "description", "icon"], base: { title: { color: "white" }, description: { color: "white" }, icon: { color: "white" }, }, variants: { status: { info: { title: { color: "blue.500" }, description: { color: "blue.500" }, icon: { color: "blue.500" }, }, }, }, }) alert({ status: "info" }) // => { title: { color: "blue.500" }, description: { color: "blue.500" }, icon: { color: "blue.500" } } ### [isValidProperty](#isvalidproperty) The `isValidProperty` function is used to check if a property is valid. const system = createSystem(defaultConfig, config) system.isValidProperty("color") // => true system.isValidProperty("background") // => true system.isValidProperty("invalid") // => false ### [splitCssProps](#splitcssprops) The `splitCssProps` function is used to split the props into css props and non-css props. const system = createSystem(defaultConfig, config) system.splitCssProps({ color: "red.200", bg: "blue.200", "aria-label": "Hello World", }) // => [{ color: "red.200", bg: "blue.200" }, { "aria-label": "Hello World" }] ### [breakpoints](#breakpoints) The `breakpoints` property is used to query breakpoints. const system = createSystem(defaultConfig, config) system.breakpoints.up("sm") // => "@media (min-width: 320px)" system.breakpoints.down("sm") // => "@media (max-width: 319px)" system.breakpoints.only("md") // => "@media (min-width: 320px) and (max-width: 768px)" system.breakpoints.keys() // => ["sm", "md", "lg", "xl"] [Tokens](#tokens-1) -------------------- To learn more about tokens, please refer to the [tokens](/docs/theming/tokens) section. [Recipes](#recipes) -------------------- To learn more about recipes, please refer to the [recipes](/docs/theming/recipes) section. [Previous\ \ Typography](/docs/styling/style-props/typography) [Next\ \ Tokens](/docs/theming/tokens) --- # CLI | Chakra UI Build faster with Premium Chakra UI Components 💎 [Learn more](https://pro.chakra-ui.com?utm_source=chakra-ui.com) CLI === Learn more to use the Chakra CLI command to generate snippets and typings The Chakra UI CLI can be used to generate typings for your custom theme tokens, like colors, semantic tokens, recipe variants, etc. [Installation](#installation) ------------------------------ In order to use the CLI, you need to install it as a dev dependency in your project: npmpnpmbun npm i -D @chakra-ui/cli pnpm add -D @chakra-ui/cli bun add -d @chakra-ui/cli warning To use the CLI tool, please ensure that the version of Node.js is `>= 20.6.0`. [Usage](#usage) ---------------- Use the Chakra CLI to run any of the commands listed below with your preferred package manager. Usage: npx chakra [options] [command] The official CLI for Chakra UI projects Options: -V, --version output the version number -h, --help display help for command Commands: typegen [options] Generate theme and recipe typings snippet Add snippets to your project for better DX eject [options] Take control over the default theme tokens and recipes help [command] display help for command [`chakra typegen`](#chakra-typegen) ------------------------------------ Generates theme and recipe typings for your custom theme. This helps to provide autocompletion and type safety in your project. # Generate typings chakra typegen src/theme.ts # Watch for changes and rebuild chakra typegen src/theme.ts --watch # Generate strict types for props variant and size chakra typegen src/theme.ts --strict [`chakra snippet`](#chakra-snippet) ------------------------------------ Generates useful component compositions that boost your development speed. # Add all snippets chakra snippet add --all # Add a specific snippet chakra snippet add button # List all available snippets chakra snippet list # Specify a custom directory chakra snippet add dialog --outdir ./components/custom [`chakra eject`](#chakra-eject) -------------------------------- Generated the file(s) that contain the default theme tokens and recipes so you can have full control over them. # Copy the tokens and recipes to your project chakra eject --outdir src/theme [FAQ](#faq) ------------ ### [Autocomplete for custom tokens not working?](#autocomplete-for-custom-tokens-not-working) After generating the typings, you need to "Restart TS Server" for the autocomplete to show up. Alternatively, you can install the `@chakra-ui/cli` package locally as a dev dependency and run the `chakra typegen` command to generate the typings. [Previous\ \ Migration](/docs/get-started/migration) [Next\ \ LLMs.txt](/docs/get-started/llms) --- # Contributing to Chakra UI | Chakra UI Build faster with Premium Chakra UI Components 💎 [Learn more](https://pro.chakra-ui.com?utm_source=chakra-ui.com) Contributing to Chakra UI ========================= The guide to contributing to Chakra UI v3.0 Thanks for showing interest to contribute to Chakra UI 💖, you rock! [Overview](#overview) ---------------------- Here are a few ways you can help improve Chakra UI * **Improve the documentation**: Add new demos, fix typos, or add missing information. * **Add new demos**: Add new component demos to the website and storybook. Open a PR to `apps/compositions/src/examples` * **Fix bugs**: Report bugs, fix bugs, or add missing features. * **Contribute to the code**: Propose new features by opening a Github Discussion, or find existing bugs to work on. * **Improve the code**: Improve the code, fix bugs, or add missing features. info We welcome all contributions, no matter how big or small. [Architecture](#architecture) ------------------------------ Chakra v3.x is a composition of two projects in the Chakra ecosystem, Ark UI and Zag.js. The goal is to maintain as little code as possible in Chakra UI, and delegate the heavy lifting to these projects. [Zag.js\ \ Component logic modelled as a state machine](https://github.com/chakra-ui/zag) [Ark UI\ \ State machine from Zag.js converted to headless UI components](https://github.com/chakra-ui/ark) ### [Filing Issues](#filing-issues) The mindset for filing issues on Chakra v3.x works like this: * If the issue is a logic or accessibility bug, then it's most likely a bug in Zag.js. Consider opening an issue in the Zag.js repository. * If it's a styling issue, then you can fix it directly in the Chakra UI repo. ### [Feature Requests](#feature-requests) The mindset for filing feature requests on Chakra v3.x works like this: * If the feature is a new component without logic, then it can go in Chakra UI or Ark UI. Start a discussion on the [Chakra UI repository](https://github.com/chakra-ui/chakra-ui) * If the feature is a new component with logic, it belongs in Zag.js. Start a discussion on the [Zag.js repository](https://github.com/chakra-ui/zag) . [Local Setup](#local-setup) ---------------------------- * Clone the repository git clone https://github.com/chakra-ui/chakra-ui.git * Install dependencies with pnpm pnpm install * Build local version of all packages pnpm build:fast * Start storybook pnpm storybook * Start documentation website pnpm www dev * Run tests pnpm test [Recommended Extensions](#recommended-extensions) -------------------------------------------------- We recommend using the following extensions in your editor: * [ESLint](https://eslint.org/) * [Prettier](https://prettier.io/) * [EditorConfig](https://editorconfig.org/) * [MDX](https://mdxjs.com/) [Previous\ \ LLMs.txt](/docs/get-started/llms) [Next\ \ Showcase](/showcase) --- # Using Chakra UI in Next.js (App) | Chakra UI Build faster with Premium Chakra UI Components 💎 [Learn more](https://pro.chakra-ui.com?utm_source=chakra-ui.com) Using Chakra UI in Next.js (App) ================================ A guide for installing Chakra UI with Next.js app directory [Templates](#templates) ------------------------ Use one of the following templates to get started quickly. The templates are configured correctly to use Chakra UI. [Next.js app template](https://github.com/chakra-ui/chakra-ui/tree/main/sandbox/next-app) [Next.js pages template](https://github.com/chakra-ui/chakra-ui/tree/main/sandbox/next-pages) [Installation](#installation) ------------------------------ The minimum node version required is Node.20.x 1 ### [Install dependencies](#install-dependencies) npm i @chakra-ui/react @emotion/react 2 ### [Add snippets](#add-snippets) Snippets are pre-built components that you can use to build your UI faster. Using the `@chakra-ui/cli` you can add snippets to your project. npx @chakra-ui/cli snippet add 3 ### [Update tsconfig](#update-tsconfig) If you're using TypeScript, you need to update the `compilerOptions` in the tsconfig file to include the following options: { "compilerOptions": { "target": "ESNext", "module": "ESNext", "moduleResolution": "Bundler", "skipLibCheck": true, "paths": { "@/*": ["./src/*"] } } } If you're using JavaScript, create a `jsconfig.json` file and add the above code to the file. 4 ### [Setup provider](#setup-provider) Wrap your application with the `Provider` component generated in the `components/ui/provider` component at the root of your application. This provider composes the following: * `ChakraProvider` from `@chakra-ui/react` for the styling system * `ThemeProvider` from `next-themes` for color mode app/layout.tsx import { Provider } from "@/components/ui/provider" export default function RootLayout(props: { children: React.ReactNode }) { const { children } = props return ( {children} ) } Adding the `suppressHydrationWarning` prop to the `html` element is required to prevent the warning about the `next-themes` library. 5 ### [Optimize Bundle](#optimize-bundle) We recommend using the `experimental.optimizePackageImports` feature in Next.js to optimize your bundle size by loading only the modules that you are actually using. next.config.mjs export default { experimental: { optimizePackageImports: ["@chakra-ui/react"], }, } This also helps to resolve warnings like: [webpack.cache.PackFileCacheStrategy] Serializing big strings (xxxkiB) 6 ### [Hydration errors](#hydration-errors) If you see an error like this: **Hydration failed because the initial server rendered HTML did not match the client**, and the error looks similar to: +
-