Skip to content

Card and Surface

LayoutSince 0.2.0

Card and Surface. .aui-surface is a bordered panel on color-surface, with flat, raised, and sunken variants and optional inset padding. .aui-card adds header (title, subtitle), media, body, and footer sections. Both work as CSS-only APIs.

Card.create renders the structure with the right semantics:

  • an <article> named by its title when there is one, otherwise a plain <div>;
  • an optional block-link mode, where the whole card is clickable, there is exactly one tab stop, and screen readers announce only the title.
  • Titled or plainA titled card is an article with a heading at the level you choose.
  • Content areasBody, footer, and media areas take text or any DOM node.
  • Whole-card linkInteractive cards use one native link, so the whole card is clickable.
  • Surface variantsFlat, raised, and sunken surfaces, also available for your own elements.

Use it for

  • Grouping a self-contained piece of content: a product, project, article teaser, or summary tile.
  • Collections of similar items in a grid, each linking to a detail page (interactive cards).
  • Panels that visually separate a region of a page (Surface).

Use something else for

  • A single clickable action without content: use a Button or Link.
  • Cards with several equally important actions: do not use interactive mode; put actions in the footer instead.
  • Tabular or comparable data across items: use a table.
  • Nesting cards inside cards.
Anatomy
<div> (consumer host)
<article class="aui-surface aui-card [aui-surface--raised|--sunken] [aui-card--interactive]" aria-labelledby=title>
<div class="aui-card__header">
<h3 class="aui-card__title" id=title>Title (h2-h6, headingLevel)
<a class="aui-card__link" href>Title</a> (interactive only; ::after covers the card)
</h3>
<p class="aui-card__subtitle">Subtitle</p> (optional)
</div>
<div class="aui-card__media"> (visually first; hidden while empty)
<div class="aui-card__body"> (content; hidden while empty)
<div class="aui-card__footer"> (actions/metadata; hidden while empty)
</article> (<div> when there is no title)
</div>

Use the bar above each frame to switch theme, density, direction, and locale.

Card and Surface in the Team profile showcase

Section titled “Card and Surface in the Team profile showcase”

The part of the Team profile showcase that uses Card and Surface. Change its options, use it with the keyboard, and watch the event log; the link in the frame opens the full showcase. The bar above the frame switches theme, density, direction, and locale.

