Opacity Token Values
Opacity Token Values
Opacity token values establish consistent transparency levels across a design system. Opacity affects visual hierarchy, disabled states, overlays, and decorative effects. Without tokenized opacity values, transparency becomes arbitrary, with developers choosing ad-hoc percentages that fragment visual consistency. Opacity tokens ensure intentional, repeatable transparency application.
What Are Opacity Token Values
Opacity token values are design tokens that define transparency levels, typically as decimal values between 0 (fully transparent) and 1 (fully opaque). These tokens apply to element opacity, background transparency, and alpha channel values in colors.
Opacity tokens capture deliberate design decisions about how transparent different interface elements should be, from subtle background overlays to significantly dimmed disabled states.
How Opacity Token Values Work
Opacity token systems typically define a scale:
{
"opacity": {
"0": { "value": "0" },
"5": { "value": "0.05" },
"10": { "value": "0.1" },
"20": { "value": "0.2" },
"30": { "value": "0.3" },
"40": { "value": "0.4" },
"50": { "value": "0.5" },
"60": { "value": "0.6" },
"70": { "value": "0.7" },
"80": { "value": "0.8" },
"90": { "value": "0.9" },
"100": { "value": "1" }
}
}
Semantic opacity tokens map scale values to purposes:
{
"opacity": {
"disabled": { "value": "{opacity.40}" },
"placeholder": { "value": "{opacity.50}" },
"overlay": { "value": "{opacity.80}" },
"backdrop": { "value": "{opacity.50}" },
"hover": { "value": "{opacity.90}" }
}
}
CSS application:
.disabled-element {
opacity: var(--opacity-disabled);
}
.modal-backdrop {
background: rgba(0, 0, 0, var(--opacity-backdrop));
}
.placeholder-text {
opacity: var(--opacity-placeholder);
}
Key Considerations
- Opacity affects accessibility; low opacity can reduce contrast below WCAG thresholds
- Semantic tokens communicate intent more clearly than numeric values
- Opacity compounds with parent opacity, which can cause unexpected results
- Alpha channel colors offer more control than element opacity
- Performance impact is minimal but GPU compositing applies
- Animation of opacity is well-optimized in browsers
- Disabled states need careful contrast consideration
- Print styles may need opacity adjustments or removal
Common Questions
How does opacity interact with accessibility?
Opacity reduces visual contrast, which can create accessibility issues. A text element with opacity: 0.5 effectively halves its contrast against the background.
Disabled state concerns: Overly transparent disabled elements may become illegible. The disabled opacity should reduce prominence while maintaining readability:
.button:disabled {
opacity: var(--opacity-disabled); /* 0.4-0.5 typical */
}
Testing disabled states with accessibility tools ensures adequate contrast remains.
Overlay backdrop accessibility: Modal backdrops need enough opacity to indicate the background is inactive but should not completely obscure it:
.modal-backdrop {
background: rgba(0, 0, 0, var(--opacity-backdrop));
}
Values around 0.5 typically work well, allowing users to perceive the underlying content while understanding it is inaccessible.
Focus indicators: Never reduce opacity of focus indicators. Focus must remain clearly visible for keyboard navigation.
When should opacity tokens versus alpha colors be used?
Element opacity (the CSS opacity property) affects the entire element including all children and pseudo-elements. Alpha channel colors affect only the specific color application.
Use element opacity when:
- Fading entire components (disabled states, exit animations)
- Creating compound transparency effects
- The entire element should uniformly change visibility
Use alpha colors when:
- Only specific color applications need transparency (backgrounds but not text)
- Avoiding inheritance of transparency to children
- Fine-grained control over individual properties
/* Element opacity - affects everything */
.faded-card {
opacity: 0.5;
}
/* Alpha color - affects only background */
.overlay {
background: rgba(0, 0, 0, 0.5);
color: white; /* Remains fully opaque */
}
Tokens can support both patterns:
{
"opacity": {
"overlay": { "value": "0.5" }
},
"color": {
"overlay": {
"background": { "value": "rgba(0, 0, 0, 0.5)" }
}
}
}
How should opacity scale granularity be determined?
The appropriate number of opacity steps depends on actual usage needs.
Minimal scales (3-5 values) suit most applications:
{
"opacity": {
"subtle": { "value": "0.2" },
"medium": { "value": "0.5" },
"prominent": { "value": "0.8" }
}
}
This simplicity forces deliberate choices and reduces visual inconsistency.
Percentage-based scales (10% increments) provide more options:
{
"opacity": {
"10": { "value": "0.1" },
"20": { "value": "0.2" },
"30": { "value": "0.3" }
// ... etc
}
}
This flexibility suits complex systems with varied transparency needs.
Evaluate scale needs by auditing current usage. If most opacity values cluster around a few levels, a minimal scale suffices. If many distinct values are genuinely needed, a granular scale may be appropriate.
Semantic tokens (disabled, overlay, backdrop) should be the primary consumption layer regardless of scale granularity.
Summary
Opacity token values establish consistent transparency across design systems. Scale tokens provide a vocabulary of opacity levels, while semantic tokens map these to specific use cases like disabled states and overlays. Accessibility considerations are essential since opacity affects contrast. The choice between element opacity and alpha colors depends on whether transparency should affect entire elements or specific properties. Scale granularity should match actual usage needs, with semantic tokens providing the primary consumption interface.
Buoy scans your codebase for design system inconsistencies before they ship
Detect Design Drift Free