Ant Design Theme Customization with Design Tokens

Ant Design theme customization panel with token sliders and blue and coral component presets

Ant Design theme customization revolves around design tokens, named values that control colors, spacing, radius and typography across every component. Change a token once and buttons, inputs, tags and menus update together, which keeps an interface consistent without hunting down CSS selectors.

This article explains the token layers, global and component-level overrides, dark and compact algorithms and how the CSS variable approach in version 6 affects theming. Examples use the React package, and similar concepts apply in Ant Design Vue with its own syntax.

How Tokens Are Organized

Tokens come in layers. Seed tokens hold the basic decisions, such as primary color and base radius. Map tokens are derived from seeds through an algorithm, and alias tokens give friendly names to common combinations used by many components.

LayerExampleTypical use
Seed tokencolorPrimary, borderRadiusBrand-level decisions
Map tokencolorPrimaryHover, colorPrimaryBgGenerated variations
Alias tokencolorLink, controlOutlineShared semantic values
Component tokenButton primaryShadowSingle component tweaks

Setting Global Tokens

Pass a theme object to ConfigProvider at the root of the app. Changing colorPrimary alone recolors interactive elements, and adding radius or font size adjusts the overall feel.

<ConfigProvider
  theme={{
    token: {
      colorPrimary: '#1b8be0',
      borderRadius: 8,
      fontFamily: 'Poppins, Arial, sans-serif',
    },
  }}
>
  <App />
</ConfigProvider>

Component-Level Overrides

Sometimes one component needs a different look without affecting the rest. The components key accepts per-component tokens, so you can, for example, make buttons rounder or change a menu background while keeping global values intact.

theme={{
  components: {
    Button: { borderRadius: 20 },
    Menu: { itemSelectedBg: '#e6f4ff' },
  },
}}

Check each component's documentation for its token list, since names are specific to the component and some only exist in newer versions.

Dark and Compact Algorithms

Algorithms transform seed tokens into a full palette. The library includes a default algorithm, a dark algorithm and a compact algorithm, and you can combine them by passing an array.

import { theme } from 'antd';

<ConfigProvider theme={{ algorithm: [theme.darkAlgorithm, theme.compactAlgorithm] }}>
  • Use the dark algorithm for night modes or dense data dashboards.
  • Use the compact algorithm when screens hold many controls.
  • Let users switch modes by storing the choice and swapping algorithms.

Reading Tokens in Your Own Code

Custom components should follow the same palette. The theme.useToken() hook returns the current token values, letting a chart or custom card use the active primary color and radius instead of hardcoded numbers.

Nested themes

ConfigProvider can be nested, so a section of the page can use a different theme from the rest. Marketing banners, previews or embedded widgets benefit from this without separate builds.

CSS Variables in Version 6

Version 6 adopted a pure CSS variable styling architecture. Token values become CSS custom properties, which helps theme switching and reduces runtime style work, and Ant Design Pro 6 enables this mode with several presets.

Building a Brand Theme Step by Step

Begin with the few seeds that define your brand: primary color, radius and font family. Apply them globally, review key screens and only then adjust individual components. Working from broad to specific prevents a tangle of overrides that conflict with each other.

Keep the theme object in its own module so every entry point imports the same values. That single source of truth makes design reviews easier and lets you test a new palette by changing one file.

  • Define seed tokens for brand color, radius and font.
  • Review forms, tables and menus before component tweaks.
  • Store the theme object in one shared module.
  • Document custom component tokens for the team.

Accessibility and Contrast

Brand colors do not always meet contrast requirements on white backgrounds. Check primary buttons, links and focus outlines with a contrast tool, and choose a darker shade for text use if the brand color is too light.

Status colors need the same attention. Success, warning and error states should remain distinguishable for people with color vision deficiencies, so pair colors with icons or text labels rather than relying on hue alone.

Testing Theme Changes

A theme change touches every screen, so visual regression tests are valuable. Capturing screenshots of representative pages before and after a token update reveals unintended changes in spacing, contrast or component states.

Storybook-style component galleries also help. Rendering each component in default, hover, disabled and error states under the new theme exposes problems that rarely appear during normal clicking through the app.

Migrating Older Less Variables

Projects that started on version 4 may still contain Less variable overrides. Those variables no longer drive styling in newer versions, so translate each one into the matching token and remove the old build configuration once the new theme renders correctly.

Switching Themes at Runtime

Because themes are plain objects, switching between them is a state change. Store the user's preference, pick the matching algorithm and tokens, and pass them to ConfigProvider so the interface updates without reloading the page.

Respecting the operating system's color scheme is a friendly default. Reading the prefers-color-scheme media query on first load, then letting users override it, covers both automatic and manual preferences.

  • Keep light and dark theme objects side by side.
  • Store the user's choice in local storage.
  • Default to the system color scheme on first visit.

Sharing Themes Across Projects

Organizations with several applications often publish their theme as a small internal package. Each app imports the same tokens, which keeps branding aligned and makes a palette update a single version bump instead of many manual edits.

Frequently Asked Questions

Can I change the primary color without CSS overrides?

Yes. Set the colorPrimary token in ConfigProvider and all components that use it update automatically.

Does dark mode need a separate stylesheet?

No. Apply theme.darkAlgorithm through ConfigProvider to generate a dark palette.

How do I style just one component?

Use the components key in the theme object to override that component's tokens.

Where are token names listed?

The theme documentation and each component's API page list the available tokens.

Conclusion

Ant Design theme customization works best when every visual decision lives in tokens. Set brand seeds globally, refine individual components with component tokens, apply dark or compact algorithms when needed and read tokens in custom code so the whole interface moves together.

Review contrast after every palette change and keep visual tests running, so brand updates never weaken usability. A well-maintained token set lets designers and developers discuss changes in shared terms.