Showcase source
// Layout and content showcase: a team profile page built with the layout primitives, cards,
// typography, badges, keyboard keys, avatars, an avatar group, and a tag group.
import { Avatar } from '@absoluteui/components/avatar';
import { AvatarGroup } from '@absoluteui/components/avatar-group';
import { Badge } from '@absoluteui/components/badge';
import { Card } from '@absoluteui/components/card';
import { Kbd } from '@absoluteui/components/kbd';
import { Container, Divider, Flex, Grid, Stack } from '@absoluteui/components/layout';
import { TagGroup, type TagGroupChangeDetail } from '@absoluteui/components/tag-group';
import { Heading, Link, Text } from '@absoluteui/components/typography';
import { annotate, choice, createShowcase, hostIn, toggle } from './kit.js';
const sc = createShowcase({
title: 'Team profile',
description: 'Layout primitives and content components composing a real page. Resize the frame: the grid reflows.',
});
const page = hostIn(sc.stage);
Container.apply(page, { size: 'lg' });
const stack = Stack.apply(page, { gap: 6 });
// Each block of the page declares its components (focus mode shows a component's own blocks).
// Header.
const header = annotate(hostIn(page), ['layout', 'avatar', 'typography', 'badge']);
const headerFlex = Flex.apply(header, { gap: 4, align: 'center', wrap: true });
const avatar = Avatar.create(hostIn(header), { name: 'Platform Engineering', size: 'xl', shape: 'square', icon: 'code' });
const titles = hostIn(header);
Stack.apply(titles, { gap: 1 });
titles.append(Heading.create(2, 'Platform Engineering', { size: 3 }), Text.create('Builds and runs the internal developer platform.', { tone: 'muted' }));
const badges = hostIn(titles);
Flex.apply(badges, { gap: 2, wrap: true });
const badgeList = [
Badge.create(hostIn(badges), { label: 'Hiring', tone: 'success', dot: true }),
Badge.create(hostIn(badges), { label: '14 members', tone: 'neutral' }),
Badge.create(hostIn(badges), { label: 'On call', tone: 'warning', variant: 'outline', icon: 'clock' }),
];
// Members grid of cards.
const members = annotate(hostIn(page), ['layout', 'card', 'avatar', 'typography']);
Stack.apply(members, { gap: 4 });
members.append(Divider.create({ label: 'Members' }));
const grid = hostIn(members);
const gridLayout = Grid.apply(grid, { columns: 'auto', minColumnWidth: '14rem', gap: 4 });
const MEMBERS = [
{ name: 'Ada Kowalski', role: 'Engineering lead', status: 'online' },
{ name: 'Bruno Silva', role: 'Site reliability', status: 'busy' },
{ name: 'Chen Wei', role: 'Backend engineer', status: 'away' },
{ name: 'Divya Nair', role: 'Frontend engineer', status: 'offline' },
] as const;
const cards = MEMBERS.map((m) => {
const content = document.createElement('div');
Flex.apply(content, { gap: 3, align: 'center' });
Avatar.create(hostIn(content), { name: m.name, status: m.status, size: 'md' });
const who = document.createElement('div');
who.append(Text.create(m.name, { strong: true }), Text.create(m.role, { tone: 'muted', size: 'sm' }));
content.append(who);
return Card.create(hostIn(grid), { content, variant: 'raised', headingLevel: 3 });
});
// Skills and shortcuts.
const details = hostIn(page);
Grid.apply(details, { columns: 'auto', minColumnWidth: '16rem', gap: 4 });
const skillsBody = document.createElement('div');
const tags = TagGroup.create(hostIn(skillsBody), {
label: 'Team skills',
removable: true,
selection: 'multiple',
value: ['kubernetes'],
items: [
{ value: 'kubernetes', label: 'Kubernetes' },
{ value: 'terraform', label: 'Terraform' },
{ value: 'go', label: 'Go' },
{ value: 'observability', label: 'Observability' },
{ value: 'security', label: 'Security' },
],
});
annotate(Card.create(hostIn(details), { title: 'Skills', content: skillsBody, headingLevel: 3 }).host, ['layout', 'card', 'tag-group']);
const shortcutsBody = document.createElement('dl');
shortcutsBody.className = 'sc-shortcuts';
for (const [keys, text] of [
['Mod+K', 'Search'],
['Mod+Shift+P', 'Command palette'],
['?', 'Show shortcuts'],
] as const) {
const dt = document.createElement('dt');
Kbd.create(dt, { hotkey: keys });
const dd = document.createElement('dd');
dd.textContent = text;
shortcutsBody.append(dt, dd);
}
annotate(Card.create(hostIn(details), { title: 'Shortcuts', content: shortcutsBody, headingLevel: 3 }).host, ['layout', 'card', 'kbd']);
const footer = annotate(hostIn(page), ['layout', 'avatar-group', 'typography']);
Flex.apply(footer, { gap: 3, align: 'center', justify: 'between', wrap: true });
const group = AvatarGroup.create(hostIn(footer), { label: 'Recently active', max: 4, items: ['Ada Kowalski', 'Bruno Silva', 'Chen Wei', 'Divya Nair', 'Emeka Obi', 'Farah Haddad', 'Grace Liu'].map((name) => ({ name })) });
footer.append(Link.create({ href: 'https://example.com/platform', text: 'Team handbook', external: true }));
sc.listen(tags.host, ['aui-change', 'aui-remove'], 'tags');
tags.host.addEventListener('aui-change', (e) => {
sc.log('selected skills', (e as CustomEvent<TagGroupChangeDetail>).detail.value);
});
choice(
sc,
'Spacing',
[
{ value: '4', label: 'Compact' },
{ value: '6', label: 'Comfortable' },
{ value: '10', label: 'Spacious' },
],
'6',
(g) => {
const gap = Number(g) as 4 | 6 | 10;
stack.update({ gap });
gridLayout.update({ gap: gap === 10 ? 8 : 4 });
headerFlex.update({ gap: gap === 10 ? 6 : 4 });
},
['layout'],
);
choice(
sc,
'Avatar shape',
[
{ value: 'square', label: 'Square' },
{ value: 'circle', label: 'Circle' },
],
'square',
(shape) => {
avatar.update({ shape });
group.update({ shape });
},
['avatar', 'avatar-group'],
);
toggle(sc, 'Outline badges', false, (outline) => {
for (const b of badgeList) b.update({ variant: outline ? 'outline' : 'subtle' });
}, ['badge']);
toggle(sc, 'Sunken cards', false, (sunken) => {
for (const c of cards) c.update({ variant: sunken ? 'sunken' : 'raised' });
}, ['card']);
import { Card } from '@absoluteui/components/card';
import { Button } from '@absoluteui/components/button';
const host = document.createElement('div');
document.body.append(host);
const archive = document.createElement('button');
archive.type = 'button';
archive.textContent = 'Archive';
Button.enhance(archive);
Card.create(host, {
title: 'Quarterly report',
subtitle: 'Updated today',
content: 'Revenue grew 4% compared to last quarter.',
footer: archive,
variant: 'raised',
});
import { Card } from '@absoluteui/components/card';
const host = document.createElement('div');
document.body.append(host);
const img = document.createElement('img');
img.src = '/images/alpha.png';
img.alt = '';
Card.create(host, {
title: 'Project Alpha',
subtitle: 'Owner: Ada Lovelace',
media: img,
interactive: { href: '/projects/alpha' },
headingLevel: 2,
});
import { Surface } from '@absoluteui/components/card';
const panel = document.createElement('section');
document.body.append(panel);
const surface = Surface.apply(panel, { variant: 'sunken', padded: true });
surface.update({ variant: 'raised' });
import { configureAbsoluteUI } from '@absoluteui/core';
configureAbsoluteUI({ components: { card: { headingLevel: 2 } } });
Terminal window
npm install @absoluteui/components @absoluteui/core @absoluteui/theme

