Blazor Avatar
The Blazor Bootstrap Avatar component shows a person or entity as an image, initials, or an icon, with an optional status, and AvatarGroup stacks avatars with a "+N" overflow. The examples below cover image, initials and icon avatars, a broken-image fallback, sizes, shapes and colors.
INFO
Icon avatars use Bootstrap Icons, so reference the Bootstrap Icons stylesheet in your app. The broken-image fallback runs once the page is interactive; on a static server-rendered page a broken image stays as rendered.
Image, initials, and icon #
Avatar shows the image from
How to use:
Initials use the first letter of the first and last words, so María José García would show MG; this example overrides it with MJ.
ImageUrl. Without an image it shows initials from Name, then the icon from IconName, then a person icon.
How to use:
- Add
Avatarand setName. It gives the initials and the name screen readers announce. - Set
ImageUrlto show a photo. - Set
Initialswhen the computed ones are wrong, orIconName(orCustomIconName) for an icon. - Leave
Nameempty for a decorative avatar, or name it witharia-label.
Broken image fallback #
When the image fails to load, the avatar falls back to the next source: initials, the icon, then the person icon.
How to use:
Use the button to switch between a missing and a working image.
How to use:
- Set
ImageUrltogether withNameorIconNameso there is something to fall back to. - Change
ImageUrlat any time. The avatar tries the new image again, even after a failure.
Sizes #
Avatars come in four sizes, and the
How to use:
--bb-avatar-size CSS custom property sets any other size.
How to use:
- Set
SizetoAvatarSize.Small,Medium(default),Large, orExtraLarge. - For a custom size, add
Style="--bb-avatar-size: 6rem;". Initials and icons scale with it.
Shapes #
Avatars are circles by default and can also be rounded squares or squares.
How to use:
How to use:
- Set
ShapetoAvatarShape.Circle,Rounded, orSquare.
Colors #
Color sets the background of initials and icon avatars, with a readable text color in light and dark themes. It has no effect while an image is shown.
How to use:
- Set
Colorto anAvatarColorvalue. The default isSecondary;Noneremoves the background.
Status #
A status dot at the bottom-end corner shows presence. The status is also part of the name screen readers announce, so it never relies on color alone.
How to use:
How to use:
- Set
StatustoAvatarStatus.Online,Away,Busy, orOffline. - Translate the announced text with
OnlineText,AwayText,BusyText, andOfflineText.
Group with overflow #
AvatarGroup overlaps its avatars, shows at most
How to use:
The group follows avatars as they are added and removed. Hidden avatars without a name are counted but not listed.
Max of them, and adds a "+N" button for the rest. Hover the button to see the hidden names, or select it to open a list of them.
How to use:
- Wrap
Avatarcomponents inAvatarGroup. - Set
Maxto the number of avatars to show. Leave it unset to show them all. - Name the group for screen readers with
aria-labeloraria-labelledby. - Translate the button's announced text with
OverflowTextFormat, for example"{0} more".
Group size, shape, and overlap #
A group gives every avatar and the "+N" button the same size and shape. The overlap follows the size and mirrors in right-to-left layouts.
How to use:
How to use:
- Set
SizeandShapeonAvatarGroup; they replace the values on each avatar. - Change the overlap with
Style="--bb-avatar-group-overlap: .25rem;".
Inside a grid #
Avatars and groups fit in Grid cells next to text.
How to use:
How to use:
- Place an
Avatarin aGridColumntemplate. - Use
AvatarSize.Smallto keep rows compact.
Inside a dropdown and tooltip #
Avatars work in a Dropdown toggle and its items, and inside a Tooltip.
How to use:
How to use:
- Put an
AvatarinDropdownToggleButtonorDropdownItemcontent, with a margin class such asme-2. - Wrap an
Avatarin aTooltipto show more details on hover.