2017-05-28 14:20:59 +08:00
---
category: Components
title: Avatar
2024-03-22 14:22:42 +08:00
description: Used to represent users or things, supporting the display of images, icons, or characters.
2022-11-30 20:14:41 +08:00
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*JJBSS5lBG4IAAAAAAAAAAAAADrJ8AQ/original
2023-02-09 22:17:31 +08:00
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*YbgyQaRGz-UAAAAAAAAAAAAADrJ8AQ/original
2022-11-09 12:28:04 +08:00
demo:
cols: 2
group:
title: Data Display
order: 5
2017-05-28 14:20:59 +08:00
---
2022-11-09 12:28:04 +08:00
## Examples
2022-11-17 17:31:26 +08:00
<!-- prettier - ignore -->
2022-11-09 12:28:04 +08:00
< code src = "./demo/basic.tsx" > Basic< / code >
< code src = "./demo/type.tsx" > Type< / code >
< code src = "./demo/dynamic.tsx" > Autoset Font Size< / code >
< code src = "./demo/badge.tsx" > With Badge< / code >
< code src = "./demo/group.tsx" > Avatar.Group< / code >
< code src = "./demo/toggle-debug.tsx" debug > Calculate text style when hiding< / code >
< code src = "./demo/responsive.tsx" > Responsive Size< / code >
< code src = "./demo/fallback.tsx" debug > Fallback< / code >
2023-05-26 17:59:13 +08:00
< code src = "./demo/component-token.tsx" debug > Component Token< / code >
2022-11-09 12:28:04 +08:00
2017-05-28 14:20:59 +08:00
## API
2023-08-08 18:27:48 +08:00
Common props ref: [Common props](/docs/react/common-props)
2020-07-13 12:45:37 +08:00
### Avatar
2019-07-11 14:14:33 +08:00
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
2020-10-21 10:33:43 +08:00
| 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 |
2020-07-01 21:35:29 +08:00
| icon | Custom icon type for an icon avatar | ReactNode | - | |
| shape | The shape of avatar | `circle` \| `square` | `circle` | |
2020-11-02 11:31:42 +08:00
| size | The size of the avatar | number \| `large` \| `small` \| `default` \| { xs: number, sm: number, ...} | `default` | 4.7.0 |
| src | The address of the image for an image avatar or image element | string \| ReactNode | - | ReactNode: 4.8.0 |
2020-07-01 21:35:29 +08:00
| srcSet | A list of sources to use for different screen resolutions | string | - | |
2023-03-09 17:37:22 +08:00
| draggable | Whether the picture is allowed to be dragged | boolean \| `'true'` \| `'false'` | true | |
2021-07-06 12:16:46 +08:00
| crossOrigin | CORS settings attributes | `'anonymous'` \| `'use-credentials'` \| `''` | - | 4.17.0 |
2020-07-01 21:35:29 +08:00
| onError | Handler when img load error, return false to prevent default fallback behavior | () => boolean | - | |
2020-06-12 15:26:40 +08:00
> Tip: You can set `icon` or `children` as the fallback for image load error, with the priority of `icon` > `children`
2020-07-13 12:45:37 +08:00
### Avatar.Group (4.5.0+)
2021-07-06 14:40:58 +08:00
| Property | Description | Type | Default | Version |
2020-10-21 10:33:43 +08:00
| --- | --- | --- | --- | --- |
2024-06-01 14:44:53 +08:00
| max | Set maximum display related configurations, Before `5.18.0` you can use [parameters ](https://github.com/ant-design/ant-design/blob/9d134859becbdae5b9ce276f6d9af4264691d81f/components/avatar/group.tsx#L35-L38 ) | `{ count?: number; style?: CSSProperties; popover?: PopoverProps }` | - | 5.18.0 |
2020-10-24 22:00:43 +08:00
| size | The size of the avatar | number \| `large` \| `small` \| `default` \| { xs: number, sm: number, ...} | `default` | 4.8.0 |
2023-07-27 20:04:32 +08:00
| shape | The shape of the avatar | `circle` \| `square` | `circle` | 5.8.0 |
2023-04-11 10:25:24 +08:00
## Design Token
< ComponentTokenTable component = "Avatar" > < / ComponentTokenTable >