Display

Avatar

A person's picture, or their initials when there is none.

Installation

npx sinaui add avatar

Examples

Initials

Initials come from the first and last words of the name.

<script lang="ts">
	import Avatar from '#lib/ui/Avatar.svelte';
</script>

<Avatar name="Maryam al-Ijliya" />

Small

For lists and dense rows.

<script lang="ts">
	import Avatar from '#lib/ui/Avatar.svelte';
</script>

<Avatar name="Ibn Sīnā" size="sm" />

Large

For profiles and headers.

<script lang="ts">
	import Avatar from '#lib/ui/Avatar.svelte';
</script>

<Avatar name="Al-Khwārizmī" size="lg" />

With a picture

The picture fades in over the initials once it has loaded, so nothing pops in.

<script lang="ts">
	import Avatar from '#lib/ui/Avatar.svelte';
</script>

<Avatar
	name="Ebn Sina"
	src="https://avatars.githubusercontent.com/u/26293733?v=4&size=64"
	size="lg"
/>

When the picture fails

A picture that can't load leaves the initials in place.

<script lang="ts">
	import Avatar from '#lib/ui/Avatar.svelte';
</script>

<!-- The image fails to load, so the initials stay. -->
<Avatar name="Fāṭima al-Fihrī" src="https://example.invalid/fatima.png" size="lg" />

Next to a name

When the name is already written beside it, mark the avatar decorative so screen readers don't read the name twice.

Thābit ibn Qurra Translator, Baghdad
<script lang="ts">
	import Avatar from '#lib/ui/Avatar.svelte';
</script>

<div class="person">
	<Avatar name="Thābit ibn Qurra" decorative />
	<div>
		<strong>Thābit ibn Qurra</strong>
		<span>Translator, Baghdad</span>
	</div>
</div>

<style>
	.person {
		display: flex;
		align-items: center;
		gap: 0.75rem;
	}
	.person div {
		display: grid;
	}
	.person span {
		color: var(--ui-muted);
		font-size: 0.875rem;
	}
</style>

Props

PropTypeDefault
namestring (required)
srcstring
size'sm' | 'md' | 'lg''md'
decorativebooleanfalse

Accessibility

  • Read as an image named after the person, whether it shows a picture or initials.
  • Initials are muted text on a tint, at 4.5:1 contrast or more in both themes.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme