user-persona

Displays user personas in an Agile-friendly visual format with avatar, quote, goals, frustrations, and behaviors.

Overview

A web component for displaying user personas in a structured, visual card format. Includes an auto-generated avatar with initials and a deterministic color derived from the name hash, a quote block, and slotted sections for biography, goals, frustrations, and behaviors. Ideal for design documentation, sprint planning boards, and stakeholder presentations.

Attributes

Attribute Type Default Description
name string "Unnamed Persona" Full name of the persona
role string Job title or role description
age string Age displayed as "[value] years old"
location string Geographic location shown with a pin icon
avatar string (URL) Custom avatar image URL. When omitted, initials are generated from the name.
quote string Representative quote displayed in an italic block with a decorative quotation mark
compact boolean Reduces padding, font sizes, and avatar size for denser layouts
src string (URL) URL to JSON file containing persona data. Loads and populates all fields.

Slots

Slot Expected Content Description
bio <p> or text Background information about the persona
goals <ul> or <ol> What the persona wants to achieve. Displayed with a green accent icon.
frustrations <ul> or <ol> Pain points and frustrations. Displayed with a red accent icon.
behaviors <ul> or <ol> Behavioral patterns and habits. Displayed with a purple accent icon.

Scalar attributes (name, role, age, location, quote) can also be provided as named slots for SSR-friendly authoring. Attributes take priority when both are present.

Avatar Behavior

When no avatar URL is provided, the component generates an avatar automatically:

  1. Initials — extracted from the first letter of each word in the name, capped at two characters (e.g., "Sarah Chen" becomes "SC")
  2. Background color — a deterministic HSL hue is computed from a hash of the name string, ensuring the same name always produces the same color

To use a custom image instead, set the avatar attribute to any image URL. The image renders as a circular background-image with center/cover sizing.

Compact Variant

Add the compact attribute for a denser layout with smaller padding, reduced font sizes, and a 56px avatar (down from 80px). Useful when displaying multiple personas side by side or in a dashboard grid.

JSON Loading

Load persona data from a JSON file using the src attribute. All fields are mapped to attributes or cached for rendering.

Slot-Based Authoring

All scalar values can be provided as slotted children instead of attributes. This enables server-rendered HTML where the persona data is inline content rather than attributes.

CSS Custom Properties

Variable Default Description
--user-persona-bg #ffffff / #1e1e1e Card background color
--user-persona-text #1a1a1a / #e8e8e8 Primary text color
--user-persona-muted #666666 / #888888 Secondary/muted text color
--user-persona-border #e0e0e0 / #333333 Card and section border color
--user-persona-accent #0066cc / #6b9fff Accent color for role text and bio icon
--user-persona-card-bg #f8f9fa / #252525 Section card background (quote block, content sections)
--user-persona-radius 16px Outer card border radius
--user-persona-avatar-size 80px Avatar width and height (56px in compact mode)
--user-persona-goals #22c55e / #4ade80 Goals section accent color
--user-persona-frustrations #ef4444 / #f87171 Frustrations section accent color
--user-persona-behaviors #8b5cf6 Behaviors section accent color

Events

Event Detail When
persona-ready { name, role, age, location } Fires after the component renders for the first time

Accessibility

  • The outer card uses role="article" with an aria-label of "User persona: [name]"
  • The avatar element has role="img" with aria-label="Avatar for [name]"
  • The decorative quotation mark uses aria-hidden="true" so screen readers skip it
  • Each content section has a visible heading for screen reader navigation
  • Respects prefers-reduced-motion: reduce by disabling all transitions
  • Responsive layout stacks to a single column at narrow viewports (<600px)

Related