Close

2023-11-01

Using Ant Design in ReactJS

Using Ant Design in ReactJS

Ant Design is a popular enterprise-class UI design language and React UI library. It offers a comprehensive set of high-quality React components that can be easily integrated into React applications. In this article, we’ll explore how to set up and use Ant Design in a ReactJS project, complete with code samples.

Setting Up Ant Design in React

  1. Create a New React Project:
    If you haven’t already, start by creating a new React project using Create React App:
   npx create-react-app ant-design-demo
  1. Install Ant Design:
    Navigate to your project directory and install the antd Package using npm or yarn:
   cd ant-design-demo
   npm install antd
  1. Import Ant Design CSS:
    In your src/App.css or src/index.cssImport the Ant Design stylesheet:
   @import '~antd/dist/antd.css';

Using Ant Design Components

  1. Importing Components:
    You can now import any Ant Design component into your React components. For instance, to use the Button component:
   import { Button } from 'antd';
  1. Using the Component:
    Once imported, you can use the component in your JSX:
   function App() {
     return (
       <div className="App">
         <Button type="primary">Click Me</Button>
       </div>
     );
   }
  1. Customizing Components:
    Ant Design components come with various props to customize their behavior and appearance. For example, to create a large-sized button:
   <Button type="primary" size="large">Large Button</Button>

Advanced Usage

  1. Using Icons:
    Ant Design provides a set of icons that can be used with its components. To use them, you’ll need to install the @ant-design/icons package:
   npm install @ant-design/icons

Then, you can import and use the icons:

   import { SmileOutlined } from '@ant-design/icons';

   <Button icon={<SmileOutlined />}>Smile Button</Button>
  1. Custom Theming:
    Ant Design allows for custom theming using Fewer variables. You can override default values to customize the appearance of components. This requires additional setup with tools like craco and less-loader.
  2. Grid System:
    Ant Design provides a responsive grid system. The Row and Col Components can be used to create grid layouts:
   import { Row, Col } from 'antd';

   <Row>
     <Col span={12}>Column 1</Col>
     <Col span={12}>Column 2</Col>
   </Row>


Ant Design offers a rich set of components that can elevate the UI of any React application. With its easy integration and comprehensive documentation, developers can quickly build elegant and functional user interfaces. Whether you’re building a simple web app or an enterprise-grade system, Ant Design’s components can be a valuable addition to your React toolkit.