output
Displays the result of a calculation or user action. Semantically ideal for form validation messages, computed values, and dynamic results. Used extensively in the form-field custom element for validation feedback.
When to Use
- Form validation messages (see form-field)
- Calculated totals or results
- Dynamic values that change based on user input
- Displaying range slider values
- Any result that is derived from other form controls
Why Output over div/span?
The <output> element is purpose-built for displaying results of calculations and user actions. It has three advantages that <div> and <span> lack:
- Semantic meaning: Browsers and assistive technology understand that output contains a computed result
aria-liveby default: Output has an implicitaria-live="polite"role, so screen readers announce changes automaticallyforattribute: Directly associates the result with the input(s) that produced it, giving assistive technology a clear relationship
| Approach | Semantics | Accessibility | Recommendation |
|---|---|---|---|
<output> |
Result of action | Native support with for attribute |
Recommended |
<span class="error"> |
None | Requires manual ARIA | Avoid |
<div class="message"> |
None | Requires manual ARIA | Avoid |
Basic Usage
Vanilla Breeze styles output as an inline-block element with monospace font, subtle raised background, and small border radius. Display a simple calculated or dynamic value:
<label>Calculated Total</label><output>$124.99</output>
Attributes
| Attribute | Purpose | Example |
|---|---|---|
for |
Space-separated IDs of related inputs | for="qty price" |
form |
Associates with a form by ID | form="order-form" |
name |
Name for form submission | name="total" |
Style Variants
Four CSS classes control presentation:
| Class | Effect |
|---|---|
| (default) | Inline monospace with subtle raised background |
.block |
display: block with larger padding for full-width output |
.inline |
No padding or background — blends into surrounding text |
.highlight |
Brand-tinted background with interactive color text |
.large |
Increased font size (var(--font-size-xl)) for prominent values |
<output>Default</output><output class="block">Block output</output><output class="inline">Inline</output><output class="highlight">Highlighted</output><output class="large">Large</output>
Variants can be combined: class="large highlight" or class="block success".
State Variants
Semantic colors for different message types. Each state uses an OKLCH-based tinted background with matching text color.
| Class | Use Case |
|---|---|
.success |
Confirmations, completed operations (green tones) |
.warning |
Caution messages, pending review (amber tones) |
.error |
Validation errors, failures (red tones) |
<output class="success">Operation completed</output><output class="warning">Please review</output><output class="error">Invalid input</output>
For Validation Messages
The primary use case in Vanilla Breeze. Pair with form-field and aria-describedby for CSS-only validation feedback.
<form-field> <label for="email">Email</label> <input type="email" id="email" required aria-describedby="email-msg" /> <output id="email-msg" for="email" aria-live="polite"> Enter a valid email address </output></form-field>
With Range Slider
Display the current value of a range input. The for attribute links the output to its source.
<label>Volume: <output id="volume">50</output>%</label><input type="range" min="0" max="100" value="50" oninput="document.getElementById('volume').value = this.value" />
Calculated Values
Display computed results from multiple inputs. The for attribute accepts a space-separated list of input IDs.
<input type="number" id="qty" value="2" /><input type="number" id="price" value="29.99" /><output for="qty price" class="large highlight">$59.98</output>
Live Status Updates
Use aria-live="polite" for dynamic content that should be announced by screen readers when it changes.
<output class="success" aria-live="polite">Connected</output><output aria-live="polite">All changes saved</output>
Accessibility Notes
- Use
forattribute: Associates output with related input(s) for assistive technology - Add
aria-live: Usepolitefor updates that should be announced (output has implicit live region semantics, but explicit is clearer) - Link with
aria-describedby: Connect inputs to their validation outputs so screen readers announce the message when the input is focused - Don't use for static content: Output is for dynamic/calculated values
- Include meaningful content: Always have useful text, not just icons
CSS Reference
output { display: inline-block; font-family: var(--font-mono); padding: var(--size-2xs) var(--size-xs); background: var(--color-surface-raised); border-radius: var(--radius-s);} /* --- Style Variants --- */ output.block { display: block; padding: var(--size-s) var(--size-m);} output.inline { padding: 0; background: transparent;} output.highlight { background: oklch(from var(--color-interactive) l c h / 0.1); color: var(--color-interactive);} output.large { font-size: var(--font-size-xl); padding: var(--size-s) var(--size-m);} /* --- State Variants --- */ output.success { background: oklch(60% 0.18 145 / 0.1); color: oklch(45% 0.15 145);} output.warning { background: oklch(75% 0.18 75 / 0.1); color: oklch(55% 0.15 75);} output.error { background: oklch(55% 0.2 25 / 0.1); color: oklch(50% 0.18 25);}
Related
- form-field - Uses output for validation messages
- meter - Visual gauge for scalar values
- progress - Task completion indicator
- input - Form inputs that output relates to
- data - Machine-readable value for static data