--- title: Avatar summary: An avatar shows a user's picture, initials or an icon in a fixed-size circle or square, with sizes, statuses and stacked lists. description: Display user avatars with images, initials, or icons. Change sizes, shapes, and colors, or group them into stacked avatar lists. related: [/ui/components/status, /ui/components/badge] source: core/scss/ui/_avatars.scss css-vars: avatar classnames: component: - class: avatar desc: Container element part: - class: avatar-brand desc: Small brand mark in the bottom corner - class: avatar-cover desc: Pulls the avatar over the element above it, with a ring - class: avatar-upload-text desc: Label inside an empty upload slot - class: avatar-list desc: Wrapper that spaces several avatars in a row style: - class: avatar-square desc: Rounded corners instead of a circle - class: avatar-rounded desc: Fully round, the default shape - class: avatar-upload desc: Dashed empty slot for a picture that is not set yet modifier: - class: avatar-list-stacked desc: Overlaps the avatars in the list color: - class: bg-{color} desc: Any base color for an avatar with initials, for example bg-azure-lt size: - class: avatar-{size} desc: From avatar-xxs to avatar-2xl; avatar-list-{size} sizes a whole list --- import Example from '@components/Example.astro' import Icon from '@ui/Icon.astro' import AvatarList from '@ui/AvatarList.astro' ## Default markup Add the `avatar` class to a `span`. Fill it with a picture as a `background-image`, or with initials as text. JL ## Avatar image Set the picture as a `background-image` on the avatar. It's cropped to the avatar's shape and size. ## Initials When there is no picture, put the initials as text inside the avatar. AB CD EF GH IJ ## Avatar icons An [icon](/ui/components/icon) inside the avatar works as a placeholder, or for an account that isn't a person, such as a system user. ## Avatar initials color Set the background with a `bg-*` class from the [color palette](/ui/base/colors). It's most useful with initials. AB CD EF GH IJ ## Avatar size Add a size class from `avatar-xxs` to `avatar-2xl`. The names follow the usual Bootstrap pattern. ## Avatar status Add a [status indicator](/ui/components/status) to show whether a user is online, or a small count such as unread messages. {' '} SA{' '} 5 ## Avatar shape An avatar is a circle by default. Add `avatar-square` to give it the same rounded corners as the rest of the interface - the usual choice when the avatar stands for a company, a project or an app rather than a person. TB AA For any other radius use the Bootstrap utilities. `rounded-0` gives sharp corners, and `rounded-3` a larger radius than `avatar-square`. ## Avatar brand Add a `avatar-brand` element inside an avatar to mark where the account comes from. It sits in the bottom corner and keeps its own background, so a brand logo stays readable over any photo. ## Avatar on a cover Add `avatar-cover` to pull an avatar halfway over the element above it and draw a ring in the card background color. Use it for a profile picture that overlaps a cover image.
Paweł Kuna
UI Designer
## Avatar upload Use the `avatar-upload` class together with `avatar` to show an empty avatar slot. It has a dashed border and no image, so users can see that the picture is still missing. On hover the border and the icon turn to the primary color. Put an icon inside to show the action. The variant is often used as a link or a button. ## Avatar upload size The upload avatar uses the same size classes as a normal avatar, from `avatar-xxs` to `avatar-2xl`. ## Avatar upload text Add a short label under the icon with the `avatar-upload-text` class. The content is stacked in a column, so use this only in the larger sizes. The text is shown in uppercase, like all avatar text. Upload Add photo ## Avatar upload in a form To pick a real file, use a `label` with the upload classes and connect it to a hidden file input. Add `cursor-pointer`, because the pointer cursor is only set for links.
Click to upload a new avatar
## Avatar list Put several avatars in an `.avatar-list` container. It keeps consistent spacing between them and wraps them when there isn't enough space. JL ## Stacked list Add `avatar-list-stacked` to overlap the avatars, which fits a long list of participants into a small space. {' '} EB {' '} +8{' '} {' '} {' '} SA {' '} {' '} {' '} ## Accessibility - An avatar with a background image has no text of its own. Show the user name next to it, or add an `aria-label` to the avatar. - Give the upload avatar a clear name. Use the `avatar-upload-text` label, an `aria-label`, or a `form-label` linked with `for`. - Use a `label` with a file input, or a `button`, when the upload avatar does something. A link with `href="#"` is only good for a static demo. - Keep the hidden file input in the markup with the `visually-hidden` class. Do not use `display: none`, because then keyboard users cannot reach it.