PPolaris ComponentsConnect an agent

Avatar

Shows a visual identifier for a person or business, falling back from an image to initials to a customer placeholder, in five sizes.

Preview

Code

Example.jsx
import { Card, BlockStack, InlineStack, Text, Avatar, Divider } from '@shopify/polaris';

const PHOTO_URL = 'https://burst.shopifycdn.com/photos/freelance-designer-working-on-laptop.jpg?width=746';

const SIZES = ['xs', 'sm', 'md', 'lg', 'xl'];

const STAFF = [
  { id: 'mae', name: 'Mae Jemison', initials: 'MJ', role: 'Store owner' },
  { id: 'tomas', name: 'Tomas Ruiz', initials: 'TR', role: 'Fulfillment' },
  { id: 'chelsea', name: 'Chelsea Okafor', initials: 'CO', role: 'Support' },
];

const CUSTOMERS = [
  { id: 'russell', name: 'Russell Winfield', email: 'russell@example.com' },
  { id: 'ellen', name: 'Ellen Ochoa', email: 'ellen@example.com' },
];

const Section = ({ title, children }) => (
  <BlockStack gap="300">
    <Text as="h2" variant="headingSm" tone="subdued">
      {title}
    </Text>
    {children}
  </BlockStack>
);

export const Example = () => (
  <BlockStack gap="400">
    <Card>
      <Section title="Sizes">
        <InlineStack gap="400" blockAlign="center" wrap>
          {SIZES.map((size) => (
            <BlockStack key={size} gap="150" inlineAlign="center">
              <Avatar size={size} name="Mae Jemison" initials="MJ" />
              <Text as="span" variant="bodyXs" tone="subdued">
                {size}
              </Text>
            </BlockStack>
          ))}
        </InlineStack>
      </Section>
    </Card>

    <Card>
      <BlockStack gap="500">
        <Section title="With an image source">
          <InlineStack gap="300" blockAlign="center">
            <Avatar
              size="lg"
              name="Dominic Vega"
              initials="DV"
              source={PHOTO_URL}
              accessibilityLabel="Dominic Vega"
            />
            <BlockStack gap="050">
              <Text as="p" fontWeight="semibold">
                Dominic Vega
              </Text>
              <Text as="p" variant="bodySm" tone="subdued">
                Falls back to the initials if the image fails to load
              </Text>
            </BlockStack>
          </InlineStack>
        </Section>

        <Divider />

        <Section title="Initials">
          <BlockStack gap="300">
            {STAFF.map((person) => (
              <InlineStack key={person.id} gap="300" blockAlign="center">
                <Avatar name={person.name} initials={person.initials} />
                <BlockStack gap="050">
                  <Text as="p" fontWeight="medium">
                    {person.name}
                  </Text>
                  <Text as="p" variant="bodySm" tone="subdued">
                    {person.role}
                  </Text>
                </BlockStack>
              </InlineStack>
            ))}
          </BlockStack>
        </Section>

        <Divider />

        <Section title="Name only">
          <InlineStack gap="300" blockAlign="center">
            <Avatar name="Silver Quill Supply" />
            <Text as="p">Derives the initial from the name when none is given</Text>
          </InlineStack>
        </Section>

        <Divider />

        <Section title="Customer">
          <BlockStack gap="300">
            {CUSTOMERS.map((customer) => (
              <InlineStack key={customer.id} gap="300" blockAlign="center">
                <Avatar customer name={customer.name} />
                <BlockStack gap="050">
                  <Text as="p" fontWeight="medium">
                    {customer.name}
                  </Text>
                  <Text as="p" variant="bodySm" tone="subdued">
                    {customer.email}
                  </Text>
                </BlockStack>
              </InlineStack>
            ))}
          </BlockStack>
        </Section>
      </BlockStack>
    </Card>
  </BlockStack>
);