---
title: "Avatar"
description: "Элемент img с запасным видом; поддерживает Nuxt Image."
canonical_url: "https://b24-ui.bx-shef.by/docs/components/avatar"
---
# Avatar

> Элемент img с запасным видом; поддерживает Nuxt Image.

## Использование

<__flatten>

**Nuxt:**

Если установлен [`@nuxt/image`](https://b24-ui.bx-shef.by/raw/docs/getting-started/integrations/image.md), Avatar использует компонент `<NuxtImg>`, иначе — обычный `img`.

</__flatten>

```vue
<template>
  <B24Avatar src="/b24ui/avatar/employee.png" alt="employee" loading="lazy" />
</template>
```

> [!NOTE]
> Можно передать любое свойство HTML-элемента `<img>`: `alt`, `loading` и другие.

**Nuxt:**

> [!TIP]
> Чтобы отказаться от `@nuxt/image`, используйте пропс `as`: `:as="{ img: 'img' }"`.

### Источник изображения

Пропс `src` задаёт адрес изображения.

```vue
<template>
  <B24Avatar src="https://github.com/bitrix24.png" loading="lazy" />
</template>
```

### Размер

Пропс `size` задаёт размер Avatar.

```vue
<template>
  <B24Avatar size="2xl" src="/b24ui/avatar/assistant.png" loading="lazy" />
</template>
```

> [!NOTE]
> Атрибуты `width` и `height` элемента `<img>` выставляются автоматически по пропсу `size`.

### Иконка

Пропс `icon` показывает запасную [иконку](https://bitrix24.github.io/b24icons/icons/).

```vue
<script setup lang="ts">
import RocketIcon from '@bitrix24/b24icons-vue/main/RocketIcon'
</script>

<template>
  <B24Avatar :icon="RocketIcon" size="md" />
</template>
```

### Текст

Пропс `text` показывает запасной текст.

```vue
<template>
  <B24Avatar text="+24" size="xl" />
</template>
```

### Альтернативный текст

Если нет ни иконки, ни текста, запасным видом служат **инициалы** из пропса `alt`.

```vue
<template>
  <B24Avatar alt="Иван Петров" size="xl" />
</template>
```

> [!NOTE]
> Пропс `alt` передаётся элементу `img` как атрибут `alt`.

### Цвет

Пропс `color` меняет цвет Avatar.

```vue
<template>
  <B24Avatar color="air-boost" alt="Иван Петров" />
</template>
```

### Чип

Пропс `chip` показывает чип рядом с Avatar.

```vue
<template>
  <B24Avatar src="/b24ui/avatar/assistant.png" loading="lazy" :chip="{text:'+1',inset:true,hideZero:true}" />
</template>
```

## Примеры

### С подсказкой

Компонент [Tooltip](https://b24-ui.bx-shef.by/raw/docs/components/tooltip.md) показывает подсказку при наведении на Avatar.

```vue [AvatarTooltipExample.vue]
<template>
  <B24Tooltip text="Имя сотрудника">
    <B24Avatar
      src="/b24ui/avatar/employee.png"
      alt="Имя сотрудника"
      loading="lazy"
    />
  </B24Tooltip>
</template>
```

### С маской

CSS-маска позволяет показать Avatar не кругом, а в нестандартной форме.

```vue [AvatarMaskExample.vue]
<template>
  <B24Avatar
    class="rounded-none squircle"
    src="/b24ui/avatar/employee.png"
    alt="Имя сотрудника"
    size="3xl"
    loading="lazy"
  />
</template>

<style>
.squircle {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M8.65 20H6q-.825 0-1.412-.587T4 18v-2.65L2.075 13.4q-.275-.3-.425-.662T1.5 12t.15-.737t.425-.663L4 8.65V6q0-.825.588-1.412T6 4h2.65l1.95-1.925q.3-.275.663-.425T12 1.5t.738.15t.662.425L15.35 4H18q.825 0 1.413.588T20 6v2.65l1.925 1.95q.275.3.425.663t.15.737t-.15.738t-.425.662L20 15.35V18q0 .825-.587 1.413T18 20h-2.65l-1.95 1.925q-.3.275-.662.425T12 22.5t-.737-.15t-.663-.425z'/%3E%3C/svg%3E");
  mask-size: contain;
  mask-position: center;
  mask-repeat: no-repeat;
}
</style>
```

## API

### Пропсы

```ts
/**
 * Props for the Avatar component
 */
interface AvatarProps {
  /**
   * The element or component this component should render as.
   * @default 'span'
   */
  as?: any;
  src?: string | undefined;
  alt?: string | undefined;
  /**
   * Display an icon on the left side.
   */
  icon?: (props: HTMLAttributes & VNodeProps & {}, ctx: Omit<{ attrs: Attrs; slots: Readonly<InternalSlots>; emit: (event: string, ...args: any[]) => void; expose: <Exposed extends Record<string, any> = Record<...>>(exposed?: Exposed | undefined) => void; }, "expose">): any | undefined;
  text?: string | undefined;
  /**
   * @default 'md'
   */
  size?: "md" | "3xs" | "2xs" | "xs" | "sm" | "lg" | "xl" | "2xl" | "3xl" | undefined;
  /**
   * @default 'air-secondary-no-accent'
   */
  color?: "air-primary" | "air-primary-success" | "air-primary-alert" | "air-primary-warning" | "air-primary-copilot" | "air-secondary" | "air-secondary-alert" | "air-secondary-accent" | "air-secondary-accent-1" | "air-secondary-accent-2" | "air-secondary-no-accent" | "air-tertiary" | "air-tertiary-accent" | "air-tertiary-no-accent" | "air-selection" | "air-boost" | "air-primary-no-accent";
  chip?: boolean | ChipProps | undefined;
  b24ui?: { root?: SlotClass; image?: SlotClass; fallback?: SlotClass; icon?: SlotClass; } | undefined;
  decoding?: "async" | "auto" | "sync" | undefined;
  height?: string | number | undefined;
  loading?: "lazy" | "eager" | undefined;
  referrerpolicy?: "" | "no-referrer" | "no-referrer-when-downgrade" | "origin" | "origin-when-cross-origin" | "same-origin" | "strict-origin" | "strict-origin-when-cross-origin" | "unsafe-url" | undefined;
  sizes?: string | undefined;
  srcset?: string | undefined;
  usemap?: string | undefined;
  width?: string | number | undefined;
  crossorigin?: "anonymous" | "use-credentials" | undefined;
}
```

> [!NOTE]
> See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attributes
> Компонент поддерживает и все нативные HTML-атрибуты `<img>`.

## Тема

```ts [app.config.ts]
export default defineAppConfig({
  b24ui: {
    avatar: {
      slots: {
        root: 'air-secondary-accent inline-flex items-center justify-center shrink-0 select-none rounded-full align-middle bg-(--b24ui-background) ring ring-(--b24ui-border-color)',
        image: 'h-full w-full rounded-[inherit] object-cover',
        fallback: 'font-(--ui-font-weight-medium) text-(--b24ui-color) truncate',
        icon: 'text-(--b24ui-icon) shrink-0'
      },
      variants: {
        color: {
          'air-primary': {
            root: 'style-filled'
          },
          'air-primary-success': {
            root: 'style-filled-success'
          },
          'air-primary-alert': {
            root: 'style-filled-alert'
          },
          'air-primary-copilot': {
            root: 'style-filled-copilot'
          },
          'air-primary-warning': {
            root: 'style-filled-warning'
          },
          'air-primary-no-accent': {
            root: 'style-filled-no-accent'
          },
          'air-secondary': {
            root: 'style-tinted'
          },
          'air-secondary-alert': {
            root: 'style-tinted-alert'
          },
          'air-secondary-accent': {
            root: 'style-outline'
          },
          'air-secondary-accent-1': {
            root: 'style-outline-accent-1'
          },
          'air-secondary-accent-2': {
            root: 'style-outline-accent-2'
          },
          'air-secondary-no-accent': {
            root: 'style-outline-no-accent'
          },
          'air-tertiary': {
            root: 'style-plain'
          },
          'air-tertiary-accent': {
            root: 'style-plain-accent'
          },
          'air-tertiary-no-accent': {
            root: 'style-plain-no-accent'
          },
          'air-selection': {
            root: 'style-selection'
          },
          'air-boost': {
            root: 'style-filled-boost'
          }
        },
        size: {
          '3xs': {
            root: 'size-2.5 text-4xs font-(--ui-font-weight-regular)',
            icon: 'size-2.5'
          },
          '2xs': {
            root: 'size-5 text-(length:--ui-font-size-4xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)',
            icon: 'size-4.5'
          },
          xs: {
            root: 'size-6 text-(length:--ui-font-size-3xs)/(--ui-font-line-height-reset) font-(--ui-font-weight-regular)',
            icon: 'size-5.5'
          },
          sm: {
            root: 'size-7 text-(length:--ui-font-size-xs)/(--ui-font-line-height-reset)',
            icon: 'size-6.5'
          },
          md: {
            root: 'size-8 text-(length:--ui-font-size-sm)/(--ui-font-line-height-reset)',
            icon: 'size-7'
          },
          lg: {
            root: 'size-10.5 text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)',
            icon: 'size-9.5'
          },
          xl: {
            root: 'ring-2 size-12 text-(length:--ui-font-size-2xl)/(--ui-font-line-height-reset)',
            icon: 'size-11'
          },
          '2xl': {
            root: 'ring-2 size-15 text-(length:--ui-font-size-5xl)/(--ui-font-line-height-reset)',
            icon: 'size-14'
          },
          '3xl': {
            root: 'ring-2 size-23.5 text-6xl/(--ui-font-line-height-reset)',
            icon: 'size-22.5'
          }
        }
      },
      defaultVariants: {
        size: 'md',
        color: 'air-secondary-no-accent'
      }
    }
  }
})
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
