Avatar

Used to represent users or things, supporting the display of images, icons, or characters.
Importimport{ Avatar }from"antd";

Examples

Three sizes and two shapes are available.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
U

For letter type Avatar, when the letters are too long to display, the font size can be automatically adjusted according to the width of the Avatar. You can also use gap to set the unit distance between left and right sides.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
K+2
K+2
K+2
AK

Avatar group display.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
U
USER
avatar
U

Image, Icon and letter are supported, and the latter two kinds of avatar can have custom colors and background colors.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
1

Usually used for reminders and notifications.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

Avatar size can be automatically adjusted based on the screen size.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

API

Common props ref:Common props

Avatar

PropertyDescriptionTypeDefaultVersion
altThis attribute defines the alternative text describing the imagestring-
gapLetter type unit distance between left and right sidesnumber44.3.0
iconCustom icon type for an icon avatarReactNode-
shapeThe shape of avatarcircle | squarecircle
sizeThe size of the avatarnumber | large | small | default | { xs: number, sm: number, ...}default4.7.0
srcThe address of the image for an image avatar or image elementstring | ReactNode-ReactNode: 4.8.0
srcSetA list of sources to use for different screen resolutionsstring-
draggableWhether the picture is allowed to be draggedboolean | 'true' | 'false'true
crossOriginCORS settings attributes'anonymous' | 'use-credentials' | ''-4.17.0
onErrorHandler when img load error, return false to prevent default fallback behavior() => boolean-

Tip: You can set icon or children as the fallback for image load error, with the priority of icon > children

Avatar.Group (4.5.0+)

PropertyDescriptionTypeDefaultVersion
maxSet maximum display related configurations, Before 5.18.0 you can use parameters{ count?: number; style?: CSSProperties; popover?: PopoverProps }-5.18.0
sizeThe size of the avatarnumber | large | small | default | { xs: number, sm: number, ...}default4.8.0
shapeThe shape of the avatarcircle | squarecircle5.8.0

Design Token

Component TokenHow to use?

Token NameDescriptionTypeDefault Value
containerSizeSize of Avatarnumber32
containerSizeLGSize of large Avatarnumber40
containerSizeSMSize of small Avatarnumber24
groupBorderColorBorder color of avatars in a groupstring#ffffff
groupOverlappingOverlapping of avatars in a groupnumber-8
groupSpaceSpacing between avatars in a groupnumber4
textFontSizeFont size of Avatarnumber18
textFontSizeLGFont size of large Avatarnumber24
textFontSizeSMFont size of small Avatarnumber14

Global TokenHow to use?