# Pandacss > Panda CSS is a CSS-in-JS framework with build-time optimizations for styling web applications --- # Panda CSS Documentation # Source: https://panda-css.com/llms-full.txt # Section: llms-full.txt # Panda CSS Complete Documentation > Panda CSS is a CSS-in-JS framework with build-time optimizations for styling web applications This document contains the complete Panda CSS documentation, organized by category for easy navigation. ## Table of Contents ### Overview - [Browser Support](#browser-support) - [Frequently Asked Questions](#frequently-asked-questions) - [Get started with Panda](#get-started-with-panda) - [LLMs.txt](#llms.txt) - [Why Panda](#why-panda) ### Installation - [Using Angular](#using-angular) - [Using Astro](#using-astro) - [Panda CLI](#panda-cli) - [Using Ember](#using-ember) - [Using Gatsby](#using-gatsby) - [Using Next.js](#using-next.js) - [Using Nuxt](#using-nuxt) - [Using PostCSS](#using-postcss) - [Using Preact](#using-preact) - [Using Qwik](#using-qwik) - [Using React Router](#using-react-router) - [Using Redwood](#using-redwood) - [Using Remix](#using-remix) - [Using Rsbuild](#using-rsbuild) - [Using SolidJS](#using-solidjs) - [Using Storybook](#using-storybook) - [Using Svelte](#using-svelte) - [Using Vite](#using-vite) - [Using Vue](#using-vue) ### Concepts - [Cascade Layers](#cascade-layers) - [Color opacity modifier](#color-opacity-modifier) - [Conditional Styles](#conditional-styles) - [The extend keyword](#the-extend-keyword) - [Global Styles](#global-styles) - [Panda Integration Hooks](#panda-integration-hooks) - [JSX Style Context](#jsx-style-context) - [Merging Styles](#merging-styles) - [Patterns](#patterns) - [Recipes](#recipes) - [Responsive Design](#responsive-design) - [Slot Recipes](#slot-recipes) - [Style props](#style-props) - [Styled System](#styled-system) - [Template Literals](#template-literals) - [Virtual Color](#virtual-color) - [Writing Styles](#writing-styles) ### Theming - [Animation Styles](#animation-styles) - [Layer Styles](#layer-styles) - [Spec](#spec) - [Using Panda Studio](#using-panda-studio) - [Text Styles](#text-styles) - [Tokens](#tokens) - [Using Tokens](#using-tokens) ### Utilities - [Background](#background) - [Border](#border) - [Display](#display) - [Divide](#divide) - [Effects](#effects) - [Flex and Grid](#flex-and-grid) - [Focus Ring](#focus-ring) - [Gradients](#gradients) - [Helpers](#helpers) - [Interactivity](#interactivity) - [Layout](#layout) - [List](#list) - [Outline](#outline) - [Sizing](#sizing) - [Spacing](#spacing) - [SVG](#svg) - [Tables](#tables) - [Transforms](#transforms) - [Transitions](#transitions) - [Typography](#typography) ### Customization - [Conditions](#conditions) - [Config Functions](#config-functions) - [Deprecations](#deprecations) - [Customizing Patterns](#customizing-patterns) - [Presets](#presets) - [Theme](#theme) - [Utilities](#utilities) ### Guides - [Using Panda in a Component Library](#using-panda-in-a-component-library) - [Debugging](#debugging) - [Dynamic styling](#dynamic-styling) - [Custom Font](#custom-font) - [Minimal Setup](#minimal-setup) - [Multi-Theme Tokens](#multi-theme-tokens) - [Static CSS Generator](#static-css-generator) ### Migration - [Migrating from Stitches](#migrating-from-stitches) - [Migrating from Styled Components](#migrating-from-styled-components) - [Migrating from Theme UI](#migrating-from-theme-ui) ### References - [CLI Reference](#cli-reference) - [Configuring Panda](#configuring-panda) --- # Overview ## Browser Support Learn about the browser support for Panda Panda CSS is built with modern CSS features and uses [PostCSS](https://postcss.org/) to add support for older browsers. Panda supports the latest, stable releases of major browsers that support the following features: - [CSS Variables](https://caniuse.com/css-variables) - [CSS Cascade Layers](https://caniuse.com/css-cascade-layers) - Modern selectors, such as [`:where()`](https://caniuse.com/mdn-css_selectors_where) and [`:is()`](https://caniuse.com/css-matches-pseudo) ## Browserlist Based on the above criteria, the following browsers are supported: ```txt >= 1% last 1 major version not dead Chrome >= 99 Edge >= 99 Firefox >= 97 iOS >= 15.4 Safari >= 15.4 Android >= 115 Opera >= 73 ``` ## Polyfills In event that you need to support older browsers, you can use the following polyfills in your PostCSS config: - [autoprefixer](https://github.com/postcss/autoprefixer): Adds vendor prefixes to CSS rules using values from [Can I Use](https://caniuse.com/). - [postcss-cascade-layers](https://www.npmjs.com/package/@csstools/postcss-cascade-layers): Adds support for CSS Cascade Layers. Here is an example of a `postcss.config.js` file that uses these polyfills: ```js module.exports = { plugins: ['@pandacss/dev/postcss', 'autoprefixer', '@csstools/postcss-cascade-layers'] } ``` --- ## Frequently Asked Questions Frequently asked questions and how to resolve common issues ## How does Panda manage style conflicts ? When you combine shorthand and longhand properties, Panda will resolve the styles in a predictable way. The shorthand property will take precedence over the longhand property. ```jsx import { css } from '../styled-system/css' const styles = css({ paddingTop: '20px', padding: '10px' }) ``` The styles generated at build time will look like this: ```css @layer utilities { .p_10px { padding: 10px; } .pt_20px { padding-top: 20px; } } ``` --- ## Imported Image is not working in Vite App This is a known limitation of Panda due to our static extraction approach. > Think of it this way: there's no way for the compiler to know what the final asset URL will be since Vite controls it. We recommend moving the imported `backgroundImage` to the `style` attribute. ```jsx import myImageBackground from './my-image.png' const Demo = () => { return (
Hello World
) } ``` --- ## How to get Panda to work with Jest? If you run into error messages like `SyntaxError: Unexpected token 'export'` when running Jest tests. Here's what you can: In your tsconfig, add ```json { "compilerOptions": { "allowJs": true } } ``` In your Jest configuration, add the `ts-jest` transformer: ```ts export default { // ... transform: { '^.+\\.tsx?$': 'ts-jest', '^.+\\.(ts|tsx|js|jsx)?$': 'ts-jest' } } ``` In your Panda config, set the `outExtension` to `js`: ```ts export default defineConfig({ // ... outExtension: 'js' }) ``` --- ## HMR does not work when I use `tsconfig` paths? Panda tries to automatically infer and read the custom paths defined in `tsconfig.json` file. However, there might be scenarios where the hot module replacement doesn't work. To fix this add the `importMap` option to your `panda.config.js` file, setting it's value to the specified `paths` in your `tsconfig.json` file. ```json // tsconfig.json { "compilerOptions": { "baseUrl": "./src", "paths": { "@my-path/*": ["./styled-system/*"] } } } ``` ```js // panda.config.js module.exports = { importMap: '@my-path' } ``` This will ensure that the paths are resolved correctly, and HMR works as expected. --- ## HMR not triggered If you are having issues with HMR not being triggered after a `panda.config.ts` change (or one of its [dependencies](/docs/references/config#dependencies)), you can manually specify the files that should trigger a rebuild by adding the following to your `panda.config.ts`: ```js filename="panda.config.ts" import { defineConfig } from '@pandacss/dev' export default defineConfig({ // ... dependencies: ['path/to/files/**.ts'] }) ``` --- ## Why are my styles not applied? Check that the [`@layer` rules](/docs/concepts/cascade-layers#layer-css) are set and the corresponding `.css` file is included. [If you're not using `postcss`](/docs/installation/cli), ensure that `styled-system/styles.css` is imported and that the `panda` command has been run (or is running with `--watch`). --- ## How can I debug the styles? You can use the `panda debug` to debug design token extraction & css generated from files. If the issue persists, you can try looking for it in the [issues](https://github.com/chakra-ui/panda/issues) or in the [discord](https://discord.gg/VQrkpsgSx7). If you can't find it, please create a minimal reproduction and submit [a new github issue](https://github.com/chakra-ui/panda/issues/new/choose) so we can help you. --- ## Why is my IDE not showing `styled-system` imports? If you're not getting import autocomplete in your IDE, you may need to include the `styled-system` directory in your tsconfig.json file. --- ## How do I get a type with each recipe properties? You can get a [`config recipe`](/docs/concepts/recipes#config-recipe) properties types by using `XXXVariantProps`. Let's say you have a `config recipe` named `button`, you can import its type like this: ```ts import { button, type ButtonVariantProps } from '../styled-system/recipes' ``` --- You can get an [`atomic recipe`](/docs/concepts/recipes#atomic-recipe) properties types by using `RecipeVariantProps`. Let's say you have a `atomic recipe` named `button`, you can get its type like this: ```ts import { cva, type RecipeVariantProps } from '../styled-system/css' export type ButtonVariantProps = RecipeVariantPropsHello World
| {item} |
Hover me
Hover me
I'll change by bg
{description}
{description}
Hello World
{color.name}
{color.value}
{token.name}
{token.cssVar}
{value}
{buttonRecipe.description}
}| Variant | Options | Default |
|---|---|---|
| {key} | {(options as string[]).map(option => ( {option} ))} | {defaultVariants[key as keyof typeof defaultVariants] || 'none'} |
The quick brown fox jumps over the lazy dog
| Prop | Type | Default |
|---|---|---|
| {prop.name} | {prop.type} | {prop.defaultValue || '—'} |
This is a paragraph from Panda with the body text style.
} ``` ## Nesting text styles Text styles support nested structures with a special `DEFAULT` key. This allows you to create variants of a text style while having a default fallback. When you define a `DEFAULT` key within a nested text style, you can reference the parent key directly to use the default value. ```js filename="panda.config.ts" export default defineConfig({ theme: { extend: { textStyles: { heading: { DEFAULT: { value: { fontFamily: 'Inter', fontWeight: 'bold', fontSize: '1.5rem', lineHeight: '1.2' } }, h1: { value: { fontFamily: 'Inter', fontWeight: 'bold', fontSize: '2.5rem', lineHeight: '1.1' } }, h2: { value: { fontFamily: 'Inter', fontWeight: 'bold', fontSize: '2rem', lineHeight: '1.15' } } } } } } }) ``` Now you can use the default heading style or specific variants: ```jsx import { css } from '../styled-system/css' function App() { return (Hello World
) } ``` You can also add an optional description to your tokens. This will be used in the autogenerate token documentation. ```js {8} import { defineConfig } from '@pandacss/dev' export default defineConfig({ theme: { tokens: { colors: { danger: { value: '#EE0F0F', description: 'Color for errors' } } } } }) ``` ## Semantic Tokens Semantic tokens are tokens that are designed to be used in a specific context. In most cases, the value of a semantic token references to an existing token. > To reference a value in a semantic token, use the `{}` syntax. For example, assuming we've defined the following tokens: - `red` and `green` are raw tokens that define the color red and green. - `danger` and `success` are semantic tokens that reference the `red` and `green` tokens. ```js import { defineConfig } from '@pandacss/dev' export default defineConfig({ theme: { tokens: { colors: { red: { value: '#EE0F0F' }, green: { value: '#0FEE0F' } } }, semanticTokens: { colors: { danger: { value: '{colors.red}' }, success: { value: '{colors.green}' } } } } }) ``` > ⚠️ Semantic Token values need to be nested in an object with a `value` key. This is to allow for additional properties > like `description` and more in the future. Semantic tokens can also be changed based on the [conditions](/docs/concepts/conditional-styles) like light and dark modes. For example, if you want a color to change automatically based on light or dark mode. ```js import { defineConfig } from '@pandacss/dev' export default defineConfig({ // ... theme: { semanticTokens: { colors: { danger: { value: { base: '{colors.red}', _dark: '{colors.darkred}' } }, success: { value: { base: '{colors.green}', _dark: '{colors.darkgreen}' } } } } } }) ``` > NOTE 🚨: The conditions used in semantic tokens must be an at-rule or parent selector > [condition](/docs/concepts/conditional-styles#reference). ## Token Nesting Tokens can be nested to create a hierarchy of tokens. This is useful when you want to group tokens together. > Tip: You can use the `DEFAULT` key to define the default value of a nested token. ```js import { defineConfig } from '@pandacss/dev' export default defineConfig({ // ... theme: { semanticTokens: { colors: { bg: { DEFAULT: { value: '{colors.gray.100}' }, muted: { value: '{colors.gray.100}' } } } } } }) ``` This allows the use of the `bg` token in the following ways: ```jsx import { css } from '../styled-system/css' function App() { return (Some content
Some content
Fira Code
Text
` work as expected. ## Re-using Panda presets Panda offers 2 presets: - `@pandacss/preset-base`: This is a relatively unopinionated set of utilities for mapping CSS properties to values (almost everyone will want these) You can use these presets by installing them via npm and adding them to your `presets` key: ```js export default defineConfig({ // ... presets: ['@pandacss/preset-base'] }) ``` - `@pandacss/preset-panda` as an opinionated set of tokens if you don't want to define your own colors/spacing/fonts etc. ```js export default defineConfig({ // ... presets: ['@pandacss/preset-panda'] }) ``` > Note: You don't need to install `@pandacss/preset-base` or `@pandacss/preset-panda`. Panda will automatically resolve > them for you. --- ## Multi-Theme Tokens Panda supports advance token definition beyond just light/dark mode; theming beyond just dark mode. You can define multi-theme tokens using nested conditions. ## Multi-Theme Tokens Panda supports advance token definition beyond just light/dark mode; theming beyond just dark mode. You can define multi-theme tokens using nested conditions. Let's say your application supports a pink and blue theme, and each theme can have a light and dark mode. Let's see how to model this in Panda. We'll start by defining the following conditions for these theme and color modes: ```js // panda.config.ts const config = { conditions: { light: '[data-color-mode=light] &', dark: '[data-color-mode=dark] &', pinkTheme: '[data-theme=pink] &', blueTheme: '[data-theme=blue] &' } } ``` > Conditions are a way to provide preset css selectors or media queries for use in your Panda project Next, we'll define a `colors.text` semantic token for the pink and blue theme. ```js // panda.config.ts const theme = { // ... semanticTokens: { colors: { text: { value: { _pinkTheme: '{colors.pink.500}', _blueTheme: '{colors.blue.500}' } } } } } ``` Next, we'll modify `colors.text` to support light and dark color modes for each theme. ```js // panda.config.ts const theme = { // ... semanticTokens: { colors: { text: { value: { _pinkTheme: { base: '{colors.pink.500}', _dark: '{colors.pink.300}' }, _blueTheme: { base: '{colors.blue.500}', _dark: '{colors.blue.300}' } } } } } } ``` Now, you can use the `text` token in your styles, and it will automatically change based on the theme and the color scheme. ```jsx // use pink and dark mode theme| {item} |
Hover me
Hover me
I'll change by bg
{description}
{description}
Hello World
Some content
Some content
Fira Code
Text
` work as expected. ## Re-using Panda presets Panda offers 2 presets: - `@pandacss/preset-base`: This is a relatively unopinionated set of utilities for mapping CSS properties to values (almost everyone will want these) You can use these presets by installing them via npm and adding them to your `presets` key: ```js export default defineConfig({ // ... presets: ['@pandacss/preset-base'] }) ``` - `@pandacss/preset-panda` as an opinionated set of tokens if you don't want to define your own colors/spacing/fonts etc. ```js export default defineConfig({ // ... presets: ['@pandacss/preset-panda'] }) ``` > Note: You don't need to install `@pandacss/preset-base` or `@pandacss/preset-panda`. Panda will automatically resolve > them for you. --- ## Multi-Theme Tokens Panda supports advance token definition beyond just light/dark mode; theming beyond just dark mode. You can define multi-theme tokens using nested conditions. ## Multi-Theme Tokens Panda supports advance token definition beyond just light/dark mode; theming beyond just dark mode. You can define multi-theme tokens using nested conditions. Let's say your application supports a pink and blue theme, and each theme can have a light and dark mode. Let's see how to model this in Panda. We'll start by defining the following conditions for these theme and color modes: ```js // panda.config.ts const config = { conditions: { light: '[data-color-mode=light] &', dark: '[data-color-mode=dark] &', pinkTheme: '[data-theme=pink] &', blueTheme: '[data-theme=blue] &' } } ``` > Conditions are a way to provide preset css selectors or media queries for use in your Panda project Next, we'll define a `colors.text` semantic token for the pink and blue theme. ```js // panda.config.ts const theme = { // ... semanticTokens: { colors: { text: { value: { _pinkTheme: '{colors.pink.500}', _blueTheme: '{colors.blue.500}' } } } } } ``` Next, we'll modify `colors.text` to support light and dark color modes for each theme. ```js // panda.config.ts const theme = { // ... semanticTokens: { colors: { text: { value: { _pinkTheme: { base: '{colors.pink.500}', _dark: '{colors.pink.300}' }, _blueTheme: { base: '{colors.blue.500}', _dark: '{colors.blue.300}' } } } } } } ``` Now, you can use the `text` token in your styles, and it will automatically change based on the theme and the color scheme. ```jsx // use pink and dark mode themeHello World
Hello World
) } ``` --- ## How to get Panda to work with Jest? If you run into error messages like `SyntaxError: Unexpected token 'export'` when running Jest tests. Here's what you can: In your tsconfig, add ```json { "compilerOptions": { "allowJs": true } } ``` In your Jest configuration, add the `ts-jest` transformer: ```ts export default { // ... transform: { '^.+\\.tsx?$': 'ts-jest', '^.+\\.(ts|tsx|js|jsx)?$': 'ts-jest' } } ``` In your Panda config, set the `outExtension` to `js`: ```ts export default defineConfig({ // ... outExtension: 'js' }) ``` --- ## HMR does not work when I use `tsconfig` paths? Panda tries to automatically infer and read the custom paths defined in `tsconfig.json` file. However, there might be scenarios where the hot module replacement doesn't work. To fix this add the `importMap` option to your `panda.config.js` file, setting it's value to the specified `paths` in your `tsconfig.json` file. ```json // tsconfig.json { "compilerOptions": { "baseUrl": "./src", "paths": { "@my-path/*": ["./styled-system/*"] } } } ``` ```js // panda.config.js module.exports = { importMap: '@my-path' } ``` This will ensure that the paths are resolved correctly, and HMR works as expected. --- ## HMR not triggered If you are having issues with HMR not being triggered after a `panda.config.ts` change (or one of its [dependencies](/docs/references/config#dependencies)), you can manually specify the files that should trigger a rebuild by adding the following to your `panda.config.ts`: ```js filename="panda.config.ts" import { defineConfig } from '@pandacss/dev' export default defineConfig({ // ... dependencies: ['path/to/files/**.ts'] }) ``` --- ## Why are my styles not applied? Check that the [`@layer` rules](/docs/concepts/cascade-layers#layer-css) are set and the corresponding `.css` file is included. [If you're not using `postcss`](/docs/installation/cli), ensure that `styled-system/styles.css` is imported and that the `panda` command has been run (or is running with `--watch`). --- ## How can I debug the styles? You can use the `panda debug` to debug design token extraction & css generated from files. If the issue persists, you can try looking for it in the [issues](https://github.com/chakra-ui/panda/issues) or in the [discord](https://discord.gg/VQrkpsgSx7). If you can't find it, please create a minimal reproduction and submit [a new github issue](https://github.com/chakra-ui/panda/issues/new/choose) so we can help you. --- ## Why is my IDE not showing `styled-system` imports? If you're not getting import autocomplete in your IDE, you may need to include the `styled-system` directory in your tsconfig.json file. --- ## How do I get a type with each recipe properties? You can get a [`config recipe`](/docs/concepts/recipes#config-recipe) properties types by using `XXXVariantProps`. Let's say you have a `config recipe` named `button`, you can import its type like this: ```ts import { button, type ButtonVariantProps } from '../styled-system/recipes' ``` --- You can get an [`atomic recipe`](/docs/concepts/recipes#atomic-recipe) properties types by using `RecipeVariantProps`. Let's say you have a `atomic recipe` named `button`, you can get its type like this: ```ts import { cva, type RecipeVariantProps } from '../styled-system/css' export type ButtonVariantProps = RecipeVariantProps{color.name}
{color.value}
{token.name}
{token.cssVar}
{value}
{buttonRecipe.description}
}| Variant | Options | Default |
|---|---|---|
| {key} | {(options as string[]).map(option => ( {option} ))} | {defaultVariants[key as keyof typeof defaultVariants] || 'none'} |
The quick brown fox jumps over the lazy dog
| Prop | Type | Default |
|---|---|---|
| {prop.name} | {prop.type} | {prop.defaultValue || '—'} |
This is a paragraph from Panda with the body text style.
} ``` ## Nesting text styles Text styles support nested structures with a special `DEFAULT` key. This allows you to create variants of a text style while having a default fallback. When you define a `DEFAULT` key within a nested text style, you can reference the parent key directly to use the default value. ```js filename="panda.config.ts" export default defineConfig({ theme: { extend: { textStyles: { heading: { DEFAULT: { value: { fontFamily: 'Inter', fontWeight: 'bold', fontSize: '1.5rem', lineHeight: '1.2' } }, h1: { value: { fontFamily: 'Inter', fontWeight: 'bold', fontSize: '2.5rem', lineHeight: '1.1' } }, h2: { value: { fontFamily: 'Inter', fontWeight: 'bold', fontSize: '2rem', lineHeight: '1.15' } } } } } } }) ``` Now you can use the default heading style or specific variants: ```jsx import { css } from '../styled-system/css' function App() { return (Hello World
) } ``` You can also add an optional description to your tokens. This will be used in the autogenerate token documentation. ```js {8} import { defineConfig } from '@pandacss/dev' export default defineConfig({ theme: { tokens: { colors: { danger: { value: '#EE0F0F', description: 'Color for errors' } } } } }) ``` ## Semantic Tokens Semantic tokens are tokens that are designed to be used in a specific context. In most cases, the value of a semantic token references to an existing token. > To reference a value in a semantic token, use the `{}` syntax. For example, assuming we've defined the following tokens: - `red` and `green` are raw tokens that define the color red and green. - `danger` and `success` are semantic tokens that reference the `red` and `green` tokens. ```js import { defineConfig } from '@pandacss/dev' export default defineConfig({ theme: { tokens: { colors: { red: { value: '#EE0F0F' }, green: { value: '#0FEE0F' } } }, semanticTokens: { colors: { danger: { value: '{colors.red}' }, success: { value: '{colors.green}' } } } } }) ``` > ⚠️ Semantic Token values need to be nested in an object with a `value` key. This is to allow for additional properties > like `description` and more in the future. Semantic tokens can also be changed based on the [conditions](/docs/concepts/conditional-styles) like light and dark modes. For example, if you want a color to change automatically based on light or dark mode. ```js import { defineConfig } from '@pandacss/dev' export default defineConfig({ // ... theme: { semanticTokens: { colors: { danger: { value: { base: '{colors.red}', _dark: '{colors.darkred}' } }, success: { value: { base: '{colors.green}', _dark: '{colors.darkgreen}' } } } } } }) ``` > NOTE 🚨: The conditions used in semantic tokens must be an at-rule or parent selector > [condition](/docs/concepts/conditional-styles#reference). ## Token Nesting Tokens can be nested to create a hierarchy of tokens. This is useful when you want to group tokens together. > Tip: You can use the `DEFAULT` key to define the default value of a nested token. ```js import { defineConfig } from '@pandacss/dev' export default defineConfig({ // ... theme: { semanticTokens: { colors: { bg: { DEFAULT: { value: '{colors.gray.100}' }, muted: { value: '{colors.gray.100}' } } } } } }) ``` This allows the use of the `bg` token in the following ways: ```jsx import { css } from '../styled-system/css' function App() { return (