Dosu LogoDosu Logo
Ask
Join our Discord
Ant DesignPublic
Ant Design
DocumentsAnt Design
create-static-styles.en-US
create-static-styles.en-US
Type
External
Status
Published
Created
Jun 12, 2026
Updated
Jun 12, 2026
Source
docs/api/create-static-styles.en-US.md
Recommended

When you only need CSS variables and don't require dynamic props, use createStaticStyles for optimal performance.

Introduction#

createStaticStyles is a high-performance style creation function. The main differences from createStyles are:

  • Non-Hook: Returns style object directly, not a React Hook
  • Zero Runtime Overhead: Styles are computed once at module import
  • CSS Variables: Uses antd's CSS variables through cssVar

Basic Usage#

import { createStaticStyles } from 'antd-style';

// Module-level definition, styles computed once at import
const styles = createStaticStyles(({ css, cssVar }) => ({
  container: css`
    padding: 16px;
    background: ${cssVar.colorBgContainer};
    border: 1px solid ${cssVar.colorBorder};
    border-radius: ${cssVar.borderRadius};
  `,
  title: css`
    font-size: 18px;
    color: ${cssVar.colorText};
  `,
}));

// Use directly in components, no Hook call needed
const MyComponent = () => {
  return (
    <div className={styles.container}>
      <h1 className={styles.title}>Hello</h1>
    </div>
  );
};

Comparison with createStyles#

FeaturecreateStylescreateStaticStyles
Return ValueHookStyle Object
token (JS values)✅❌
cssVar (CSS variables)✅✅
customToken✅❌
stylish✅❌
responsive✅ (dynamic)✅ (fixed breakpoints)
props parameter✅❌
isDarkMode✅❌
Hooks count8+0
Performance overheadHighNear Zero

API#

StaticStyleUtils#

The parameter function of createStaticStyles receives a utility object with the following properties:

PropertyTypeDescription
cssCssUtilCSS template function, converts styles to className
cxClassNamesUtilMerges multiple classNames
cssVarCSSVarMapantd CSS variable mapping
responsiveStaticResponsiveMapResponsive breakpoint mapping

cssVar#

CSS variable mapping object that converts antd tokens to corresponding CSS variable format.

import { cssVar } from 'antd-style';

// cssVar.colorPrimary => 'var(--ant-color-primary)'
// cssVar.colorBgContainer => 'var(--ant-color-bg-container)'
// cssVar.borderRadius => 'var(--ant-border-radius)'

responsive#

Fixed responsive breakpoint mapping:

import { responsive } from 'antd-style';

// responsive.xs => '@media (max-width: 479.98px)'
// responsive.sm => '@media (max-width: 575.98px)'
// responsive.md => '@media (max-width: 767.98px)'
// responsive.lg => '@media (max-width: 991.98px)'
// responsive.xl => '@media (max-width: 1199.98px)'
// responsive.xxl => '@media (min-width: 1200px)'

Usage Examples#

Responsive Layout#

const styles = createStaticStyles(({ css, responsive }) => ({
  layout: css`
    display: flex;
    flex-direction: row;
    gap: 16px;

    ${responsive.md} {
      flex-direction: column;
    }

    ${responsive.sm} {
      padding: 8px;
    }
  `,
}));

Merging classNames#

const styles = createStaticStyles(({ css, cx }) => {
  const baseButton = css`
    padding: 8px 16px;
    border-radius: 4px;
  `;

  const primaryButton = css`
    background: blue;
    color: white;
  `;

  return {
    button: cx(baseButton, primaryButton),
  };
});

Use Cases#

Recommended#

  1. Pure UI Component Styles: Components that don't depend on dynamic token values
  2. Layout Styles: Spacing, border-radius, etc. using CSS variables
  3. High-frequency Rendering Components: List items, table cells, and other performance-sensitive scenarios
  4. Many Components: Pages with many styled components

Not Recommended#

  1. Need custom tokens
  2. Need JS-computed styles (e.g., token.colorPrimary + '80')
  3. Need dynamic styles based on props
  4. Need stylish presets
  5. Need isDarkMode for conditional logic

createStaticStylesFactory#

