BetaPublic beta — Read the release notes
Documentation

Avatar

User avatar with image and fallback support.

Package
@solidiom/avatar
Version
0.0.1-next.0
Status
stable

Preview

Photo of Jane DoeJDPhoto of Alice SmithASPhoto of Bob KimBK

This preview uses documentation-only styling. Ship with one of the included recipe outputs (CSS, Tailwind, or UnoCSS) for production styles.

Avatar renders a user profile image with automatic fallback to text content (such as initials or a name) when the image fails to load. It manages image loading state internally and coordinates visibility between the image and fallback parts.

Usage

Avatar has three composable parts: Root, Image, and Fallback. Always provide both an Image and a Fallback inside Root.

import * as Avatar from "@solidiom/avatar"

;<Avatar.Root>
  <Avatar.Image src="/user-photo.jpg" alt="Photo of Jane Doe" />
  <Avatar.Fallback>JD</Avatar.Fallback>
</Avatar.Root>

Installation

Install the package with pnpm add @solidiom/avatar. The package requires compatible solid-js and @solidjs/web peer dependencies.

Parts

Root

Container that manages image loading state for its child Image and Fallback parts.

PropTypeDefaultDescription
classstringCSS class for the root element.

Image

Renders an <img> element that is hidden until the image loads successfully. Reports loading state to the Root.

PropTypeDefaultDescription
srcstringURL of the avatar image.
altstringAlternative text for the image.
classstringCSS class for the image element.

Fallback

Renders fallback content (e.g., initials, icon) when the image has not loaded or has errored. Hidden when the image is successfully loaded.

PropTypeDefaultDescription
childrenJSX.ElementContent to display when the image is not available.
classstringCSS class for the fallback element.

Styling

Avatar carries data-scope="avatar" and data-part attributes for targeting each part:

  • Root: data-scope="avatar", data-part="root" — renders as a <span>
  • Image: data-scope="avatar", data-part="image" — renders as an <img>
  • Fallback: data-scope="avatar", data-part="fallback" — renders as a <span>

Style the root as a flex container to overlay the image and fallback. Use the data-part attributes to target individual parts.

Keyboard & behavior

This primitive has no keyboard interaction. It renders static content that does not receive focus or respond to key events.

SSR and hydration

Avatar manages image loading state client-side. On the server, the Image is hidden and the Fallback is visible. After hydration, the image loads and replaces the fallback. No manual state management is required.