Registry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.

import { Card, Surface } from '@absoluteui/components/card';
import '@absoluteui/components/card/style.css';
import { Card } from '@absoluteui/components/card';
import '@absoluteui/components/card/style.css';
const host = document.querySelector<HTMLElement>('#report');
if (host) {
const button = document.createElement('button');
button.type = 'button';
button.textContent = 'Download';
const card = Card.create(host, { title: 'Quarterly report', content: 'Revenue grew 4%.', footer: button, variant: 'raised' });
button.addEventListener('click', () => {
card.update({ subtitle: 'Download started' });
});
}
More usage
<article class="aui-surface aui-card" aria-labelledby="c1">
<div class="aui-card__header"><h3 class="aui-card__title" id="c1">Quarterly report</h3></div>
<div class="aui-card__body">Revenue grew 4%.</div>
</article>
import { Card } from '@absoluteui/components/card';
const host = document.createElement('div');
document.body.append(host);
Card.create(host, { title: 'Project Alpha', subtitle: 'Owner: Ada', interactive: { href: '/projects/alpha' } });

Using Angular? See Card and Surface for Angular.

Card.create(host: HTMLElement, options?: CardOptions): Card; Surface.apply(el: HTMLElement, options?: SurfaceOptions): SurfaceHandle

Global configuration key: card (see Configuration).

Option Type Default Description
title string Card heading and the <article>’s accessible name (aria-labelledby). Without a title the card is a <div>.
subtitle string Supporting line under the title (text only).
content Node | string Body content; strings render as text. Omit to fill card.body directly.
footer Node Footer content such as actions or metadata.
media Node Image or illustration, shown above the header while the header stays first in source order.
interactive { href: string } Block-link mode: the title becomes the only link and its ::after covers the card. Requires title; href must be http(s) or relative.
variant 'flat' | 'raised' | 'sunken' "flat" Surface treatment (Card and Surface.apply).
padded boolean false Surface.apply only: space-inset padding.
headingLevel 2 | 3 | 4 | 5 | 6 3 Heading level of the card title; match it to the surrounding outline. Globally configurable.
Property Type Description
host HTMLElement Card: consumer host; its children are replaced by the card.
element HTMLElement Card: root <article> (titled) or <div>. Replaced when the title is added or removed.
body HTMLDivElement Card: body content area.
footer HTMLDivElement Card: footer area (hidden while empty).
media HTMLDivElement Card: media area (hidden while empty).
options Readonly<CardOptions> | Readonly<SurfaceOptions> Current options.
Method Description
update(options: Partial<CardOptions>): void Merge, validate, and apply options. Content areas are replaced only when their option is passed; pass undefined to remove title, subtitle, or interactive.
destroy(): void Card: remove the card element and the configuration subscription. SurfaceHandle: remove the classes it added.
Area Description
body card.body (or the content option).
footer card.footer (or the footer option).
media card.media (or the media option).

