The avatar component can be used as a visual identifier for a user profile on your website. Adjust styles and sizes with Tailwind utility classes and the component props below.
Setup
Import Avatar. If you are using the user dropdown, import Dropdown, DropdownHeader, DropdownItem. If you are using tooltip for avatar import Tooltip.
<script>
import { Avatar, Dropdown, DropdownHeader, DropdownItem, Tooltip } from '.';
</script> Default avatar
Use this example to create a circle and rounded avatar on an image element.
<script>
import { Avatar } from '.';
</script>
<div class="flex space-x-4 rtl:space-x-reverse">
<Avatar src="/images/profile-picture-2.webp" />
<Avatar src="/images/profile-picture-2.webp" cornerStyle="rounded" />
</div> Icon avatar
<script>
import { Avatar } from '.';
</script>
<Avatar>
<iconify-icon icon="ph:seal-check-fill"></iconify-icon>
</Avatar> Custom dot
<script>
import { Avatar, Indicator } from '.';
</script>
<Avatar src="/images/profile-picture-3.webp">
{#snippet indicator()}
<Indicator color="gray" border size="xl" placement="top-right">
<iconify-icon icon="ph:seal-check-fill"></iconify-icon>
</Indicator>
{/snippet}
</Avatar> Bordered
You can apply a border around the avatar component.
You can use the ring-{color} class from Tailwind CSS to modify ring color.
<script>
import { Avatar } from '.';
</script>
<Avatar src="/images/profile-picture-2.webp" border />
<Avatar src="/images/profile-picture-2.webp" border class="ring-red-400 dark:ring-red-300" /> Placeholder
When there is no custom image available a placeholder is displayed.
<script>
import { Avatar } from '.';
</script>
<Avatar />
<Avatar cornerStyle="rounded" />
<Avatar border />
<Avatar cornerStyle="rounded" border /> Placeholder initials
This example can be used to show the initials of the user’s first and last name as a placeholder when no profile picture is available.
<script>
import { Avatar } from '.';
</script>
<Avatar>JL</Avatar> Dot indicator
Use a dot element relative to the avatar component as an indicator for the user (eg. online or offline status).
<script>
import { Avatar } from '.';
</script>
<Avatar src="/images/profile-picture-3.webp" dot={{ color: 'red' }} />
<Avatar
src="/images/profile-picture-3.webp"
dot={{ placement: 'top-right', color: 'red' }}
cornerStyle="rounded"
/>
<Avatar src="/images/profile-picture-5.webp" dot={{ placement: 'bottom-right', color: 'green' }} />
<Avatar
src="/images/profile-picture-5.webp"
dot={{ placement: 'bottom-right' }}
cornerStyle="rounded"
/>
<Avatar dot={{}} /> Stacked
Use this example if you want to stack a group of users by overlapping the avatar components.
<script>
import { Avatar } from '.';
</script>
<div class="mb-5 flex">
<Avatar src="/images/profile-picture-1.webp" stacked />
<Avatar src="/images/profile-picture-2.webp" stacked />
<Avatar src="/images/profile-picture-3.webp" stacked />
<Avatar stacked />
</div>
<div class="flex">
<Avatar src="/images/profile-picture-1.webp" stacked />
<Avatar src="/images/profile-picture-2.webp" stacked />
<Avatar src="/images/profile-picture-3.webp" stacked />
<Avatar stacked href="/" class="bg-gray-700 text-sm text-white hover:bg-gray-600">+99</Avatar>
</div> User dropdown
Use this example if you want to show a dropdown menu when clicking on the avatar component.
<script>
import { Avatar, Dropdown, DropdownHeader, DropdownItem, DropdownGroup } from '.';
</script>
<Avatar
id="user-drop"
src="/images/profile-picture-3.webp"
class="cursor-pointer"
dot={{ color: 'green' }}
/>
<Dropdown triggeredBy="#user-drop">
<DropdownHeader>
<span class="block text-sm">Bonnie Green</span>
<span class="block truncate text-sm font-medium">name@flowbite.com</span>
</DropdownHeader>
<DropdownGroup>
<DropdownItem>Dashboard</DropdownItem>
<DropdownItem>Settings</DropdownItem>
<DropdownItem>Earnings</DropdownItem>
</DropdownGroup>
<DropdownGroup>
<DropdownItem>Sign out</DropdownItem>
</DropdownGroup>
</Dropdown> Sizes
You can set size property to preset values of xs | sm | md | lg | xl. Custom size can be achieved by adding any of the Tailwind Css size classes like w-[x] h-[x].
Preset values are equivalents of:
| Size | Classes | |
|---|---|---|
| xs | w-6 h-6 | |
| sm | w-8 h-8 | |
| md | w-10 h-10 | |
| lg | w-20 h-20 | |
| xl | w-36 h-36 |
<script>
import { Avatar } from '.';
</script>
<div class=" flex flex-wrap justify-center space-x-4 rtl:space-x-reverse">
<Avatar src="/images/profile-picture-3.webp" size="xs" />
<Avatar src="/images/profile-picture-3.webp" size="sm" />
<Avatar src="/images/profile-picture-3.webp" size="md" />
<Avatar src="/images/profile-picture-3.webp" size="lg" />
<Avatar src="/images/profile-picture-3.webp" size="xl" />
<Avatar src="/images/profile-picture-3.webp" class="h-28 w-28" />
</div> Composition notes
- Pass
srcfor an image; omit it to show the default user SVG or customchildren(initials, icons). dotaccepts Indicator props (placement, color, size) for online-status dots; useindicatorfor fully custom overlays.- With
href, the root renders as an anchor; otherwise a focusabledivwhen clickable.
Props
AvatarProps
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | — | Image URL |
alt | string | — | Image alt text |
size | xs | sm | md | lg | xl | md | Preset dimensions |
cornerStyle | circular | rounded | circular | Shape |
border | boolean | false | Ring border |
stacked | boolean | false | Overlap for avatar stacks |
href | string | — | Render as link |
target | string | — | Link target |
dot | object (Indicator props) | — | Status dot; merges defaults placement: 'top-right', color: 'gray', size: 'lg' |
indicator | Snippet | — | Custom overlay indicator |
children | Snippet | — | Fallback content (no src) |
onclick | () => void | — | Click handler |
class | ClassValue | — | Extra classes |
…rest | div attrs | — | Forwarded to the root |
Snippets
| Snippet | Description |
|---|---|
children | Initials / custom fallback |
indicator | Custom status overlay |