Avatar
Used to represent users or things, supporting the display of images, icons, or characters.
Examples
-
Basic ·
basic -
Type ·
type -
Autoset Font Size ·
dynamic -
With Badge ·
badge -
Avatar.Group ·
group -
maxCount includes overflow ·
max-count -
Responsive Size ·
responsive
API
Common props ref:Common props
Avatar
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| alt | This attribute defines the alternative text describing the image | string | - | × | |
| gap | Letter type unit distance between left and right sides | number | 4 | 4.3.0 | × |
| icon | Custom icon type for an icon avatar | ReactNode | - | × | |
| shape | The shape of avatar | circle | square | circle | × | |
| size | The size of the avatar | number | large | medium | small | { xs: number, sm: number, ...} | medium | 4.7.0 | × |
| src | The address of the image for an image avatar or image element | string | ReactNode | - | ReactNode: 4.8.0 | × |
| srcSet | A list of sources to use for different screen resolutions | string | - | × | |
| draggable | Whether the picture is allowed to be dragged | boolean | 'true' | 'false' | true | × | |
| crossOrigin | CORS settings attributes | 'anonymous' | 'use-credentials' | '' | - | 4.17.0 | × |
| onError | Handler when img load error, return false to prevent default fallback behavior | () => boolean | - | × |
Tip: You can set
iconorchildrenas the fallback for image load error, with the priority oficon>children
Avatar.Group <Badge>4.5.0+</Badge>
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| max | Set maximum display related configurations | { count?: number; style?: CSSProperties; popover?: PopoverProps } | - | 5.18.0 |
Deprecated, please use max={{ count: number }} | number | - | ||
Deprecated, please use max={{ popover: PopoverProps }} | top | bottom | top | ||
Deprecated, please use max={{ popover: PopoverProps }} | hover | focus | click | hover | ||
Deprecated, please use max={{ style: CSSProperties }} | CSSProperties | - | ||
| size | The size of the avatar | number | large | medium | small | { xs: number, sm: number, ...} | medium | 4.8.0 |
| shape | The shape of the avatar | circle | square | circle | 5.8.0 |
Design Token
Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.
| Token | Type | Native description |
|---|---|---|
containerSize | number | Size of Avatar |
containerSizeLG | number | Size of large Avatar |
containerSizeSM | number | Size of small Avatar |
textFontSize | number | Font size of Avatar |
textFontSizeLG | number | Font size of large Avatar |
textFontSizeSM | number | Font size of small Avatar |
iconFontSize | number | Font size of Avatar icon |
iconFontSizeLG | number | string | Font size of large Avatar icon |
iconFontSizeSM | number | Font size of small Avatar icon |
groupSpace | number | Spacing between avatars in a group |
groupOverlapping | number | Overlapping of avatars in a group |
groupBorderColor | string | Border color of avatars in a group |
Declaration source: vendor/components/avatar/style/index.ts
import type { CSSProperties } from 'react';
import { unit } from '@ant-design/cssinjs';
import type { CSSObject } from '@ant-design/cssinjs';
import { resetComponent } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
export interface ComponentToken {
/**
* @desc 头像尺寸
* @descEN Size of Avatar
*/
containerSize: number;
/**
* @desc 大号头像尺寸
* @descEN Size of large Avatar
*/
containerSizeLG: number;
/**
* @desc 小号头像尺寸
* @descEN Size of small Avatar
*/
containerSizeSM: number;
/**
* @desc 头像文字大小
* @descEN Font size of Avatar
*/
textFontSize: number;
/**
* @desc 大号头像文字大小
* @descEN Font size of large Avatar
*/
textFontSizeLG: number;
/**
* @desc 小号头像文字大小
* @descEN Font size of small Avatar
*/
textFontSizeSM: number;
/**
* @desc 头像图标大小
* @descEN Font size of Avatar icon
*/
iconFontSize: number;
/**
* @desc 大号头像图标大小
* @descEN Font size of large Avatar icon
*/
iconFontSizeLG: number | string;
/**
* @desc 小号头像图标大小
* @descEN Font size of small Avatar icon
*/
iconFontSizeSM: number;
/**
* @desc 头像组间距
* @descEN Spacing between avatars in a group
*/
groupSpace: number;
/**
* @desc 头像组重叠宽度
* @descEN Overlapping of avatars in a group
*/
groupOverlapping: number;
/**
* @desc 头像组边框颜色
* @descEN Border color of avatars in a group
*/
groupBorderColor: string;
}
/**
* @desc Avatar 组件的 Token
* @descEN Token for Avatar component
*/
type AvatarToken = FullToken<'Avatar'> & {
avatarBgColor: string;
avatarBg: string;
avatarColor: string;
};
Shared native props
Tips: The following generic properties apply to most antd components; those not supported are described separately.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
Install and reproduce an example
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23
Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.
Native type references
The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.
vendor/components/avatar/Avatar.tsxvendor/components/avatar/AvatarContext.tsvendor/components/avatar/AvatarGroup.tsxvendor/components/avatar/index.tsxvendor/components/avatar/style/index.ts
Source and license
https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd
Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.