Card
A flexible container for grouping related content. Cards support three visual variants and compose with header, body, and footer sub-components.
Wrap content in
<x-wirekit::— not directly insidecard. body> <x-wirekit::. The card root is intentionally padding-free so it can host edge-to-edge hero images. Inner padding lives on the three sub-components (card> card.header,card.body,card.footer). Dropping raw text directly inside<x-wirekit::renders flush against the border — almost certainly not what you want. The sub-components are listed bycard>...</x-wirekit:: card> php artisan wirekit:show cardand exposed via thesub_componentsfield inwirekit:export-json. For edge-to-edge content (a flush hero image or full-bleed table) set<x-wirekit::to drop the body padding — a rawcard. body :padded="false"> <table>dropped inside an unpadded body still gets readable cell padding automatically.
Live Sandbox
This is a hydrated playground for the component. Toggle "Live preview" on the block below to swap the static HTML render for a real Livewire instance — every prop in the component's sandbox schema becomes an editable form field inside the iframe, so you can try different prop combinations live without writing any local code.
Basic Usage
Full Composition
Buttons in the header
The actions slot of card.header puts buttons at the end of the head, and description a sentence under the heading. The buttons stand beside the heading while the head has room and drop under it where it has not: the heading asks for 16rem, measured in the card, not in the window, as the actions of a page header do.
A card that is itself a link or a button is one control, so its head takes no buttons. On a card with href, as="button" or role="button", actions is reported and left out: a button inside a link or inside another button is a control inside a control, and a screen reader reads it as part of the outer control's name. To give such a card a destination and keep its buttons, leave href off the card and link the heading:
<x-wirekit::card class="max-w-xl">
<x-wirekit::card.header description="Who can see the orders of this branch.">
<x-wirekit::heading level="2" size="lg">
<x-wirekit::link href="/teams/orders">Team</x-wirekit::link>
</x-wirekit::heading>
<x-slot:actions>
<x-wirekit::button size="sm">Invite</x-wirekit::button>
</x-slot:actions>
</x-wirekit::card.header>
<x-wirekit::card.body>
Three members, two of them admins.
</x-wirekit::card.body>
</x-wirekit::card>
An icon in the header
The iconSlot of card.header stands an icon before the heading and its sentence, as the head of a card of settings carries one. The space between the icon and the words is a token of its own, --gap-wk-card-header-icon, so you can widen or narrow it without moving the other small gaps of the head.
Edge-to-edge content
The card root has no padding, so <x-wirekit:: lets a hero image or full-bleed table run flush to the card's rounded edges. Stack a padded body below it for the copy.
Lisbon, three nights
From €320 for two, breakfast included.
Letting a child reach past the card
A card clips its content by default, which is what makes the rounded corners cut the content inside them. The same clip catches anything else that reaches past the box — a badge pinned to a corner, an avatar that scales on hover, a focus ring that extends past the edge.
Support inbox
Three conversations wait for an answer.
The badge stands outside the card's box. With the default overflow="hidden" its top-right corner
would be cut off.
Reach for overflow="visible" rather than forcing the base class with an !important
utility override. The override is not the same thing: it removes the clipping for every child at once, which
is harmless while the content is padded and wrong the moment a full-bleed image or a table
goes into that card — and nothing will say so.
auto and clip are accepted too, for a card whose content should scroll inside it or be
cut without a scrollbar.
card.body sets no overflow of its own, so it does not clip and needs no matching prop. If
you are carrying an override on both the card and its body, the body half is doing nothing.
Variants
A border in the color of an intent
intent draws the card's border in a color role: info, success, warning or danger. neutral is the border a card has without it. The border takes the tone callout draws its own border in, so a card that holds a warning can carry the same border while the warning stands. Background and shadow stay those of the surface, and the prop works with all three.
Bind it to the state that calls for it, and the card goes back to its neutral border once the state is resolved:
<x-wirekit::card :intent="$missingDetails === [] ? 'neutral' : 'warning'">
{{-- ... --}}
</x-wirekit::card>
Clickable Card
Pass href to render the card as a link with hover elevation:
When href is set, the card renders as an <a> tag, gets cursor-pointer, and shows a stronger shadow on hover.
Show at rest that the card leads somewhere
The pointer and the hover shadow are the only signs of a clickable card, and a phone shows neither: there, a card with href looks exactly like a card with nothing behind it. Add chevron and the card carries a chevron at its inline end, at rest:
The chevron is decoration and hidden from screen readers, because the card's own text already names where it goes. It points toward the end of the line in either writing direction, and the content keeps a column of its own beside it, so no text runs under the chevron. It works the same on a card that runs an action with as="button". A card that neither links nor runs an action never draws one, even with the prop set: the chevron would promise a destination that is not there.
A card that runs an action instead of navigating
A navigation is not the only thing a whole card can do. When the click runs an action — a
Livewire call, an Alpine handler — render the card as a real <button> with as="button".
It gets the same pointer and the same hover shadow: the treatment follows what the card
does, not the tag it happens to be.
Two things the tag brings with it, both worth setting deliberately:
type="button". A<button>inside a<form>submits it unless you say otherwise — the card does not add the attribute for you, because a card that genuinely is the submit control is a legitimate use.- A
<button>isinline-blockand centers its text. The card keepsblockon the<a>branch only, so it will not silently change the width of a button card. Addw-fullandtext-startwhere you want the full-width look an<a>card has, its text at the start of the line.
A plain <div> card also picks up the interactive treatment when it carries a click binding
(wire:click, @click, x-on:click, onclick) or role="button" — but prefer the real
<button>: it is focusable, it answers Enter and Space, and screen
readers announce it as a control.
A Card That Folds
collapsible folds a card under its own head. The head is the trigger, a button inside a heading
with a chevron in a circle at its end, and the whole head answers a click or a tap, the chevron
included. Everything in the card, its body and its footer, folds away beneath it. The heading, the
line under it and the hints beside it stay in sight, so a closed card still says what it holds and
whether anything in it needs the reader. A footer that opens what folds draws no second line under
the head.
2 undecided
The head of a collapsible card comes from its own props and slots: heading, level,
description and the hints slot. A card.header inside a collapsible card would fold away with
the body.
The hints stand beside the heading while the head has room and drop under it where it has not, as the buttons in the header do: the heading asks for 16rem, measured in the card, not in the window, and the chevron keeps to the end of the head. A heading with a word that does not break, such as a product code, and a badge in the hints keep the card inside its column on a phone.
A press anywhere on the head folds the card, the line under the heading included. A link in the
description slot and a button in the hints, such as the one of a dismissible badge, take their
own click, and the words around them stay part of the head.
Starting open
open starts the card open. Pass it where the card needs the reader, a field that failed validation
or a decision still to make. An open from the server wins on every load, even over a fold the
reader made on an earlier visit, and the reader can still fold the card while they are on the page.
During the visit the state is the reader's: a Livewire response that changes open leaves the card
as the reader has it. A response opens a card only for a reason it did not have, which the next
section describes, or for a field it rejects.
<x-wirekit::card collapsible :open="$errors->has('payment.*')" heading="Payment methods">
<x-wirekit::card.body>…</x-wirekit::card.body>
</x-wirekit::card>
Opening for a Reason
open-when says why the card stands open: a list of reasons, or a map of each reason to whether it
holds right now. With one the card starts open, as with open. After a Livewire response it opens
only for a reason it did not have before, so a card the reader folded with an undecided price in it
stays folded until something new needs them.
<x-wirekit::card
collapsible
heading="Prices"
:open-when="['undecided' => $undecidedPrices > 0, 'unsaved' => $pricesChanged]"
>
<x-wirekit::card.body>…</x-wirekit::card.body>
</x-wirekit::card>
$undecided and $pricesChanged are your Livewire component's: a count of the prices still
to decide and whether the reader changed one that is not saved yet. Each render hands the card the
reasons that hold, and the card compares them with the ones it had.
A field that a response marks invalid opens its card without a reason of its own. Every WireKit
field sets aria-invalid="true" on its error, and the card watches the fields it folds for that. A
card that holds a rejected field when the page loads starts open. To take the reader to the first
rejected field as well, see The Focus After a Refused Save.
Remembering the reader's choice
persist names a key under which the browser remembers, in localStorage, whether the reader left
the card open. A card without open starts the way the reader left it.
<x-wirekit::card collapsible persist="settings.receipts" heading="Receipts">
<x-wirekit::card.body>…</x-wirekit::card.body>
</x-wirekit::card>
To keep the choice with the reader's account instead, leave out persist, give the card a name,
pass what you stored as open, and save each change from wirekit:card-toggled. Its detail carries
the card's name and whether it is now open:
<x-wirekit::card
collapsible
name="settings.receipts"
:open="in_array('settings.receipts', $openCards, true)"
heading="Receipts"
x-on:wirekit:card-toggled="$wire.rememberCard($event.detail.name, $event.detail.open)"
>
<x-wirekit::card.body>…</x-wirekit::card.body>
</x-wirekit::card>
$openCards and rememberCard() are your Livewire component's: a list of names read from the
account in mount(), and a method that writes one change back.
Opening it from elsewhere
A closed card opens for the reader when
- the browser's find in page matches text inside it, where the browser supports that
(
:findable="false"keeps the content out of the search), - a field inside it is invalid when its form is submitted, so the browser can show the field's message,
- a response marks a field inside it invalid, or brings a reason in
open-whenthat it did not have, - the address names an element inside it, as a link to
#receipt-footerdoes, also when the reader follows that link again after folding the card, wirekit:card-openreaches it, dispatched on an element inside the card, or onwindowwith the card'sname, a list ofnames, orall:
// 1. From inside: every card around the element opens.
document.getElementById('receipt-footer').dispatchEvent(new CustomEvent('wirekit:card-open', { bubbles: true }));
// 2. By name, from anywhere on the page.
window.dispatchEvent(new CustomEvent('wirekit:card-open', { detail: { name: 'settings.receipts' } }));
// 3. Several by name, or every collapsible card on the page.
window.dispatchEvent(new CustomEvent('wirekit:card-open', { detail: { names: ['settings.receipts', 'settings.prices'] } }));
window.dispatchEvent(new CustomEvent('wirekit:card-open', { detail: { all: true } }));
A Livewire component with #[Lazy] inside a closed card whose content stays findable, or anything else that waits for x-intersect there, loads with the page rather than when the reader opens it, in a browser that supports hidden="until-found": the closed content keeps its box, so it counts as in view. Set :findable="false" where such content should wait for the reader.
The part that folds slides open from nothing, so an element inside reaches its place only when the
slide ends. A link to an element inside waits for that before it brings the element into view. A
script of yours waits for wirekit:card-opened, which rises from the card once it stands open at
its full height, also when it was open already:
// 1. Bring the element into view once the card around it stands open.
window.addEventListener('wirekit:card-opened', (event) => {
if (event.detail.name === 'settings.receipts') {
document.getElementById('receipt-footer').scrollIntoView({ block: 'center' });
}
}, { once: true });
// 2. Then open it.
window.dispatchEvent(new CustomEvent('wirekit:card-open', { detail: { name: 'settings.receipts' } }));
wirekit:card-close folds a card the same ways, except from inside: there it folds the nearest card
only, never the cards around it. When the focus was inside a card that folds, it moves to the card's
head. From Livewire, $this->dispatch('wirekit:card-open', name: 'settings. reaches a card on
window. Buttons that open and close every card dispatch all:
None of these is the reader's own choice, so none of them is remembered under persist or reported
by wirekit:card-toggled. A page that keeps "expand all" with the reader's account saves it from
its own button. On paper a collapsible card prints open.
Semantic HTML
Use the as prop to change the root tag (e.g. for <article>, <section>):
<x-wirekit::card as="article">
<x-wirekit::card.header><x-wirekit::heading level="2" size="lg">Release notes for March</x-wirekit::heading></x-wirekit::card.header>
<x-wirekit::card.body>Search answers faster, and every report exports to CSV.</x-wirekit::card.body>
</x-wirekit::card>
Width & Layout
Cards are block-level elements that fill their parent width by default. Control the width with Tailwind classes directly on the component:
In your own code you can of course reach for Tailwind's grid grid-cols-3 gap-4 utilities directly; <x-wirekit:: is the version that keeps following the design tokens when they change.
Props
Card Props
| Prop | Type | Default | Description |
|---|---|---|---|
surface |
string|null | null |
The surface treatment on the kit's canonical axis, spelled the way button spells it: outline, elevated, flat. Unset, it falls back to variant |
variant |
string | 'outlined' |
The back-compat alias of surface: outlined, elevated, flat, with outline accepted as an alias of outlined — note the direction, card's own spelling is the longer one and button's is the shorter. Kept for the whole of v2; surface wins when a call site sets both |
intent |
string|null | null |
The color role of the border: neutral (the border without it), info, success, warning or danger, in the tones callout draws its border in. Background and shadow stay those of the surface. See A border in the color of an intent |
as |
string | 'div' |
HTML tag for the root element (ignored if href is set). as="button" also gets the interactive treatment — see A card that runs an action instead of navigating |
href |
string|null | null |
Renders as <a> with the interactive treatment |
chevron |
boolean | false |
Draws a chevron at the inline end of a card that links or runs an action, so it reads as clickable without a pointer. Ignored on a card that does neither. See Show at rest that the card leads somewhere |
overflow |
string | 'hidden' |
What the card does with a child that reaches past its box: hidden, visible, auto, clip. The default clips, which is what makes the rounded corners cut the content inside them. See Letting a child reach past the card |
animateIn |
string|null | null |
Entrance-reveal preset (e.g. 'fade', 'slide-up', 'scale-in') — inline alternative to wrapping in <x-wirekit::reveal>. See Animations for the full preset list. Respects prefers-reduced-motion: reduce. |
collapsible |
boolean | false |
Folds the card under its own head. See A Card That Folds. A card that links or runs an action cannot fold, and strict validation says so |
open |
boolean|null | null |
Starts a collapsible card open, over a fold the reader made on an earlier visit. On a card that does not fold, an open you pass goes to the element, as as="details" needs |
openWhen |
array|string | [] |
The reasons a collapsible card stands open for: a list, or a map of each reason to whether it holds. With one the card starts open, and after a response only a reason it did not have opens it again. See Opening for a Reason |
persist |
string|null | null |
A key under which the browser remembers whether the reader left a collapsible card open |
name |
string|null | null |
The name wirekit:card-open and wirekit:card-close address a collapsible card by, reported in wirekit:card-toggled. On a card that does not fold it goes to the element |
heading |
string|null | null |
The text of a collapsible card's trigger; required there. The heading slot takes markup instead |
level |
int | 3 |
The level of the heading the trigger stands in, 2 to 6 |
description |
string|null | null |
The line under the heading, in sight whether the card is open or closed. The description slot takes markup instead |
findable |
boolean | true |
Closed content of a collapsible card stays findable by the browser's find in page, which opens the card |
scope |
string|null | null |
Scoped personalization name |
Slots of a Collapsible Card
| Slot | Description |
|---|---|
heading |
Markup for the trigger, in place of the heading prop |
description |
Markup for the line under the heading, in place of the description prop |
hints |
Badges or short text beside the heading, read with the trigger as its description |
Sub-Components
| Component | Description |
|---|---|
card.header |
Top section with bottom border, heading typography. Takes description, a sentence under the heading (or a description slot), and an actions slot for buttons at its end, which drop under the heading where the head has no room. See Buttons in the header |
card.body |
Main content area with comfortable padding |
card.footer |
Bottom section with top border and the subtle background |
Events
| Event | Direction | Detail |
|---|---|---|
wirekit:card-toggled |
Rises from a collapsible card when the reader opens or closes it with its head | name, persist, open |
wirekit:card-open |
Opens a collapsible card: dispatched on an element inside it, which opens every card around it, or on window |
name, names or all, on window |
wirekit:card-close |
Folds a collapsible card: dispatched on an element inside it, which folds the nearest card, or on window |
name, names or all, on window |
wirekit:card-opened |
Rises from a collapsible card once it stands open at its full height, after any way of opening it, and in answer to wirekit:card-open when it was open already |
name |
Accessibility
- When using
href, the entire card becomes a single focusable link. For cards with multiple interactive elements (buttons, links), prefer leaving the card as a<div>and let users click the inner elements individually. - A card that acts on click should be
as="button", not a<div>with a handler. The pointer and the hover shadow follow either one, but only the<button>is in the tab order and answers Enter and Space. A<div role="button">needstabindex="0"and its own key handling before it is operable — the card does not add them. - Use the
asprop to choose semantic HTML appropriate for your content (article,section,aside). card.headergives its content the look of a heading, not its role. Where the header names the card, put a heading in it,<x-wirekit::, at the level the page's outline asks for. Without one, the card is missing from the headings a screen reader lists and jumps between.heading level="2" size="lg"> - A collapsible card's head is a
<button>inside a heading, anh3unlesslevelsays otherwise, witharia-expandedandaria-controlsnaming the part that folds. The hints are its description, read after its name; the line under the heading is plain text after it. Pick thelevelthat fits the page's outline: every card on one page usually shares it. - A card that folds while the focus is inside it, from
wirekit:card-close, gives the focus to its head, so the focus never stays on a field nobody can see. The reader's own click is on the head already. - Ensure sufficient color contrast when overriding the card background — all default variants meet WCAG AA.
Keyboard Interaction
The card frame carries no key handling of its own — the keyboard behavior is whatever the
root tag brings. A <div> card is not focusable. With href it is a link, so Tab
reaches it and Enter follows it; with as="button" it is a button, so Tab
reaches it and both Enter and Space activate it. Either way the focused
card draws the kit's focus ring, in --color-wk-ring at --ring-wk-width, standing off the card
by --ring-wk-offset.
A collapsible card's head is a button: Tab reaches it, and Enter and Space open and close the card. The ring then outlines the whole head, inside the card.
Pitfalls
- Wrap content in
<x-wirekit::. The card root is a padding-free frame, so raw content placed directly inside renders flush against the border. Usecard. body> card.body(orcard.header/card.footer); in development a console warning flags a card whose content is not wrapped. - Don't apply a
dark:prefix on inner content. The card's surface token (--color-wk-bg-elevated) auto-switches under the.darkclass —dark:overrides bypass the theme. - Don't nest a card inside another card for visual emphasis. Use the
surfaceprop (elevated,flat,outline) for visual weight — nesting compounds shadows and creates a "double frame" anti-pattern.
Design Tokens
Cards use these tokens for consistent theming:
| Token | Purpose |
|---|---|
--color-wk-bg-elevated |
Card background (light: white, dark: neutral-900) |
--color-wk-bg-subtle |
Flat variant + footer background |
--color-wk-border |
Outlined variant border |
--color-wk-info-tone, --color-wk-success, --color-wk-warning, --color-wk-danger |
The border of a card with an intent, 35% of the tone mixed into --color-wk-border, as on callout and alert |
--color-wk-border-strong |
The circle around the chevron of a collapsible card |
--color-wk-border-subtle |
Sub-component dividers, and the line under a collapsible card's head while it is open |
--color-wk-text-muted |
The line under a collapsible card's heading, and its chevron |
--color-wk-ring |
The focus ring of a collapsible card's head |
--shadow-wk-md |
Elevated variant shadow |
--shadow-wk-lg |
Interactive card hover shadow |
--radius-wk-lg |
Card corner radius |
--gap-wk-card-header-icon |
The space between the icon in a card's head and its heading and sentence |
All tokens automatically adapt to light/dark mode.
Customization
Override defaults in config/:
'components' => [
'card' => ['variant' => 'elevated'],
],
Two class blocks are adjustable on every card, base and variant, and six more on a collapsible one: head, trigger, description, hints, content and chevron, the circle around the arrow, whose color the arrow takes. Replacing variant is how a card carries a selected state — a metric tile that sets a filter, for instance:
// 1. In a service provider's boot(), or scoped with the `scope` prop.
WireKit::personalize('card', [
// 2. REPLACES the variant block rather than adding to it.
'variant' => 'border-[length:var(--border-wk-width)] border-[var(--color-wk-accent)] ring-1 ring-inset ring-[var(--color-wk-accent)]',
]);
Every variant sets a border color, so an extra class lands in the same attribute at the same specificity. Which one wins is then decided by the order the classes happen to appear in your built stylesheet rather than by which you meant, and the card renders as though you had never set it — no error, no warning, just the wrong border. Replace the block instead.
Usage & Conventions
Prop conventions — this component uses one or more of the shared semantic prop names (
intent/variant/tone/surface). See Prop naming conventions for the canonical vocabulary, alias matrix, and decision tree.
Further Reading
- MDN:
<article>vs<section>vs<div>— when to use each for cards - WAI-ARIA Landmark Regions
- Inclusive Components: Cards