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 span/div? The output element has built-in accessibility semantics and can be associated with inputs via the for attribute.
Basic Usage
Display a simple calculated or dynamic value.
Code
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
Default
Inline monospace text with subtle background.
.block
Block-level output for larger content.
.inline
Minimal inline output without background.
Your total is including tax.
.highlight
Emphasized output with brand color.
.large
Prominent display for important values.
Code
State Variants
Semantic colors for different message types.
Code
For Validation Messages
The primary use case in Vanilla Breeze. See form-field for the complete pattern.
Code
With Range Slider
Display the current value of a range input.
Code
Calculated Values
Display computed results from multiple inputs.
Code
Live Status Updates
Use aria-live for dynamic content that should be announced.
Code
Why Output for Validation?
The <output> element is semantically ideal for form messages.
| 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 |
Accessibility Notes
- Use
forattribute: Associates output with related input(s) - Add
aria-live: Usepolitefor updates that should be announced - Link with
aria-describedby: Connect inputs to their validation outputs - Don't use for static content: Output is for dynamic/calculated values
- Include meaningful content: Always have useful text, not just icons
CSS Reference
Related Elements
- form-field - Uses output for validation messages
- meter - Visual gauge for scalar values
- progress - Task completion indicator
- input - Form inputs that output relates to