Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Avatar

    Round profile photo in three sizes, with name initials as a fallback when the image is empty or fails to load.

    Rani Wulandari
    Rani Wulandari
    Rani Wulandari
    BS SA R Dewi Lestari
    BSSARDewi Lestari

    Avatar

    <x-markas.avatar name="Rani Wulandari" size="md" src="/demo/avatar.svg" />
    import { Avatar } from "@/components/markas/Avatar";
    
    <Avatar name="Rani Wulandari" size="md" src="/demo/avatar.svg" />
    import Avatar from "@/components/markas/Avatar.vue";
    
    <Avatar name="Rani Wulandari" size="md" src="/demo/avatar.svg" />
    <script lang="ts">
      import Avatar from "$lib/components/markas/Avatar.svelte";
    
      const photo =
        "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";
    </script>
    
    <div class="flex items-center gap-4">
      <Avatar name="Budi Santoso" size="sm" />
      <Avatar name="Siti Aminah" />
      <Avatar name="rina" size="lg" />
      <Avatar name="Dewi Lestari" size="lg" src={photo} />
    </div>
    ---
    import Avatar from "@/components/markas/Avatar.astro";
    
    const photo =
      "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 class="flex items-center gap-4">
      <Avatar name="Budi Santoso" size="sm" />
      <Avatar name="Siti Aminah" />
      <Avatar name="rina" size="lg" />
      <Avatar name="Dewi Lestari" size="lg" src={photo} />
    </div>
    import { Component } from "@angular/core";
    import { Avatar } from "./markas/avatar.component";
    
    @Component({
      selector: "markas-example",
      imports: [Avatar],
      template: `
        <div class="flex items-center gap-4">
          <markas-avatar name="Budi Santoso" size="sm" />
          <markas-avatar name="Siti Aminah" />
          <markas-avatar name="rina" size="lg" />
          <markas-avatar name="Dewi Lestari" size="lg" [src]="photo" />
        </div>
      `,
    })
    export default class AvatarExample {
      protected readonly photo =
        "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";
    }

    Examples

    Sizes

    BS BS BS Dewi Lestari Dewi Lestari Dewi Lestari
    BSBSBSDewi LestariDewi LestariDewi Lestari
    BSBSBSDewi LestariDewi LestariDewi Lestari
    BS BS BS Dewi Lestari Dewi Lestari Dewi Lestari
    BSBSBSDewi LestariDewi LestariDewi Lestari

    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

    Dewi Lestari BS SA JC +5 more members
    9 people on this project
    Dewi LestariBSSAJC+5 more members
    9 people on this project
    Dewi LestariBSSAJC+5 more members
    9 people on this project
    Dewi Lestari BS SA JC +5more members
    9 people on this project
    Dewi LestariBSSAJC+5 more members
    9 people on this project

    With status

    BS Online SA Away JC Offline
    BSOnlineSAAwayJCOffline
    BSOnlineSAAwayJCOffline
    BS Online SA Away JC Offline
    BSOnlineSAAwayJCOffline

    In a list

    • Sarah Miller

      sarah@markasui.com

      Owner
    • Budi Santoso

      budi@markasui.com

      Editor
    • Siti Aminah

      siti@markasui.com

      Viewer
    • Sarah Miller

      sarah@markasui.com

      Owner
    • Budi Santoso

      budi@markasui.com

      Editor
    • Siti Aminah

      siti@markasui.com

      Viewer
    • Sarah Miller

      sarah@markasui.com

      Owner
    • Budi Santoso

      budi@markasui.com

      Editor
    • Siti Aminah

      siti@markasui.com

      Viewer
    • Sarah Miller

      sarah@markasui.com

      Owner
    • Budi Santoso

      budi@markasui.com

      Editor
    • Siti Aminah

      siti@markasui.com

      Viewer
    • Sarah Miller

      sarah@markasui.com

      Owner
    • Budi Santoso

      budi@markasui.com

      Editor
    • Siti Aminah

      siti@markasui.com

      Viewer

    Installation

    npx markasui@latest add avatar

    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 Carter becomes JC, ann becomes A. The getInitials function is exported from the React and Vue versions.
    • Extra attributes (loading, width, data-*) land on the <img>. The fallback element only receives class.
    • In Blade, an image that already failed before Alpine starts is still detected through x-init (it checks complete and naturalWidth).
    • Avatar has no built-in text. The accessible name comes from name or alt, so pass them in your site’s language.

    Props

    NameTypeDefaultDescription
    namestring-Person's name. Used for the initials and as the default alt.
    srcstring-Image URL. When empty or when it fails to load, the initials are shown.
    altstringnameAlternative text. Pass an empty string when the avatar is decorative next to a name that is already written.
    size'sm' | 'md' | 'lg'mdSize 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.