Round profile photo in three sizes, with name initials as a fallback when the image is empty or fails to load.
<x-markas.avatar name="Rani Wulandari" size="sm" /><x-markas.avatar name="Rani Wulandari" size="sm" src="/demo/avatar.svg" /><x-markas.avatar name="Rani Wulandari" size="md" /><x-markas.avatar name="Rani Wulandari" size="md" src="/demo/avatar.svg" /><x-markas.avatar name="Rani Wulandari" size="lg" /><x-markas.avatar name="Rani Wulandari" size="lg" src="/demo/avatar.svg" />import { Avatar } from "@/components/markas/Avatar";
<Avatar name="Rani Wulandari" size="sm" />import { Avatar } from "@/components/markas/Avatar";
<Avatar name="Rani Wulandari" size="sm" src="/demo/avatar.svg" />import { Avatar } from "@/components/markas/Avatar";
<Avatar name="Rani Wulandari" size="md" />import { Avatar } from "@/components/markas/Avatar";
<Avatar name="Rani Wulandari" size="md" src="/demo/avatar.svg" />import { Avatar } from "@/components/markas/Avatar";
<Avatar name="Rani Wulandari" size="lg" />import { Avatar } from "@/components/markas/Avatar";
<Avatar name="Rani Wulandari" size="lg" src="/demo/avatar.svg" />import Avatar from "@/components/markas/Avatar.vue";
<Avatar name="Rani Wulandari" size="sm" />import Avatar from "@/components/markas/Avatar.vue";
<Avatar name="Rani Wulandari" size="sm" src="/demo/avatar.svg" />import Avatar from "@/components/markas/Avatar.vue";
<Avatar name="Rani Wulandari" size="md" />import Avatar from "@/components/markas/Avatar.vue";
<Avatar name="Rani Wulandari" size="md" src="/demo/avatar.svg" />import Avatar from "@/components/markas/Avatar.vue";
<Avatar name="Rani Wulandari" size="lg" />import Avatar from "@/components/markas/Avatar.vue";
<Avatar name="Rani Wulandari" size="lg" src="/demo/avatar.svg" />Examples
Sizes
<div class="flex items-center gap-4">
<x-markas.avatar name="Budi Santoso" size="sm" />
<x-markas.avatar name="Budi Santoso" />
<x-markas.avatar name="Budi Santoso" size="lg" />
<x-markas.avatar name="Dewi Lestari" size="sm" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Crect width='48' height='48' fill='rgb(46 107 58)'/%3E%3Ccircle cx='24' cy='19' r='8' fill='rgb(231 239 229)'/%3E%3Cpath d='M8 46c1-9 8-15 16-15s15 6 16 15z' fill='rgb(231 239 229)'/%3E%3C/svg%3E" />
<x-markas.avatar name="Dewi Lestari" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Crect width='48' height='48' fill='rgb(46 107 58)'/%3E%3Ccircle cx='24' cy='19' r='8' fill='rgb(231 239 229)'/%3E%3Cpath d='M8 46c1-9 8-15 16-15s15 6 16 15z' fill='rgb(231 239 229)'/%3E%3C/svg%3E" />
<x-markas.avatar name="Dewi Lestari" size="lg" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Crect width='48' height='48' fill='rgb(46 107 58)'/%3E%3Ccircle cx='24' cy='19' r='8' fill='rgb(231 239 229)'/%3E%3Cpath d='M8 46c1-9 8-15 16-15s15 6 16 15z' fill='rgb(231 239 229)'/%3E%3C/svg%3E" />
</div>Initials
- Budi Santoso
- Ahmad Rian Putra
- rina
- Maria José García
- Budi Santoso
- Ahmad Rian Putra
- rina
- Maria José García
- Budi Santoso
- Ahmad Rian Putra
- rina
- Maria José García
- Budi Santoso
- Ahmad Rian Putra
- rina
- Maria José García
- Budi Santoso
- Ahmad Rian Putra
- rina
- Maria José García
Stacked group
<div class="flex items-center gap-3">
<div role="group" aria-label="Project members" class="flex">
<x-markas.avatar name="Dewi Lestari" src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='48' height='48' viewBox='0 0 48 48'%3E%3Crect width='48' height='48' fill='rgb(46 107 58)'/%3E%3Ccircle cx='24' cy='19' r='8' fill='rgb(231 239 229)'/%3E%3Cpath d='M8 46c1-9 8-15 16-15s15 6 16 15z' fill='rgb(231 239 229)'/%3E%3C/svg%3E" class="ring-2 ring-canvas" />
<x-markas.avatar name="Budi Santoso" class="-ml-2 ring-2 ring-canvas" />
<x-markas.avatar name="Siti Aminah" class="-ml-2 ring-2 ring-canvas" />
<x-markas.avatar name="John Carter" class="-ml-2 ring-2 ring-canvas" />
<span class="-ml-2 inline-flex size-10 items-center justify-center rounded-full bg-subtle text-sm font-medium text-ink ring-2 ring-canvas">+5<span class="sr-only"> more members</span></span>
</div>
<span class="text-sm text-muted">9 people on this project</span>
</div>With status
In a list
-
Owner
Sarah Miller
sarah@markasui.com
-
Editor
Budi Santoso
budi@markasui.com
-
Viewer
Siti Aminah
siti@markasui.com
- Owner
Sarah Miller
sarah@markasui.com
- Editor
Budi Santoso
budi@markasui.com
- Viewer
Siti Aminah
siti@markasui.com
- Owner
Sarah Miller
sarah@markasui.com
- Editor
Budi Santoso
budi@markasui.com
- Viewer
Siti Aminah
siti@markasui.com
- Owner
Sarah Miller
sarah@markasui.com
- Editor
Budi Santoso
budi@markasui.com
- Viewer
Siti Aminah
siti@markasui.com
- Owner
Sarah Miller
sarah@markasui.com
- Editor
Budi Santoso
budi@markasui.com
- Viewer
Siti Aminah
siti@markasui.com
Installation
npx markasui@latest add avatarpnpm dlx markasui@latest add avataryarn dlx markasui@latest add avatarbunx --bun markasui@latest add avatar- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Install the dependency:
npm install alpinejs - Copy the component source below to
resources/views/components/markas/avatar.blade.php.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Avatar.tsx.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Avatar.vue.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/Avatar.svelte.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/Avatar.astro.
- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/avatar.component.ts.
Usage
<x-markas.avatar name="John Carter" size="sm" />
<x-markas.avatar name="Sarah Miller" :src="$user->photo_url" />
<x-markas.avatar name="Emma Wilson" src="/img/emma.jpg" size="lg" alt="" />The fallback for an image that fails to load needs Alpine.js. Livewire 3 and 4 already ship it. Without src, the initials render with no JavaScript.
import { Avatar } from "@/components/markas/Avatar";
<Avatar name="John Carter" size="sm" />
<Avatar name="Sarah Miller" src={user.photoUrl} />
<Avatar name="Emma Wilson" src="/img/emma.jpg" size="lg" alt="" /><script setup lang="ts">
import Avatar from "@/components/markas/Avatar.vue";
</script>
<template>
<Avatar name="John Carter" size="sm" />
<Avatar name="Sarah Miller" :src="user.photoUrl" />
<Avatar name="Emma Wilson" src="/img/emma.jpg" size="lg" alt="" />
</template><script lang="ts">
import Avatar from "$lib/components/markas/Avatar.svelte";
</script>
<Avatar name="Dewi Lestari" src="/avatars/dewi.jpg" size="lg" />
<Avatar name="Budi Santoso" />---
import Avatar from "@/components/markas/Avatar.astro";
---
<Avatar name="Dewi Lestari" src="/avatars/dewi.jpg" size="lg" />
<Avatar name="Budi Santoso" />A small bundled script swaps a broken image for the initials.
import { Component } from "@angular/core";
import { Avatar } from "./markas/avatar.component";
@Component({
selector: "app-example",
imports: [Avatar],
template: `
<markas-avatar name="Dewi Lestari" src="/avatars/dewi.jpg" size="lg" />
<markas-avatar name="Budi Santoso" />
`,
})
export class Example {}- Initials come from the first letter of the first and last word:
John CarterbecomesJC,annbecomesA. ThegetInitialsfunction is exported from the React and Vue versions. - Extra attributes (
loading,width,data-*) land on the<img>. The fallback element only receivesclass. - In Blade, an image that already failed before Alpine starts is still detected through
x-init(it checkscompleteandnaturalWidth). - Avatar has no built-in text. The accessible name comes from
nameoralt, so pass them in your site’s language.
Props
| Name | Type | Default | Description |
|---|---|---|---|
name | string | - | Person's name. Used for the initials and as the default alt. |
src | string | - | Image URL. When empty or when it fails to load, the initials are shown. |
alt | string | name | Alternative text. Pass an empty string when the avatar is decorative next to a name that is already written. |
size | 'sm' | 'md' | 'lg' | md | Size of 32, 40, or 48 pixels. |
Accessibility
- The image always has an alt, which defaults to name.
- The initials fallback uses role img and the same aria-label as alt, so screen readers announce the name, not the letters.
- With an empty alt, the avatar is hidden from screen readers (aria-hidden).
Related components
More data components with the same classes in every framework.
- CardCard that groups content with an optional title, description, body, and footer.
- CarouselRow of slides built on CSS scroll snap, with previous and next buttons, optional dots, and arrow key navigation. No autoplay.
- Code BlockMonospace code block with an optional file name, line numbers, and a copy button. Plain text, no syntax highlighting.
- KbdKeycap for keyboard shortcuts using the native kbd element, in two sizes, with key combinations rendered as separate keys.
- Scroll AreaScrollable container with a thin token-styled scrollbar that keyboard users can focus and scroll. No JavaScript.
- SeparatorHorizontal or vertical dividing line, decorative by default, with an optional label in the middle such as "or".