---
title: "How to Customize a React Theme Using Ant Design"
description: "Ant design is a great UI tool with readymade components you can use and customize to build elegant user interfaces. No wonder it is the highest rated project on GitHub! If you liked this article and would like to get more such interesting ones delivered to your inbox, consider signing up to our…"
url: https://www.specbee.com/blogs/how-to-customize-react-theme-using-ant-design
type: Article
author: "Vinit Kumar"
categories: "Code Corner"
published: 2022-03-01
updated: 2026-10-07
---

# How to Customize a React Theme Using Ant Design

It’s a bit of an understatement to say good User Interface (UI) design plays a huge role in engaging your website audience and leading them to a conversion. While any good UI requires interactive, intuitive, rich and accessible design - a seemingly daunting challenge - it’s achievable when you use high-quality components and libraries to build it.

The most popular of these is Ant design. It’s a React UI library that has access to easy-to-use, quality components for building elegant and fast user interfaces.

 ![React theme](https://www.specbee.com/sites/default/files/styles/large/public/migrated/React_theme_ant_design_0.jpg.avif?itok=a36PZSw_)

 

 ## Why Ant Design?

Created by Alibaba, the Ant design system is used by several big names like Alibaba (of course), Tencent, Baidu, and more.

 ![Ant](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Ant_0.png.avif?itok=MGQ-brsT)

 

  ![Alibaba](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Alibaba_0.png.avif?itok=Myo6o9O1)

 

  ![Ant Design](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Ant_design_0.png.avif?itok=v-vBlBD2)

 

  ![Material](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Material_0.png.avif?itok=GEweP68V)

 

 It has fast become the most used React UI library. Previously Material-UI was the most popular with over 75k stars on Github, but Ant Design has now overtaken them with 77.5k!

What Ant design has done so well is humanizing their design. They evaluate quality of design by measuring against four human-consciousness and happiness centric values - naturalness, certainty, meaningfulness, and growth. Those act as a standard for designers and guide them in decision-making and better judgment.

## Ant Design Components

Ant design (or antd) offers many rich UI components that can enhance your website or app experience. Check out some of them below but for more options, visit [here](https://ant.design/components/overview-cn/).

**Universal Components:** Buttons, icons, typography, etc.

 ![Universal](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Universal_0.png.avif?itok=Y-AI5GG8)

 

 **Layouts:** Grids, layouts, spacing, etc.

 ![Layouts](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Layout_1.png.avif?itok=HGId8bg4)

 

 **Navigation:** Breadcrumbs, menus, dropdown menus, etc.

 ![Navigation](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Navigation_0.png.avif?itok=RA7L7jqx)

 

 **Data Entry:** Autocomplete, checkbox, date picker, etc.

 ![Data Entry](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Data_entry_0.png.avif?itok=Pr68cdoV)

 

 **Data Display:** Avatar, comments, collapsible panels, etc.

 ![Data Display](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Data_display_0.png.avif?itok=I4lo6YvW)

 

 ## Installing React and Ant Design

Now that we know what components are available in Ant design, let’s learn the basic installation process of React and then install Ant design in it.

You can use **yarn** or **npm** to set up the React project. Below are the basic commands to install and set up React:

```plaintext
$ yarn create react-app antd-demo

# or

$ npx create-react-app antd-demo

$ cd antd-demo
$ yarn start
```

Once React is installed, you can see the running app in the browser.

 ![Edit src app](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Src_app_0.png.avif?itok=d8mEKurL)

 

 This is the default generated directory in the newly created project. Going forward, we will be modifying some of the files here to achieve the final output.

```plaintext
├── README.md
├── package.json
├── public
│   ├── favicon.ico
│   └── index.html
├── src
│   ├── App.css
│   ├── App.js
│   ├── App.test.js
│   ├── index.css
│   ├── index.js
│   └── logo.svg
└── yarn.lock
```

Now after setting up React, let’s install Ant design in it with this command:

```plaintext
$ yarn add antd
```

After installing antd, you can use the Ant components by modifying the markup in App.js that is inside the src folder in your project. Here, I am adding a button element from Ant.

```javascript
import React from 'react';
import { Button } from 'antd';
import './App.css';

const App = () => (
  <div className="App">
    <Button type="primary">Button</Button>
  </div>
);

export default App;
```

### Ant button component:

 ![Button](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Button_1.png.avif?itok=oyV2Y7tF)

 

 Once you save and run the app, you will be able to see the Ant primary button element in the browser in blue color (as shown above). This means that Ant is successfully integrated in React.

## Customizing a Theme

The best part about integrating Ant Design with React is that it allows you to customize your design tokens to satisfy UI diversity from business or brand requirements, including primary color, border radius, border color, etc.

 ![Intoli](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Intoli_0.png.avif?itok=GeKmBFOH)

 

 *Image credits :* [*Intoli*](https://intoli.com/)

To allow these customization, you will need to do some advanced configurations.

### Advance Configuration:

At this point you need to customize the default configurations of create-react-app. Let’s use **CRACO** (Create React App Configuration Override) - a community solution for custom configuration of create-react-app.

**Step 1:** You will first need to install CRACO and replace the default React-script with CRACO in **package.json.**

```plaintext
$ yarn add @craco/craco

/* package.json */
"scripts": {
-   "start": "react-scripts start",
-   "build": "react-scripts build",
-   "test": "react-scripts test",
+   "start": "craco start",
+   "build": "craco build",
+   "test": "craco test",
}
```

According to the requirements of [configuring](https://ant.design/docs/react/customize-theme-cn) the theme, the custom theme needs to use the Less variable override function similar to that provided by [less-loader](https://github.com/webpack-contrib/less-loader/). We can introduce [Craco-less](https://github.com/DocSpring/craco-less) to help load less styles and modify variables.

```plaintext
$ yarn add craco-less
```

**Step 2:** Modify the src/App.css **file to** src/App.less, and import **antd.less** file over antd.css in app.less

```plaintext
/* src/App.js */
- import './App.css';

+ import './App.less';

/* src/App.less */
- @import '~antd/dist/antd.css';

+ @import '~antd/dist/antd.less';
```

**Step 3:** Create craco.config.js in the root directory to modify the default configuration.

```javascript
const CracoLessPlugin = require('craco-less');
module.exports = {
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            modifyVars: { '@primary-color': '#1DA57A' },
            javascriptEnabled: true,
          },
        },
      },
    },
  ],
};
```

Here, [less-loader](https://github.com/webpack/less-loader#less-options) is modifyVars used for theme configuration.

 ![Button](https://www.specbee.com/sites/default/files/styles/large/public/migrated/Button_0_0.png.avif?itok=cjnzsCqM)

 

 If you see a green button, you know the configuration is successful. Now you can customize the theme with your own set of colors using the tokens/variables provided.

## Ant Design Style Variables

Below are some of the most commonly used generic variables. You can [visit](https://github.com/ant-design/ant-design/blob/master/components/style/themes/default.less) here to get details on all the available style variables.

```plaintext
@primary-color: #1890ff; // primary color for all components
@link-color: #1890ff; // link color
@success-color: #52c41a; // success state color
@warning-color: #faad14; // warning state color
@error-color: #f5222d; // error state color
@font-size-base: 14px; // major text font size
@heading-color: rgba(0, 0, 0, 0.85); // heading text color
@text-color: rgba(0, 0, 0, 0.65); // major text color
@text-color-secondary: rgba(0, 0, 0, 0.45); // secondary text color
@disabled-color: rgba(0, 0, 0, 0.25); // disable state color
@border-radius-base: 2px; // major border radius
@border-color-base: #d9d9d9; // major border color
@box-shadow-base: 0 3px 6px -4px rgba(0, 0, 0, 0.12), 0 6px 16px 0 rgba(0, 0, 0, 0.08),
  0 9px 28px 8px rgba(0, 0, 0, 0.05); // major shadow for layers
```

Ant design is a great UI tool with readymade components you can use and customize to build elegant user interfaces. No wonder it is the highest rated project on GitHub! If you liked this article and would like to get more such interesting ones delivered to your inbox, consider [signing up to our newsletter](https://specbee.us19.list-manage.com/subscribe?u=a3d560a1fc06522ef6c707339&id=689c8b7694).