overlay

Modal Dialog

An accessible modal with focus trap and backdrop click-to-close.

modal dialog accessibility | Claude 4.6 Opus

Prompt

# Role
You are a Senior Frontend Developer specializing in accessible modal patterns, focus management, and overlay interactions.

# Objective
Build an accessible modal dialog component with focus trapping, backdrop click-to-close, escape key dismissal, and smooth entrance/exit animations — styled for dark mode.

# Instructions
1. Create the modal structure:
   - Modal container with `role="dialog"` and `aria-modal="true"`
   - `aria-labelledby` pointing to the modal title
   - Optional `aria-describedby` for descriptive text
2. Build the modal content:
   - Header with title and close button (×)
   - Body with scrollable content area
   - Optional footer with action buttons (Cancel / Confirm)
3. Implement overlay (backdrop):
   - Semi-transparent dark backdrop covering the viewport
   - Click on backdrop closes the modal
   - Body scroll is locked when modal is open
4. Add focus management:
   - Focus moves to the modal when opened (usually the close button or first focusable element)
   - Focus is trapped within the modal while open
   - Focus returns to the trigger element when closed
5. Handle escape key:
   - Pressing Escape closes the modal
6. Implement animations:
   - Entrance: backdrop fades in, modal scales up with fade (200ms)
   - Exit: reverse animation (150ms)

# Constraints
- Proper ARIA: `role="dialog"`, `aria-modal="true"`, `aria-labelledby`, `aria-hidden` on body content
- Focus trap using `Tab` key cycling through focusable elements
- Body scroll lock when modal is open
- Tailwind CSS only — no custom CSS
- Include a demo trigger button to open the modal

# Output Format
- Single HTML file using Tailwind CSS CDN
- Include focusable elements inside modal (input, buttons)
- Well-commented code with clear sections for structure, styles, and logic

Notes

Prompt

Role

You are a Senior Frontend Developer specializing in accessible modal patterns, focus management, and overlay interactions.

Objective

Build an accessible modal dialog component with focus trapping, backdrop click-to-close, escape key dismissal, and smooth entrance/exit animations — styled for dark mode.

Instructions

  1. Create the modal structure:
    • Modal container with role="dialog" and aria-modal="true"
    • aria-labelledby pointing to the modal title
    • Optional aria-describedby for descriptive text
  2. Build the modal content:
    • Header with title and close button (×)
    • Body with scrollable content area
    • Optional footer with action buttons (Cancel / Confirm)
  3. Implement overlay (backdrop):
    • Semi-transparent dark backdrop covering the viewport
    • Click on backdrop closes the modal
    • Body scroll is locked when modal is open
  4. Add focus management:
    • Focus moves to the modal when opened (usually the close button or first focusable element)
    • Focus is trapped within the modal while open
    • Focus returns to the trigger element when closed
  5. Handle escape key:
    • Pressing Escape closes the modal
  6. Implement animations:
    • Entrance: backdrop fades in, modal scales up with fade (200ms)
    • Exit: reverse animation (150ms)

Constraints

  • Proper ARIA: role="dialog", aria-modal="true", aria-labelledby, aria-hidden on body content
  • Focus trap using Tab key cycling through focusable elements
  • Body scroll lock when modal is open
  • Tailwind CSS only — no custom CSS
  • Include a demo trigger button to open the modal

Output Format

  • Single HTML file using Tailwind CSS CDN
  • Include focusable elements inside modal (input, buttons)
  • Well-commented code with clear sections for structure, styles, and logic

Notes

  • Focus trapping is essential — users should not be able to tab outside the modal while it’s open.
  • Body scroll lock prevents the background from scrolling while the modal is visible.
  • The aria-modal="true" attribute tells assistive technology to ignore the background content.

Related Prompts

View prompt details

Confirmation Dialog

Accessible modal for destructive action confirmation.

# Role You are a Senior Frontend Developer specializing in accessible UI components and interaction design patterns. # Objective Create a reusable confirmation dialog component for destructive actions that is fully accessible, keyboard-navigable, and visually clear about the consequences of the action. # Instructions 1. Build the dialog using the native `<dialog>` HTML element: - Centered on screen with a backdrop blur overlay - Smooth entrance animation: fade-in combined with subtle scale-up (0.95 → 1.0) 2. Structure the dialog content as follows: - Top: warning triangle icon (SVG) in amber/yellow - Title: bold, clear heading describing the action (e.g., "Delete this project?") - Description: secondary text explaining consequences - Action context: display the name/identifier of the item being affected 3. Add two action buttons at the bottom: - Cancel button (secondary/outline style) — closes the dialog with no action - Confirm button (danger red, filled) — executes the destructive action - Confirm button should be visually dominant but NOT auto-focused (prevent accidental confirmation) 4. Implement keyboard and focus management: - Focus trap: Tab key cycles only within the dialog - Escape key closes the dialog - Set `inert` attribute on background content when dialog is open 5. Add exit animation: fade-out with scale-down on close # Constraints - Use the native `<dialog>` element — do not build a custom modal from `<div>` - No external dependencies — vanilla HTML, CSS, and JavaScript only - Must pass WCAG 2.1 AA accessibility requirements - Auto-focus the Cancel button on open (safe default) - Do not allow background scroll when dialog is open # Output Format - Single HTML file with embedded `<style>` and `<script>` blocks - Include a demo trigger button to open the dialog - Clean, commented code with clear separation of structure, style, and behavior

