|$ curl https://forge-ai.dev/api/markdown?path=docs/components/modals
$cat docs/modals.md
updated Recently·14 min read·published

Modals

CSSHTMLUIAdvanced
Modal Components

Modal dialogs focus user attention on a specific task or message. These examples use clean CSS overlays with backdrop blur, smooth entrance animations, and accessible markup — all without any JavaScript framework.

Dialog Modal

A confirmation dialog with backdrop overlay, centered layout, and action buttons. The overlay prevents interaction with the page behind it.

confirmation-dialog
Live
untitled.html
HTML
1<div class="modal-demo">
2 <button class="open-btn">
3 Open Modal
4 </button>
5 <div class="modal-wrapper" id="demo-modal">
6 <div class="modal-backdrop">
7 </div>
8 <div class="modal" role="dialog" aria-modal="true" aria-labelledby="modal-title">
9 <div class="modal-header">
10 <h3 id="modal-title" class="modal-title">
11 Confirm Action
12 </h3>
13 <button class="modal-close" aria-label="Close">
14
15 </button>
16 </div>
17 <p class="modal-desc">
18 Are you sure you want to delete this item? This action cannot be undone. All associated data will be permanently removed.
19 </p>
20 <div class="modal-footer">
21 <button class="btn btn-secondary">
22 Cancel
23 </button>
24 <button class="btn btn-danger">
25 Delete
26 </button>
27 </div>
28 </div>
29 </div>
30</div>
preview
Slide-Out Panel

A slide-out panel from the right side — useful for detail views, settings, and navigation drawers. Uses CSS transform for smooth animation.

slide-panel
Live
untitled.html
HTML
1<div class="panel-demo">
2 <div class="panel-backdrop">
3 </div>
4 <div class="panel">
5 <div class="panel-header">
6 <h3 class="panel-title">
7 Settings
8 </h3>
9 <button class="panel-close" aria-label="Close panel">
10
11 </button>
12 </div>
13 <div class="panel-body">
14 <p>
15 Notification preferences, account settings, and application configuration options are displayed in this slide-out panel.
16 </p>
17 <p>
18 Slide-out panels are ideal for secondary content that doesn't need a full page navigation — keeping the user's context intact.
19 </p>
20 </div>
21 </div>
22</div>
preview
HTML Structure

The modal follows a semantic structure: backdrop overlay, dialog container with role="dialog", header with title and close button, content area, and footer with actions. Always use aria-modal="true" and aria-labelledby to connect the title.

modal-structure.html
HTML
1<div class="modal-backdrop"><!-- background overlay --></div>
2<div class="modal" role="dialog" aria-modal="true"
3 aria-labelledby="dialog-title">
4 <div class="modal-header">
5 <h3 id="dialog-title" class="modal-title">
6 Confirm Action
7 </h3>
8 <button class="modal-close" aria-label="Close">✕</button>
9 </div>
10 <p class="modal-desc">
11 Are you sure you want to proceed?
12 </p>
13 <div class="modal-footer">
14 <button class="btn">Cancel</button>
15 <button class="btn btn-primary">Confirm</button>
16 </div>
17</div>
Best Practices
  • Use role="dialog" and aria-modal="true" for screen reader identification.
  • Traps focus inside the modal when open — Tab should cycle through modal elements only.
  • Close on Escape key and backdrop click (light-dismiss) for user convenience.
  • Avoid stacking multiple modals — use a queue or replace the current one.
  • Animate entrance with opacity and transform for smooth UX, but keep it brief (200-300ms).