Pattern Overlay
Background patterns (dots, grid, lines, etc.) as overlays for any element.
When to Use
Use Pattern Overlay when you need to:
- Add subtle texture to card backgrounds, hero sections, or containers
- Differentiate visual sections with decorative patterns
- Create branded surface treatments using design token colors
- Add depth and visual interest to otherwise flat backgrounds
- Apply consistent, theme-aware background patterns across components
When Not to Use
- Over text-heavy content where patterns reduce readability — keep opacity very low or use Card without patterns
- On interactive elements where the pattern obscures focus indicators — use Separator for visual dividers instead
- As the sole visual differentiator for important data — use color, spacing, or Aspect Ratio containers
- When performance is critical with many overlapping patterns — CSS gradients can impact rendering
Default
Interactive demo showing all pattern types with adjustable scale and opacity controls.
Pattern Type
Scale
1.0xOpacity
15%Preview on Different Backgrounds
Background
Card
Primary
Secondary
Muted
All Pattern Types
Overview of all 11 available pattern types: dots, grid, diagonal lines, crosshatch, checkered, checkered-odd, plus, isometric, circles, custom, and solid (none).
Dots
Grid
Diagonal
Crosshatch
Checkered
Checkered Odd
Plus
Isometric
Circles
Custom
Solid
Card with Pattern
Use PatternOverlay inside a Card component by wrapping the card content in a relative container.
The pattern is rendered as an overlay and automatically adjusts to the background.
Button with Pattern
Subtle pattern textures can be applied to buttons. Use lower scale and opacity values for small elements.
PatternBackground Wrapper
PatternBackground is a convenience wrapper that handles relative positioning and z-index management automatically.
Grid Pattern
PatternBackground wraps content with automatic relative positioning and z-index management. No manual layout needed.
Crosshatch Pattern
The wrapper component handles overflow clipping, relative positioning, and z-index stacking automatically.
Custom Colors
Override the default currentColor with any CSS color value, including design system token variables.
Primary Color
color="var(--primary)"
Destructive Color
color="var(--destructive)"
Muted Foreground
color="var(--muted-foreground)"
Scale
The scale prop multiplies the base pattern size. Lower values create denser patterns, higher values create more spacious ones.
Scale 0.5x
Dense pattern
Scale 1x (Default)
Standard spacing
Scale 2x
Spacious pattern
UX & Design Guidelines
Visual Hierarchy
Patterns should be subtle enough to add texture without competing with content. Use low opacity values (0.05 to 0.15) for backgrounds behind text. Reserve higher opacity values for decorative hero sections or empty states where readability is not a concern.
Spacing & Layout
The parent container must have position: relative and overflow: hidden when using PatternOverlay directly. Content above the overlay needs relative z-10 to appear above the pattern. Use PatternBackground to avoid managing this manually.
Responsive Behavior
Pattern overlays scale based on the scale prop and CSS background-size, so they tile naturally at any container size. On smaller screens, consider reducing opacity slightly to avoid visual noise on compact layouts. Patterns remain performant across all viewport sizes since they use pure CSS gradients.
Color & Contrast
Patterns inherit currentColor by default, adapting to the parent text color. Use design token variables like var(--primary) or var(--muted-foreground) for theme-consistent colors. Always verify that text remains readable over patterned backgrounds by testing in both light and dark modes.
Accessibility
Keyboard Navigation
- Pattern overlays are purely decorative and do not receive focus
pointer-events: noneis applied by default, so overlays never intercept Tab navigation or clicks- Interactive content placed above patterns (
z-10) remains fully keyboard accessible
Screen Reader Support
aria-hidden="true"is set by default on the overlay element, hiding it from assistive technology- Patterns carry no semantic meaning and should never convey information that is not available through other means
- Screen readers will skip the overlay entirely and read only the content above it
Focus Management
Pattern overlays do not affect focus management. The overlay is positioned at z-0 and content at z-10, ensuring focus rings on interactive elements remain visible and unobscured. No focus trapping or redirection occurs.
Motion & Visual Sensitivity
Patterns are static CSS backgrounds with no animation. The opacity transition (0.3s ease) is the only motion applied and is minimal. Users with visual sensitivities benefit from the low default opacity (0.1) which ensures patterns are subtle. Consider providing a way for users to disable patterns entirely for maximum accessibility.
ARIA Attributes
{/* Pattern overlays are decorative — always use aria-hidden */}
<div className="relative overflow-hidden">
<PatternOverlay
pattern="dots"
opacity={0.15}
aria-hidden="true" {/* Set by default */}
/>
<div className="relative z-10">
<p>Accessible content here</p>
</div>
</div>
{/* PatternBackground handles this automatically */}
<PatternBackground pattern="grid" className="p-6">
<p>Content is automatically wrapped with correct z-index</p>
</PatternBackground>Related Components
Aspect Ratio
Constrain content to a specific aspect ratio, useful for patterned media containers.
Card
Content container that pairs well with pattern overlays for visual depth.
Separator
Visual divider for separating content sections as an alternative to pattern-based differentiation.
Empty
Empty state placeholder that can be enhanced with pattern backgrounds for visual interest.
API Reference
The PatternOverlay component accepts the following props in addition to standard div attributes.
PatternOverlay
| Prop | Type | Default | Description |
|---|---|---|---|
| pattern | "dots" | "grid" | "lines" | "crosshatch" | "checkered" | "checkered-odd" | "plus" | "isometric" | "circles" | "custom" | "none" | "dots" | The pattern type to display as a background overlay. |
| scale | number | 1 | Scale multiplier for the pattern size. Values below 1 create denser patterns, above 1 create more spacious patterns. |
| opacity | number | 0.1 | Opacity of the pattern overlay, from 0 (invisible) to 1 (fully opaque). Recommended range is 0.05 to 0.3. |
| color | string | "currentColor" | CSS color value for the pattern. Supports CSS custom properties like var(--primary). |
| className | string | — | Additional CSS classes to apply to the overlay element. |
PatternBackground
A convenience wrapper that automatically handles relative positioning, overflow clipping, and z-index stacking.
| Prop | Type | Default | Description |
|---|---|---|---|
| pattern | "dots" | "grid" | "lines" | "crosshatch" | "checkered" | "checkered-odd" | "plus" | "isometric" | "circles" | "custom" | "none" | "dots" | The pattern type to display as a background overlay. |
| scale | number | 1 | Scale multiplier for the pattern size. |
| opacity | number | 0.1 | Opacity of the pattern overlay, from 0 to 1. |
| color | string | "currentColor" | CSS color value for the pattern. |
| patternClassName | string | — | Additional CSS classes applied to the inner PatternOverlay element. |
| className | string | — | CSS classes for the outer container wrapper. |
| children | React.ReactNode | — | Content rendered above the pattern overlay with automatic z-index stacking. |