If your application uses a custom CSS variable prefix (e.g., via ConfigProvider's prefixCls configuration), you can use createStaticStylesFactory to create a custom instance.

Basic Usage#

import { createStaticStylesFactory } from 'antd-style';

// Create instance with custom prefix
const { createStaticStyles, cssVar, responsive } = createStaticStylesFactory({
  prefix: 'my-app',
});

// cssVar.colorPrimary => 'var(--my-app-color-primary)'
// cssVar.colorBgContainer => 'var(--my-app-color-bg-container)'

const styles = createStaticStyles(({ css, cssVar }) => ({
  container: css`
    background: ${cssVar.colorBgContainer};
  `,
}));

Configuration Options#

ParameterTypeDefaultDescription
prefixstring'ant'CSS variable prefix
hashPriorityHashPriority'high'Style hash priority

Integration with createInstance#

If you use createInstance to create a custom instance, static styles will automatically use the configured prefixCls:

import { createInstance } from 'antd-style';

const { createStaticStyles, cssVar } = createInstance({
  prefixCls: 'my-app',
});

// cssVar will automatically use 'my-app' prefix
// cssVar.colorPrimary => 'var(--my-app-color-primary)'

Performance Notes#

createStaticStyles has the following performance advantages over createStyles:

  • Zero Hooks Calls: No Hook calls during component rendering
  • Module-level Caching: Styles computed only once at module import
  • No useMemo Overhead: No memoization computation needed

For performance-sensitive scenarios, consider using createStaticStyles first.

Documents
Masonry Server-Side Rendering
2026-03-17-doctor-enhancements
2026-03-17-doctor-enhancements-design
2026-03-20-bug-fixes-round-2
2026-03-23-bug-report-commands
2026-03-23-bug-report-commands-design
2026-03-24-antd-mcp-server-design
2026-03-24-doctor-ecosystem-peerdeps
2026-03-24-doctor-ecosystem-peerdeps-design
2026-03-26-env-command
2026-03-26-env-command-design
2026-04-02-antd-v3-support-design
2026-04-02-antd-v3-support-plan
2026-04-17-opt-out-auto-report-design
2026-05-26-upgrade-command-design
AGENTS
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG.zh-CN
CLAUDE
HISTORY
HISTORY
README
README
README
README
README
README
README
README
README
README
README.zh-CN
README.zh-CN
RFC-createStaticStyles
SKILL
antd-based-components.en-US
antd-based-components.zh-CN
antd-override.en-US
antd-override.zh-CN
babel-plugin.en-US
babel-plugin.zh-CN
bug_report
changelog.en-US
changelog.zh-CN
clay.en-US
clay.zh-CN
color-panel
compare.en-US
compare.zh-CN
components-usage.en-US
components-usage.zh-CN
controlled
create-instance.en-US
create-instance.zh-CN
create-static-styles.en-US
create-static-styles.zh-CN
create-styles.en-US
create-styles.en-US
create-styles.zh-CN
create-styles.zh-CN
create-stylish.en-US
create-stylish.zh-CN
css-in-js-intro.en-US
css-in-js-intro.zh-CN
cssinjs-compiler-difference.en-US
cssinjs-compiler-difference.zh-CN
custom-theme.en-US
custom-theme.zh-CN
custom-token-types.en-US
custom-token-types.zh-CN
design-v6
feature_request
fix-switch-theme-fouc.en-US
fix-switch-theme-fouc.zh-CN
genStyleUtils
global-styles.en-US
global-styles.zh-CN
index
index
index
index
index
index
index.en-US
index.en-US
index.zh-CN
index.zh-CN
index.zh-CN
intro
intro
introModal
introModal
mac-select.en-US
mac-select.zh-CN
migrate-less-application.en-US
migrate-less-application.zh-CN
migrate-less-codemod.en-US
migrate-less-codemod.zh-CN
migrate-less-component.en-US
migrate-less-component.zh-CN
mirgration-less-global-style.en-US
mirgration-less-global-style.zh-CN
motivationHelp
motivationHelp
nest-element-style.en-US
nest-element-style.zh-CN
overview
performance-comparsion.en-US
performance-comparsion.zh-CN
performance.en-US
performance.zh-CN
previewer-token-panel
proposalHelp
proposalHelp
question
reproHelp
reproHelp
reproModal
reproModal
setup-styled.en-US
setup-styled.zh-CN
spec
ssr.en-US
ssr.zh-CN
static-message.en-US
static-message.zh-CN
stepsHelp
stepsHelp
strategy.en-US
strategy.zh-CN
style-provider.en-US
style-provider.zh-CN
styled.en-US
styled.en-US
styled.zh-CN
styled.zh-CN
stylish.en-US
stylish.zh-CN
switch-theme.en-US
switch-theme.zh-CN
theme
theme-provider.en-US
theme-provider.zh-CN
use-responsive.en-US
use-responsive.zh-CN
use-theme-mode.en-US
use-theme-mode.zh-CN
use-theme.en-US
use-theme.zh-CN