Override Ant Design v5 Tokens at Runtime with ConfigProvider
Use ConfigProvider theme.token to override Ant Design v5 colors at runtime without a Less rebuild.
21 Nov 2026, 03:36 UTC

You just upgraded to Ant Design v5, and the brand color still looks like Ant Design’s default blue. In v4, you might have overridden Less variables in a webpack or Vite config and rebuilt stylesheets. That build-step approach does not carry over cleanly to v5, and maintaining a custom Less pipeline just to change a primary color is more work than it needs to be.
The practical takeaway: wrap your application—or just the part of it that needs a different look—in ConfigProvider and pass theme.token overrides. Ant Design v5 derives related colors from colorPrimary at runtime, so a single token change can update primary, info, success, warning, and error tones together without recompiling CSS.
Check the installed version first
Ant Design v5 theming APIs differ from v4 Less variable customization. Confirm you are on v5 before adopting the code below.
npm ls antd
Run this in your project root. No special permissions are required. Expected output includes antd@5.x.x. If you see antd@4.x.x, the v5 token API described here will not work, and you should follow the v4 Less variable documentation instead.
Override tokens with ConfigProvider
ConfigProvider is Ant Design’s React context component for theme configuration. The theme.token object accepts global design tokens such as colorPrimary, borderRadius, and fontSize. When you change a token, Ant Design’s default theme algorithm derives related palette colors automatically.
Here is a minimal worked example. Place this in a React component file, such as src/App.jsx:
import { ConfigProvider, Button, Space } from 'antd';
export default function ThemedApp() {
return (
Primary action
Success
Warning
Error
);
}
Where to run: in your React application’s component tree, typically at the top of your page or route layout. Required permissions: none beyond normal file edit access. Placeholders: replace #722ed1 with your brand color, and adjust borderRadius or fontSize as needed.
To verify, open the rendered page in browser DevTools, inspect a primary button, and check its computed background color. It should match the derived primary tone from colorPrimary, not Ant Design’s default blue. Change colorPrimary in your source and refresh; the button colors should update without a Less rebuild.
Use nested providers for different UI subtrees
You can nest ConfigProvider instances. The inner provider’s tokens override the outer provider’s tokens for that subtree only, while the rest of the application keeps the default theme. This is useful when one section of your app, such as a marketing landing page, needs a different brand color than the admin dashboard.
<ConfigProvider theme={{ token: { colorPrimary: '#1677ff' } }}>
<Dashboard />
<ConfigProvider theme={{ token: { colorPrimary: '#fa541c' } }}>
<LandingPage />
</ConfigProvider>
</ConfigProvider>
Keep custom components consistent with useToken
Components mounted before ConfigProvider, or custom components that do not read Ant Design’s theme context, may not reflect token overrides. Ant Design exposes the useToken hook so your own components can consume the same token context and stay consistent with the library theme.
For example, a custom badge component can read colorPrimary from useToken:
import { useToken } from 'antd';
function CustomBadge() {
const { token } = useToken();
return (
New
);
}
Trade-offs and limitations
- Not every Ant Design v4 Less variable maps cleanly to a v5 token. Some component-specific appearance still requires CSS,
styleprops, or custom style tokens. - Runtime theme generation adds client-side processing. Measure bundle and render impact in large applications before rolling this out broadly.
- Ant Design v5 assumes React 16.8 or newer because theming relies on hooks. Verify peer dependencies before adopting.
- If
ConfigProviderloads after components mount, users may see a flash of default-styled UI.
Practical verification and closing
After adding ConfigProvider, check three things:
npm ls antdreportsantd@5.x.x.- DevTools shows the expected computed color on themed components.
- Changing a token and refreshing updates component styles without rebuilding stylesheets.
If a component does not update, confirm it is rendered inside ConfigProvider and that custom components use useToken for colors derived from the theme. Runtime token overrides are usually the simpler path for v5 theming, but they are not a one-to-one replacement for every v4 Less customization, so review the official Ant Design v5 theming documentation for supported token names before finalizing your design system.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.