modal dialog confirmation +1
Gemini 3.1 Pro
View prompt details

Command Palette

VS Code / Linear-style ⌘K command palette with fuzzy search.

# Role You are a Senior Frontend Engineer and Keyboard-First UX Specialist with deep expertise in command-palette interfaces, fuzzy search algorithms, and developer-focused productivity tools. # Objective Build a VS Code / Linear-style command palette triggered by `⌘K` (or `Ctrl+K`), featuring fuzzy search filtering, grouped results, keyboard navigation, and smooth enter/exit animations — optimized for power users. # Instructions 1. Create the command palette overlay: - Centered modal with a search input at the top - Semi-transparent backdrop with blur effect (`backdrop-filter: blur(8px)`) - Smooth scale + fade entrance animation (200ms ease-out) - Close on `Escape`, backdrop click, or `⌘K` toggle 2. Build the search input: - Auto-focused on open with a search icon and placeholder: "Type a command..." - Real-time filtering as the user types - Clear button (×) when input has text 3. Implement the results list: - Group results by category with section headers (e.g., "Pages", "Actions", "Settings") - Each result item shows: icon (emoji or SVG), label, optional description, and keyboard shortcut hint (right-aligned `<kbd>`) - Highlight matching characters in bold within result labels 4. Add full keyboard navigation: - `↑` / `↓` arrows to move selection highlight - `Enter` to execute the selected command - Active item highlighted with accent background - Scroll active item into view automatically 5. Style in dark mode: - Dark modal background (`#1a1a2e` or similar) with subtle border - Muted section headers, bright result labels - `<kbd>` shortcut badges styled as pill-shaped tags - Max-height with scrollable results area # Constraints - Vanilla JavaScript — no frameworks or libraries - Fuzzy matching: filter results where input characters appear in order (not necessarily contiguous) - Must be keyboard-accessible end to end — no mouse required - Limit visible results to 8 items before scrolling - Trap focus inside the palette while open - Include at least 12 sample commands across 3 categories - Semantic HTML with `role="dialog"` and `aria-modal="true"` # Output Format - Single HTML file with embedded `<style>` and `<script>` blocks - Include realistic sample commands (developer tool or productivity app theme) - Well-commented code with clear separation: markup, styles, search logic, keyboard handling

command-palette search keyboard +1
Claude 4.6 Opus
View prompt details

Elegant Login Modal

A slick, centered login modal with social auth.

# Role You are a Senior Security Architect and Full-Stack Engineer specializing in authentication interfaces, secure form design, and polished user experience. # Objective Build an elegant, accessible login modal with email/password authentication, social login options, and a polished dark-mode design suitable for SaaS applications. # Instructions 1. Create a centered modal overlay: - Backdrop with blur effect and dark overlay - Modal card with rounded corners, subtle border, and shadow - Smooth entrance animation (fade + scale) 2. Build the login form: - Email input with icon prefix and validation - Password input with icon prefix and show/hide toggle - "Remember me" checkbox - "Forgot password?" link aligned right - Submit button: full-width, accent color, hover effect 3. Add social authentication options: - Divider with "or continue with" text - Social login buttons: Google, GitHub, Apple (icon + label) - Styled as outline buttons with hover fill effect 4. Include a sign-up prompt: - "Don't have an account? Sign up" text below the form - "Sign up" as an accent-colored link 5. Implement interaction details: - Close button (×) in top-right corner - Close on Escape key or backdrop click - Focus trap within the modal - Auto-focus on email input when modal opens # Constraints - Use Tailwind CSS for all styling — no custom CSS - Semantic HTML with proper `<form>`, `<label>`, and ARIA attributes - Do not include actual authentication logic — UI only - Must be fully keyboard-navigable (Tab, Escape, Enter) - Modal max-width: 420px, centered on all screen sizes - Dark mode only # Output Format - Single HTML file using Tailwind CSS CDN - Include a trigger button to open the modal for demonstration - Well-structured, accessible markup with inline comments - Use placeholder content ready for real integration

modal auth ui
Claude 4.6 Opus