Loading workspace environment...
Build enterprise-grade web experiences with WCAG 2.2 AA accessibility standards, ARIA roles, CSS Custom Properties design tokens, and Core Web Vitals optimization.
:root { --primary-color: #2563eb; --radius: 8px; }CSS Custom Properties (design tokens) at root level.role="dialog" aria-modal="true" aria-labelledby="modal-title"Accessible modal dialog attributes.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accessible Modal Dialog</title>
<style>
:root {
--bg: #ffffff;
--text: #0f172a;
--accent: #2563eb;
--overlay: rgba(15, 23, 42, 0.6);
}
body { font-family: system-ui, sans-serif; padding: 2rem; background: #f8fafc; color: var(--text); }
.backdrop { position: fixed; inset: 0; background: var(--overlay); display: none; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
.backdrop.open { display: flex; }
.dialog { background: var(--bg); border-radius: 12px; padding: 2rem; max-width: 440px; width: 90%; box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1); }
button { background: var(--accent); color: white; border: none; padding: 0.625rem 1.25rem; border-radius: 6px; font-weight: 600; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
</style>
</head>
<body>
<button id="open-btn" aria-haspopup="dialog">Open Confirmation Dialog</button>
<div id="modal-backdrop" class="backdrop" role="dialog" aria-modal="true" aria-labelledby="dialog-title">
<div class="dialog">
<h2 id="dialog-title">Confirm Workspace Reset</h2>
<p>Are you sure you want to reset the current editor file? All unsaved edits will be cleared.</p>
<div style="display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem;">
<button id="close-btn" style="background: #e2e8f0; color: #334155;">Cancel</button>
<button id="confirm-btn" style="background: #ef4444;">Reset</button>
</div>
</div>
</div>
<script>
const openBtn = document.getElementById('open-btn');
const backdrop = document.getElementById('modal-backdrop');
const closeBtn = document.getElementById('close-btn');
function openModal() {
backdrop.classList.add('open');
closeBtn.focus();
}
function closeModal() {
backdrop.classList.remove('open');
openBtn.focus();
}
openBtn.addEventListener('click', openModal);
closeBtn.addEventListener('click', closeModal);
window.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && backdrop.classList.contains('open')) {
closeModal();
}
});
</script>
</body>
</html>Renders an accessible modal dialog with focus management and Escape key closing.button:focus { outline: none; } /* Removes focus indicators for keyboard users */button:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }Architectural Explanation: Never remove focus outlines globally. Use `:focus-visible` so keyboard navigators see clear indicators without cluttering mouse clicks.
Build a light/dark theme switch button that toggles `data-theme="dark"` on the document root element, updating CSS custom properties smoothly.