All rules live in the aui.components cascade layer, so application styles override them without specificity battles.

Class Purpose
aui-surface Bordered panel on color-surface with radius-md.
aui-surface--raised | --sunken | --padded Surface modifiers.
aui-card Card root (combined with aui-surface).
aui-card--interactive Block-link card: hover and focus-visible states on the card.
aui-card__header Title and subtitle.
aui-card__title Heading (h2 to h6).
aui-card__link Interactive title link; its ::after covers the card.
aui-card__subtitle Supporting text.
aui-card__media Media area, visually first.
aui-card__body Body content.
aui-card__footer Footer, a wrapping row.

Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.

--aui-border-width | --aui-color-border | --aui-color-border-strong | --aui-color-focus-ring | --aui-color-link | --aui-color-surface | --aui-color-surface-sunken | --aui-color-text | --aui-color-text-muted | --aui-duration-fast | --aui-easing-standard | --aui-focus-ring-offset | --aui-focus-ring-width | --aui-font-family-sans | --aui-font-size-lg | --aui-font-size-md | --aui-font-size-sm | --aui-font-weight-semibold | --aui-line-height-normal | --aui-line-height-tight | --aui-radius-md | --aui-shadow-md | --aui-shadow-sm | --aui-space-1 | --aui-space-2 | --aui-space-inset

TypeScript definitions
type CardHeadingLevel = 2 | 3 | 4 | 5 | 6;
type SurfaceVariant = 'flat' | 'raised' | 'sunken';
interface CardInteractive { href: string }
interface CardOptions {
title?: string; subtitle?: string; content?: Node | string; footer?: Node; media?: Node;
interactive?: CardInteractive; variant?: SurfaceVariant; headingLevel?: CardHeadingLevel;
}
interface SurfaceOptions { variant?: SurfaceVariant; padded?: boolean }
interface SurfaceHandle { readonly element: HTMLElement; readonly options: Readonly<SurfaceOptions>; update(o: Partial<SurfaceOptions>): void; destroy(): void }

Pattern: HTML <article> named by its heading; interactive cards use the block-link pattern (Inclusive Components ‘Cards’): one real link on the title, stretched over the card with a pseudo-element.

Checked on every docs build: the showcase passes axe (WCAG 2.2 A and AA rules) in the default, dark, and high-contrast themes and right to left; the playground loads without errors and passes axe before and after every on/off option is switched, with no Content Security Policy violations.

Key Context Action
Tab / Shift+Tab Interactive card One tab stop: the title link. Other controls inside the card (for example footer buttons) are separate tab stops after it.
Enter Title link focused Follows the link (native).
Tab / Shift+Tab Non-interactive card The card itself is not focusable; focus moves through any controls in its content.
Element Role
titled card root article (native <article>)
untitled card root none (generic <div>)
title heading, level 2 to 6 (headingLevel, default 3)
interactive title link (native <a href>) inside the heading
Attribute Element Value
aria-labelledby <article> id of the title heading

Interactive cards draw the focus indicator on the whole card (:has(.aui-card__link:focus-visible)) and underline the title; the link’s own outline is suppressed so only one indicator shows.

Criterion Level Note
1.3.1 Info and Relationships A
1.4.1 Use of Color A
1.4.3 Contrast (Minimum) AA
1.4.11 Non-text Contrast AA
2.1.1 Keyboard A
2.4.4 Link Purpose (In Context) A
2.4.7 Focus Visible AA
2.5.3 Label in Name A
4.1.2 Name, Role, Value A

