The overlay component creates a full-page overlay layer that sits on top of the main content. It's commonly used as a backdrop for modals, dialogs, and other overlaid content to focus user attention and prevent interaction with underlying elements.
✅ Use overlay when:
- Creating modal dialogs that require user focus
- Building custom popups or lightboxes
- Implementing loading states that block interaction
- Creating photo galleries or media viewers
- Building custom dropdown menus or megamenus
❌ Don't use overlay for:
- Simple tooltips (use the tooltip component)
- Inline notifications (use callout or snackbar)
- Page-level loading indicators (consider a dedicated loading component)
The overlay is hidden by default. Set the open property to true to display it. Click the overlay to close it in this example.
Overlay Content
Click anywhere to close
Use CSS custom properties to customize the overlay's appearance. The --dds-overlay-background property controls the background color and opacity.
Dark Overlay (rgba(0, 0, 0, 0.8))
Blue Overlay (rgba(0, 100, 200, 0.5))
Light Overlay (rgba(255, 255, 255, 0.9))
Control the overlay's animation with transition duration and timing function properties.
Slow Transition
Watch the 2-second fade animation
Bounce Effect
Custom cubic-bezier timing
Multiple overlays can be stacked using different z-index values. This is useful for nested modals or complex UI patterns.
Layer 1 (Red)
Layer 2 (Green)
Layer 3 (Blue)
Combining overlay with other components to create a centered modal dialog.
Using overlay to create a simple image lightbox viewer.
Creating a full-page loading indicator with overlay.
The overlay component provides extensive customization options through CSS custom properties and parts.
Gradient Overlay
Custom background with smooth transitions
Use the CSS ::part() selector to apply advanced styling to the overlay element. Try editing the CSS below:
- Focus management: When overlay opens, focus should move to overlay content
- Keyboard support: ESC key should close the overlay (implement in parent component)
- ARIA attributes: The overlay automatically sets
aria-hiddenbased on open state - Screen reader announcements: Announce when overlay opens/closes
- Ensure sufficient color contrast for overlay content
- Provide a clear way to close the overlay
- Consider users with motion sensitivity when using transitions
- Test with keyboard-only navigation
import { DapDSOverlay } from 'dap-design-system'
import { DapDSOverlayReact } from 'dap-design-system/react'
For optimal bundle sizes, use the tree-shakeable import syntax:
import { DapDSOverlay } from 'dap-design-system/components'
| Property | Type | Default | Description |
|---|---|---|---|
open | boolean | false | The open state of the overlay. |
| Name | Description |
|---|---|
(default) | The content of the overlay. |
| Event Name | Description | Type |
|---|---|---|
dds-before-open | Fires before the overlay opens. | CustomEvent |
dds-opened | Fires after the overlay opens. | CustomEvent |
dds-before-close | Fires before the overlay closes. | CustomEvent |
dds-closed | Fires after the overlay closes. | CustomEvent |
| Part Name | Description |
|---|---|
base | The overlay element |
You can style CSS parts using the ::part() pseudo-element selector:
/* Target a specific part */
.my-custom-dap-ds-overlay::part(base) {
/* Your custom styles */
}
Example usage:
<dap-ds-overlay class="my-custom-dap-ds-overlay">
Overlay
</dap-ds-overlay>
.my-custom-dap-ds-overlay::part(base) {
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.
| Property Name | Description |
|---|---|
--dds-overlay-z-index | Controls the z-index of the overlay (default: 1) |
--dds-overlay-background | Controls the background of the overlay (default: var(--dds-black-10)) |
--dds-overlay-opacity-closed | Controls the opacity when overlay is closed (default: 0) |
--dds-overlay-opacity-open | Controls the opacity when overlay is open (default: 1) |
--dds-overlay-transition-duration | Controls the transition duration (default: var(--dds-transition-fast)) |
--dds-overlay-transition-timing | Controls the transition timing function (default: var(--dds-easing-ease-in-out)) |
CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:
Method 1: Inline styles (Quick customization)
<dap-ds-overlay
style="--dds-overlay-z-index: value; --dds-overlay-background: value;">
Overlay
</dap-ds-overlay>
Method 2: CSS classes (Reusable styles)
.my-custom-dap-ds-overlay {
--dds-overlay-z-index: value;
--dds-overlay-background: value;
--dds-overlay-opacity-closed: value;
}
<dap-ds-overlay class="my-custom-dap-ds-overlay">
Overlay
</dap-ds-overlay>
Method 3: Global theme customization
/* Apply to all instances */
dap-ds-overlay {
--dds-overlay-z-index: value;
--dds-overlay-background: value;
}
CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.