Alert Avatar AvatarGroup Button ButtonGroup Checkbox CheckboxGroup FilePicker Form FormRow Hamburger Input Modal Option Radio RadioGroup Rating Select Spinner Textarea Toast Tooltip Toggle

Avatar

Avatars are used to display a user’s profile image or initials. If an initials property is passed, it will be used as the value of the image element’s alt attribute and as the backup display in case no image src is passed. Alternatively, a name attribute can be passed from which initials will be derived automatically.

Example

A basic avatar with an image source. The provided image does not need to be a circle, the avatar will be clipped to a circle automatically.

<script>
  import { Avatar } from '$lib/ui';
</script>

<Avatar src="./dave.jpg" />
Avatar

Sizes

The default size is md (medium) as shown above. The size property can be used to set the size as defined in style.css. Note that the size of the avatar can also be set using the --ui-avatar-size CSS Style Prop.

<Avatar src="./bob.jpg" size="xs" />
<Avatar src="./jane.jpg" size="sm" />
<Avatar src="./dave.jpg" size="md" />
<Avatar src="./susan.jpg" size="lg" />
<Avatar src="./lynn.jpg" size="xl" />
Avatar Avatar Avatar Avatar Avatar

Initials

Supplied initials will be used as the value of the image element’s alt attribute and as the backup display in case no src image is passed. Initials are automatically uppercased and only the first two letters are used.

<Avatar initials="ck" />
CK

Name

Instead of passing initials, a name property can be passed from which initials can be derived for backup display. If present, the name property is also used as the value of the image element’s alt attribute.

<Avatar name="Michael Jackson" />
MJ

Avatar Component Props

Name Type Default Description
srcString URL (either relative or full URL) to the image file to use in avatar. Preferably 1:1 aspect ratio. Does not need to be cropped to a circle
sizeString: 'xs', 'sm', 'md', 'lg', or 'xl''md'Sets the the size of the avatar
initialsString Initials to display if src is falsey. Also used as value of alt attribute
nameString Initials automatically derived from name to display if src is falsey. Also used as value of alt attribute
altString Value of alt attribute in avatar image element (defaults to value of name or initials)
classString CSS classes declared in global scope can be applied to the outermost element
...  Additional props will be passed through to the HTML element enabling support for things like on:click, etc

Avatar CSS Custom Properties

Name Type Default Description
--ui-avatar-sizeNumeric84pxArbitrary size of Avatar (overrides size prop)
--ui-avatar-font-sizeNumericcalc(--ui-avatar-size/2.2)Size used for initials
--ui-avatar-colorColor--ui-dark or #1e293bColor used for initials
--ui-avatar-backgroundColor--ui-light or #e2e8f0Color used for initials background
--ui-avatar-border-widthNumeric0Avatar border width
--ui-avatar-border-colorColornoneAvatar border color