Learn Ant-design - 10 Code Examples & CST Typing Practice Test
Ant Design (AntD) is a comprehensive, enterprise-class UI design system and React component library for building modern web applications. It provides high-quality prebuilt components, design guidelines, and a unified visual language.
View all 10 Ant-design code examples →
Learn ANT-DESIGN with Real Code Examples
Updated Nov 23, 2025
Code Sample Descriptions
Ant Design Counter Example
import React, { useState } from 'react';
import { Button, Typography, Space, ConfigProvider, theme } from 'antd';
const { Title } = Typography;
const Counter = () => {
const [count, setCount] = useState(0);
const [isDark, setIsDark] = useState(false);
return (
<ConfigProvider theme={{ token: { colorPrimary: isDark ? '#1f1f1f' : '#1890ff' }, algorithm: isDark ? theme.darkAlgorithm : theme.defaultAlgorithm }}>
<div style={{ textAlign: 'center', marginTop: '50px' }}>
<Title level={2}>Counter: {count}</Title>
<Space>
<Button type='primary' onClick={() => setCount(count + 1)}>+</Button>
<Button type='primary' danger onClick={() => setCount(count - 1)}>-</Button>
<Button onClick={() => setCount(0)}>Reset</Button>
</Space>
<br /><br />
<Button type='default' onClick={() => setIsDark(!isDark)}>Switch Theme</Button>
</div>
</ConfigProvider>
);
};
export default Counter;
Demonstrates a simple counter layout using Ant Design components and React for interactivity.
Ant Design Button Example
import React from 'react';
import { Button, Space } from 'antd';
const ButtonExample = () => (
<div style={{ textAlign: 'center', marginTop: '50px' }}>
<Space>
<Button type='primary'>Primary</Button>
<Button type='default'>Default</Button>
<Button type='dashed'>Dashed</Button>
<Button type='link'>Link</Button>
<Button type='text'>Text</Button>
</Space>
</div>
);
export default ButtonExample;
Shows different button types and sizes using Ant Design.
Ant Design Card Example
import React from 'react';
import { Card, Button } from 'antd';
const { Meta } = Card;
const CardExample = () => (
<div style={{ display: 'flex', justifyContent: 'center', marginTop: '50px' }}>
<Card style={{ width: 300 }} actions={[<Button>Learn More</Button>]}>
<Meta title='Card Title' description='This is an Ant Design card example.' />
</Card>
</div>
);
export default CardExample;
Displays a simple card component with title, content, and actions.
Ant Design Modal Example
import React, { useState } from 'react';
import { Button, Modal } from 'antd';
const ModalExample = () => {
const [visible, setVisible] = useState(false);
return (
<div style={{ textAlign: 'center', marginTop: '50px' }}>
<Button type='primary' onClick={() => setVisible(true)}>Open Modal</Button>
<Modal title='Modal Title' open={visible} onOk={() => setVisible(false)} onCancel={() => setVisible(false)}>
<p>This is a simple Ant Design modal.</p>
</Modal>
</div>
);
};
export default ModalExample;
Demonstrates opening and closing a modal dialog with Ant Design.
Ant Design Tabs Example
import React from 'react';
import { Tabs } from 'antd';
const { TabPane } = Tabs;
const TabsExample = () => (
<div style={{ margin: '50px' }}>
<Tabs defaultActiveKey='1'>
<TabPane tab='Tab 1' key='1'>Content of Tab 1</TabPane>
<TabPane tab='Tab 2' key='2'>Content of Tab 2</TabPane>
<TabPane tab='Tab 3' key='3'>Content of Tab 3</TabPane>
</Tabs>
</div>
);
export default TabsExample;
Shows a tabbed interface using Ant Design Tabs component.
Ant Design Form Example
import React from 'react';
import { Form, Input, Button } from 'antd';
const FormExample = () => {
const onFinish = values => console.log('Form values:', values);
return (
<div style={{ maxWidth: 400, margin: '50px auto' }}>
<Form onFinish={onFinish} layout='vertical'>
<Form.Item label='Name' name='name' rules={[{ required: true, message: 'Please enter your name' }]}>
<Input />
</Form.Item>
<Form.Item label='Email' name='email' rules={[{ required: true, type: 'email', message: 'Please enter a valid email' }]}>
<Input />
</Form.Item>
<Form.Item>
<Button type='primary' htmlType='submit'>Submit</Button>
</Form.Item>
</Form>
</div>
);
};
export default FormExample;
Shows a basic form with input fields and submit button using Ant Design.
Ant Design Alert / Notification Example
import React from 'react';
import { Alert } from 'antd';
const AlertExample = () => (
<div style={{ margin: '50px' }}>
<Alert message='Success Text' type='success' showIcon />
<Alert message='Info Text' type='info' showIcon />
<Alert message='Warning Text' type='warning' showIcon />
<Alert message='Error Text' type='error' showIcon />
</div>
);
export default AlertExample;
Shows an alert notification using Ant Design Alert component.
Ant Design Progress Example
import React, { useState, useEffect } from 'react';
import { Progress } from 'antd';
const ProgressExample = () => {
const [percent, setPercent] = useState(0);
useEffect(() => { const interval = setInterval(() => setPercent(p => (p >= 100 ? 0 : p + 10)), 1000); return () => clearInterval(interval); }, []);
return <div style={{ margin: '50px' }}><Progress percent={percent} /></div>;
};
export default ProgressExample;
Displays a linear progress bar using Ant Design Progress component.
Ant Design Accordion / Collapse Example
import React from 'react';
import { Collapse } from 'antd';
const { Panel } = Collapse;
const CollapseExample = () => (
<div style={{ margin: '50px' }}>
<Collapse defaultActiveKey={['1']}>
<Panel header='Panel 1' key='1'>Content of Panel 1</Panel>
<Panel header='Panel 2' key='2'>Content of Panel 2</Panel>
<Panel header='Panel 3' key='3'>Content of Panel 3</Panel>
</Collapse>
</div>
);
export default CollapseExample;
Demonstrates collapsible panels using Ant Design Collapse component.
Ant Design Tooltip Example
import React from 'react';
import { Button, Tooltip } from 'antd';
const TooltipExample = () => (
<div style={{ textAlign: 'center', margin: '50px' }}>
<Tooltip title='Click me!'>
<Button type='primary'>Hover me</Button>
</Tooltip>
</div>
);
export default TooltipExample;
Shows a button with a tooltip using Ant Design Tooltip component.
Frequently Asked Questions about Ant-design
What is Ant-design?
Ant Design (AntD) is a comprehensive, enterprise-class UI design system and React component library for building modern web applications. It provides high-quality prebuilt components, design guidelines, and a unified visual language.
What are the primary use cases for Ant-design?
Enterprise web applications and admin dashboards. Data-centric applications and management panels. React-based frontend development. Rapid prototyping with a unified design language. Projects needing standardized and accessible UI components
What are the strengths of Ant-design?
Enterprise-grade quality and reliability. Large library of ready-to-use React components. Consistent, structured design system. Customizable themes and style tokens. Well-documented with active community support
What are the limitations of Ant-design?
Primarily React-based (not framework-agnostic). Bundle size can be large if unused components included. Steeper learning curve for beginners. Custom styling may require LESS knowledge. Less suited for ultra-minimal or lightweight projects
How can I practice Ant-design typing speed?
CodeSpeedTest offers 10+ real Ant-design code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.