Avatar â Svelte
Avatar component â Svelte.
Avatar component
Accessible avatar: profile image when provided, or initials from name / initials. Sizes (sm, md, lg) and shape (circle, square). BEM: avatar, avatar--sm/md/lg, avatar--circle/square.
Props
src(string, optional) â Image URLalt(string, optional) â Alt text for the imagename(string, optional) â Full name for initials (e.g. "Jane Doe" â "JD")initials(string, optional) â Override initials; ignored ifnameis setsize(string, optional) âsm,md,lg(default: md)shape(string, optional) âcircle,square(default: circle)class(string, optional) â Additional CSS classes
Initials (basic)
Live examples
Sizes
Live examples
Shape
Use shape="square" for a rounded square; default is circle.
Live examples
With image
Pass src and alt for a profile image (lazy-loaded, object-fit: cover).
Live example (placeholder)
Usage
svelte svelte
<script>
import Avatar from './components/svelte/Avatar.svelte';
</script>
<Avatar name="Jane Doe" />
<Avatar name="Alice" />
<Avatar initials="AB" />
<Avatar name="Jane Doe" size="sm" />
<Avatar name="Jane Doe" shape="square" />
<Avatar src="/photo.jpg" alt="Jane Doe" size="md" />