Ant Design Svelte

Avatar

Images, icons, initials and groups of participants with text adjustment, fallback and adaptive sizes.

When to use

An Avatar identifies a user, team, or entity with an image, icon, or initials. AvatarGroup joins members and shows hidden elements via +N. Notifications next to the avatar are added with a composition with Badge.

Contents and dimensions of the avatar

Content priority: src, then icon, then children. The string src creates a managed image; snippet allows you to pass your own markup. shape selects circle/square. size accepts small/medium/large, a number in pixels, or a map of breakpoint sizes.

Script Property Example
Select geometry size, shape Size and shape
Show photo, badge or initials src, icon, children Types of content
Fit long initials gap Text selection
React to Window Width responsive size Adaptability
Handle failed download onError Fallback

Text is automatically reduced within an unchanged container. gap leaves space on the sides of the text. The size map depends on the viewport; CSS defaults are used before mount, so the server does not know the size of the client window.

For string src, alt, srcSet, crossOrigin and draggable are available. If there is an error, Avatar shows an icon or text; onError with the result false cancels the fallback. Changing src starts a new attempt. If src is snippet, the image and its events are entirely owned by the application.

Group and limit of participants

AvatarGroup accepts items with a unique key and full label. label is used to identify the participant, text is used for initials. General size/shape applies to the group; a separate item can set its own Avatar settings.

max.count limits the number of visible participants, and the +N indicator is added separately. Zero disables the limit. If you need a total limit along with an indicator, the application reserves one place when overflowing, as in limit example.

max.style designs the indicator. max.popover specifies supported Popover properties; content replaces the list of hidden participants, title is the title. Managed open requires onOpenChange. By default, the contents of such a Popover are deleted after hiding.

Signatures and design

Photos need a meaningful alt if the name is not listed next to it. The decorative avatar next to the full name should not duplicate it for the screen reader. Avatar remains span: onclick itself does not add a button keyboard. To open your profile, use the available button or link.

ConfigProvider.avatar sets the class/style for avatars; record of a nested provider replaces the parent one. The group root does not automatically inherit this class/style. Avatar design tokens control the size, font, and overlap of the group. bind:nativeElement provides the native node after the mount.

A non-empty Avatar local prefixCls takes precedence over ConfigProvider.prefixCls. The empty string and undefined inherit a common prefix with the suffix -avatar, defaulting to ant-avatar. AvatarGroup uses the same basic prefix and adds -group; Members' Avatar prefixes are resolved separately, so the group's local prefix does not rename members. Example of a common prefix shows the group next to an independent standard avatar.

Examples

Sizes and shapes

Three named sizes, a numeric size and two shapes.

Portrait in own img

Image, icon and text

src takes precedence over icon and initials; the color is set by the style.

Indentation on each side: 4px.

Automatic text size

Change initials and gap: long line shrinks inside unchanged avatar.

Count: 5 Updates available

Avatar with counter

Number of notifications and a dot next to the avatar.

Group of avatars

Group by items; the +N button reveals the names of hidden participants.

Total limit: 3. max.count: 2.

Limit with indicator

As in the official example, the application reserves one place under +N. max.count itself counts the participants.

xs: 24 · sm: 32 · md: 40 · lg: 64 · xl: 80 · xxl: 100 px.

Adaptive size

The size is selected by the width of the viewport, and not by the width of the card. CSS defaults are used before mount.

Errors: 0.

Image error

The invalid image is replaced with initials; onError returns false to cancel fallback.

Local settings and tokens

ConfigProvider.avatar sets the styles, and theme.components.Avatar sets the group sizes and overlap.

Image errors in preview: 0.

Project participants

  • Count: 3
    Анна Новикова

    Developer. Unread: 3.

  • Дмитрий Орлов

    Designer. Unread: 0.

  • Count: 1
    Вера Смирнова

    Tester. Unread: 1.

Project participants