Automated test results: Accessibility and compliance.

  • Screen readers announce only the title as the link name, not the whole card content.
  • The media area is visually first but after the header in source order, so the heading is reached first when navigating by heading or reading.
  • Section containers are <div>s, not <header>/<footer>, so untitled cards never create banner or contentinfo landmarks.
  • Consumers must give informative images in media a text alternative, or alt=“” when decorative.
  • Mouse text selection inside interactive cards is limited by the link overlay.
  • Manual screen-reader verification (NVDA, JAWS, VoiceOver) is pending.
Import cost Minified gzip brotli CSS brotli
@absoluteui/components/card 10.2 kB 4.1 kB 3.5 kB 0.8 kB

Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.

Tested scale: Constant DOM per card (root plus five section elements) and one configuration subscription; no event listeners. Not yet part of the e2e performance suite.

Constant DOM per card (root plus five section elements), no event listeners, and one configuration subscription. There is no dedicated performance budget yet.

Measured run times: Performance.

States

default, raised, sunken, interactive, hover (interactive), focus-visible (interactive).

State transitions
From Trigger To
untitled <div> update({ title }) <article>; content areas move to the new root
titled update({ title: undefined }) <div>; interactive must be removed first or in the same update
static update({ interactive: { href } }) block link
any global headingLevel change title heading re-created at the new level
Accessibility notes
  • Block-link pattern: wrapping the whole card in <a> would make screen readers read the entire card as the link name. Here only the title is the link, stretched with ::after.
  • The focus indicator is drawn around the whole card (:has(.aui-card__link:focus-visible)).
  • Media is visually first but comes after the header in source order, so heading navigation reaches the title first.
  • Give informative images a text alternative, or alt="" when decorative.
  • Manual screen-reader verification is pending.
Responsive behavior

Cards fill their container. For responsive collections, place them in an aui-grid aui-grid--auto (layout). Footer content wraps; media images are fluid.

Right-to-left

Logical properties throughout; all sections follow the writing direction.

Theming

Colors, radius, shadow, and padding come from role tokens (space-inset follows density). Verified token pairs: color-text and color-text-muted on color-surface and color-surface-sunken, and color-link on color-surface. In forced-colors mode, the border stays, the title link uses LinkText, and focus uses a Highlight outline.

Global configuration
configureAbsoluteUI({ components: { card: { headingLevel: 2 } } });

Existing cards re-render their title at the new level.

Component configuration

The headingLevel option overrides global and theme defaults. All options are dynamic.

Icons

None. Cards render no icons of their own.

Security
  • Title, subtitle, and string content use textContent. Node content is appended as-is; the consumer owns it.
  • interactive.href is checked with the WHATWG URL parser and must be http(s) or relative. javascript:, data:, and other schemes are rejected, including obfuscated forms such as java\tscript:.
  • No inline styles. CSP-safe.
Data handling

No persistence, network access, or telemetry.

Supported data scale

Not data-driven. For long card collections, render only visible cards (virtualize) in the application.

Edge cases
  • interactive without title throws CARD_OPTIONS.
  • Adding or removing the title replaces card.element (the tag changes). body, footer, and media keep their content.
  • Controls inside an interactive card are lifted above the overlay (position: relative; z-index: 1), so they stay clickable.
  • update() without content keeps whatever the consumer appended to card.body.
Errors
Code Category Cause
CARD_OPTIONS configuration Blank title, invalid content types, invalid variant, interactive without a title, or an unsafe href.
SURFACE_OPTIONS configuration Invalid surface variant or padded.
SURFACE_ALREADY_APPLIED configuration Surface.apply on an element that already has an active surface handle.
CFG_INVALID_VALUE configuration headingLevel outside 2-6.

A failed construction leaves the host untouched and registers no subscription.

Known limitations
  • Mouse text selection inside interactive cards is limited by the link overlay.
  • The root element is replaced when the title is added or removed.
  • Manual screen-reader verification is pending.
Unsupported scenarios
  • HTML strings as title, subtitle, or content (pass a Node).
  • A button (non-navigation action) as the whole-card target.
  • Heading level 1 for card titles.