How to use Ant Design icons in React

What is antd?

Ant Design (antd) is a popular UI library for React applications. It provides a set of high-quality and customizable components and styles that help developers create modern, responsive, and user-friendly interfaces for their applications quickly and easily.

The antd library includes a wide range of components such as icons, buttons, forms, tables, modals, and more, as well as powerful features like theme customization and accessibility support.

The antd icons are a collection of customizable icons in the Ant Design library. These icons can be used in React projects to add visual elements to different UI components. The antd icons provide a wide range of basic icons, outlined icons, two-tone icons, and more. These icons can be used in various sizes, colors, and styles to fit a project's design requirements.

Installation

We can install antd icons in our React project using npm or yarn. Here are the two commands that can be used:

//npm install
npm install antd
npm install @ant-design/icons
//yarn install
yarn add antd
yarn add @ant-design/icons
Installing antd Icons

Code example

Let's look at an example of using antd icons in a simple React application:

Explanation

  • Line 2: We import the Button and Space components from the antd library.

  • Lines 3–10: We import different icons from antd Icons.

  • Line 16: We use the Space component with direction="vertical" to display the buttons vertically.

  • Lines 17–30: We add six buttons with different properties and icons which we imported above.

Copyright ©2024 Educative, Inc. All rights reserved