Saved example: avatar settings, notifications and profile in Drawer.

Participants: 5. The limit counts participants; The +N button is added separately. Zero shows everyone.

  • Anna Novikova
  • Dmitry Orlov
  • Vera Smirnova
  • Elena Sokolova
  • Igor Volkov

Team management

Saved AvatarGroup: adding, deleting, member order and limit.

API

Examples are checked against the current ant.design page and the public API of the installed package. Full definitions of Props are in @woodger/antd.

Topics of official examples
ThemeExample or limitation
BasicSizes and shapes.
TypeString src, src Snippet, icon and text.
Autoset Font SizeText adjustment and gap.
With BadgeNumber and point.
Avatar.Groupitems, limit, Popover and forms.
Include overflow in max.countApplied calculation of the +N slot, as in the wrapper of the official example.
Responsive SizeSize map by viewport.
Basic parameters of Avatar
PropertyDescriptionTypeDefault
prefixClsFull local CSS prefix for Avatar root, image, and text. The empty string and undefined inherit ConfigProvider.prefixCls; by default ant-avatar.stringConfigProvider + -avatar
srcImage or own fragment with img.string | Snippet—
altAvailable avatar name; The image inside is decorative.string—
iconIcon, including fallback after src error.Snippet—
childrenText or initials with automatic scaling.Snippet—
sizesmall, medium, large, number or map breakpoints.AvatarSizecontext / medium
shapeContainer shape.circle | squarecircle
gapMinimum text indentation on each side.number4
srcSetPicture options for screen density.string—
onErrorfalse leaves a damaged image.() => boolean | void—
nativeElementbind:nativeElement instead of React ref.HTMLSpanElement—

AvatarGroup

items - required AvatarGroupItem list; size and shape set general values ​​with priority to participant settings. max contains count, style and popover.

prefixCls specifies the local base class of the group to which it is added -group. Without it, including an empty line is valid ConfigProvider.prefixCls + -avatar. Avatar members resolve their prefixes independently; the local group prefix does not rename them.

Semantic DOM

Avatar renders span, image, icon wrapper or scalable string. Separate classNames/styles API; available class, style and ConfigProvider.avatar.

alt or aria-label names the root. Next to your full name, use aria-hiddento avoid repetitions. For an interactive avatar, use a real button or link: the handle on the span itself does not add a keyboard.

AvatarGroup - a named group with an overflow button. The button is accessible from the keyboard, Escape closes the Popover and returns focus.

Registration tokens

theme.components.Avatar controls group sizes, fonts and overlap; settings size of a specific avatar take precedence over the dimensions from the theme. General colors and fillets are inherited from ConfigProvider.

Component tokens
TokenPurpose
containerSizeRegular size.
containerSizeLGLarge size.
containerSizeSMSmall size.
textFontSizeText font.
textFontSizeLGLarge avatar text.
textFontSizeSMSmall avatar text.
iconFontSizeIcon font.
iconFontSizeLGLarge icon.
iconFontSizeSMSmall icon.
groupSpaceInterval of the list of hidden participants.
groupOverlappingOverlapping group elements.
groupBorderColorColor of the border of participants.
Common tokens of the current topic
TokenCurrent value
colorTextrgba(0,0,0,0.88)
colorTextLightSolid#fff
colorTextPlaceholderrgba(0,0,0,0.25)
borderRadius6
borderRadiusLG8
borderRadiusSM4
fontFamily-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji'
fontSize14
lineHeight1.5714285714285714
lineWidth1

FAQ

Is +N included in max.count?

No. Count limits participants, the indicator is added separately. For the total limit, reserve space in the application.

How is the Svelte API different from React?

The group is exported as AvatarGroup and receives items. Content is transmitted by snippets, CSS - by strings; ref is replaced by the binding of the native node.

What happens when there is a photo error?

For string src, icon is used, then text. Returning false from onError cancels the replacement. The custom src-snippet manages this on its own.