Skip to main content

Avatar

The Avatar component represents a user or entity with images, initials, or icons. It supports multiple sizes and includes an optional status badge indicator.

Import

// with @dhl-official/react-library:
import { DhlAvatar } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlAvatar } from "@dhl-official/ui-libraries/react-library"

Code

<DhlAvatar name="John Doe" />

Interactive Demo

Readme

Properties

PropertyAttributeDescriptionTypeDefault
altaltAn optional prop for image alt text. If not provided, falls back to the name prop.stringundefined
dataAriaLabeldata-aria-labelAn optional prop defining the text read by the screen reader to represent the component; use this if you need different text to be read from name or alt.stringundefined
dataIddata-idAn optional prop. Gives a valid HTML ID attribute value for the component.string`dhl-avatar-${getRandomString()}`
dataRoledata-roleAn optional prop defining the role attribute of the component.string"img"
dataTestiddata-testidAn optional prop. The test id attached to the component as a data-testid attribute.stringundefined
iconiconAn optional prop for custom icon source. Used when type is "icon".stringundefined
name (required)nameA REQUIRED prop for the user's name. Used to generate initials and as fallback alt text.stringundefined
showBadgeshow-badgeAn optional boolean prop to show or hide the badge indicator.booleanfalse
sizesizeAn optional size prop for the component."lg" | "md" | "sm" | "xl"DHL_AVATAR.SIZE.MD
srcsrcAn optional prop for the image source URL. When provided and valid, displays an image avatar.stringundefined
statusstatusAn optional prop for badge status.Variants.error | Variants.info | Variants.neutral | Variants.success | Variants.warningDHL_AVATAR.STATUS.SUCCESS
typetypeAn optional type prop to specify the avatar type (image, initials, or icon)."icon" | "image" | "initials"DHL_AVATAR.TYPE.IMAGE

Slots

SlotDescription
"unnamed"Content to display in the avatar (for custom content)

Dependencies

Depends on

Graph


Built by DHL User Interface Library Team!