Dosu LogoDosu Logo
Ask
Join our Discord
Ant DesignPublic
Ant Design
DocumentsAnt Design
switch-theme.en-US
switch-theme.en-US
Type
External
Status
Published
Created
Jun 12, 2026
Updated
Jun 12, 2026
Source
docs/guide/switch-theme.en-US.md

Theme Switching#

Nowadays, the ability to switch between light and dark themes has gradually become a default feature on PCs, mobile phones, and other devices. Browsers also provide the ability to use media queries to help us quickly adapt to light themes. In Ant Design V5, we have implemented a more elegant runtime theme switching capability based on the Css in Js.

However, due to Ant Design's positioning as a basic component, it only provides basic APIs for theme capabilities and does not offer an out-of-the-box solution for application-level dynamic themes. Therefore, antd-style provides a complete application-level dynamic theme solution based on Ant Design's dynamic theme foundation.

1. Switching between Light and Dark Themes#

By modifying the appearance props on the container component ThemeProvider, you can achieve theme switching. This is also the simplest way to use dynamic themes.

import { ThemeProvider } from 'antd-style';

export default () => {
  return (
    // Automatically switch to dark mode
    <ThemeProvider appearance={'dark'}>
      <App />
    </ThemeProvider>
  );
};

If

In Ant Design V5, the static methods like message, notification, and modal do not respond to themes. It is recommended to use the hook versions of the static methods.

If you need to use these three static methods and also want them to respond to themes, please refer to Static Method Theme Response.

2. Automatically Responding to System Themes#

After introducing the above solution, attentive individuals should notice that this approach heavily relies on manual theme switching by users. However, the system-level theme switching on mobile phones and computers is generally automatically completed over time and usually does not require manual operation by users. Therefore, a modern theme switching capability should provide an "automatic" mode like macOS does.

In ThemeProvider, we provide the themeMode prop. For scenarios that do not require manual control of themes, you can directly set themeMode="auto" to achieve automatic switching of system theme modes with one click.

import { ThemeProvider } from 'antd-style';

export default () => {
  return (
    <ThemeProvider themeMode={'auto'}>
      <App />
    </ThemeProvider>
  );
};

:::info{title=What is the difference between appearance and themeMode?}
appearance describes the current appearance state of the application, while themeMode is used to describe the logic for controlling theme modes. Distinguishing between the two helps to achieve advanced theme capabilities.

See discussion: #52
:::

3. Controlled Mode for Theme Switching#

However, in many scenarios, we need to provide users with the autonomy to switch modes as they wish. We provide the useThemeMode hook, which is used to obtain the current theme mode and the capability to switch theme modes.

In addition to the useThemeMode hook, controlled mode can also be implemented through the themeMode prop.

Warning

Note: It is currently not recommended to simultaneously control themeMode and appearance, as this may lead to unexpected issues. The linkage capability in this area will be enhanced in the future.

4. Customizing Themes with Theme Configuration#

Ant Design V5's ConfigProvider provides theme configuration, allowing you to pass in a custom theme object to customize the theme.

/**
 * Custom theme algorithm
 */
const customDarkAlgorithm = (seedToken, mapToken) => {
  const mergeToken = theme.darkAlgorithm(seedToken, mapToken);

  return {
    ...mergeToken,
    colorBgLayout: '#20252b',
    colorBgContainer: '#282c34',
    colorBgElevated: '#32363e',
  };
};

export default () => (
  <ThemeProvider
    themeMode={'dark'}
    // Supports passing in a method to dynamically respond to appearance
    theme={(appearance) =>
      appearance === 'dark'
        ? // Custom dark theme
          {
            token: { borderRadius: 2 },
            algorithm: [customDarkAlgorithm],
          }
        : // Use default values for light theme
          undefined
    }
    <App />
  </ThemeProvider>
);

API#

Refer to the APIs related to theme switching: ThemeProvider

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