Free
View template
Buttons, badges, alerts and cards
A small, copy-paste component set: button styles and sizes, badges, alerts and cards, all driven by CSS variables.
Tools
Company
Blog About us Contact usCreate & learn
PlaygroundAPI TesterTemplatesCreditsGuided projectsChallengesLearnTutorialsHTML/CSS components Free template
An accessible navigation bar that turns into a menu on phones, plus a modal dialog built on the native dialog element.
The preview runs in a sandbox: it cannot reach your account, cookies or the network.
Two interface pieces almost every site needs. The navbar shows links in a row on wide screens and behind a menu button on narrow ones, with aria-expanded kept in sync and the menu closing on Escape. The dialog uses the browser's built-in dialog element, so focus handling, Escape to close and the backdrop come for free; the script only opens it, closes it and returns focus to the button that opened it.
Look under the hood
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Navbar and dialog</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="nav">
<a class="brand" href="#">Brightly</a>
<button type="button" id="toggle" class="toggle" aria-expanded="false" aria-controls="links">Menu</button>
<nav id="links" class="links" aria-label="Main">
<a href="#" aria-current="page">Home</a>
<a href="#">Products</a>
<a href="#">Pricing</a>
<a href="#">Contact</a>
</nav>
</header>
<main>
<h1>Welcome</h1>
<p>Resize the preview to see the menu change. Press the button below to open a dialog.</p>
<button type="button" id="open" class="btn">Subscribe to updates</button>
</main>
<dialog id="dialog" aria-labelledby="dialog-title">
<form method="dialog" id="form">
<h2 id="dialog-title">Subscribe</h2>
<p>Get one short e-mail a month. No spam.</p>
<label for="email">E-mail address</label>
<input id="email" type="email" required autocomplete="email" placeholder="you@example.com">
<p id="message" role="status"></p>
<div class="actions">
<button type="button" id="cancel" class="btn btn-outline">Cancel</button>
<button type="submit" class="btn">Subscribe</button>
</div>
</form>
</dialog>
<script src="app.js"></script>
</body>
</html>
// Navbar menu (phones)
const toggle = document.getElementById('toggle');
const links = document.getElementById('links');
function setMenu(open) {
links.classList.toggle('open', open);
toggle.setAttribute('aria-expanded', String(open));
}
toggle.addEventListener('click', () => setMenu(toggle.getAttribute('aria-expanded') !== 'true'));
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && toggle.getAttribute('aria-expanded') === 'true') {
setMenu(false);
toggle.focus();
}
});
// Dialog: the native element handles focus, Escape and the backdrop.
const dialog = document.getElementById('dialog');
const opener = document.getElementById('open');
const form = document.getElementById('form');
const message = document.getElementById('message');
opener.addEventListener('click', () => {
message.textContent = '';
dialog.showModal();
});
document.getElementById('cancel').addEventListener('click', () => dialog.close());
form.addEventListener('submit', (event) => {
event.preventDefault();
message.textContent = 'Thank you! (This demo does not send anything.)';
setTimeout(() => dialog.close(), 1200);
});
// Focus goes back to the button that opened the dialog (most browsers do this already).
dialog.addEventListener('close', () => opener.focus());
:root { --brand: #c00000; --ink: #141c20; --line: #e3e6e9; }
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, 'Segoe UI', sans-serif; color: var(--ink); line-height: 1.5; }
main { max-width: 40rem; margin: 0 auto; padding: 3rem 1.5rem; }
.nav { position: relative; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; padding: 0.8rem 1.5rem; border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 1.2rem; color: var(--brand); text-decoration: none; }
.links { display: flex; gap: 1.4rem; }
.links a { color: var(--ink); text-decoration: none; padding: 0.3rem 0; border-bottom: 2px solid transparent; }
.links a:hover, .links a[aria-current='page'] { border-color: var(--brand); }
.toggle { display: none; font: inherit; padding: 0.4rem 0.9rem; border: 1px solid var(--line); border-radius: 0.5rem; background: #fff; cursor: pointer; }
@media (max-width: 36rem) {
.toggle { display: block; }
.links { display: none; width: 100%; flex-direction: column; gap: 0; padding-top: 0.6rem; }
.links.open { display: flex; }
.links a { padding: 0.7rem 0; border-bottom: 1px solid var(--line); }
}
.btn { font: inherit; font-weight: 600; padding: 0.6rem 1.2rem; color: #fff; background: var(--brand); border: 2px solid var(--brand); border-radius: 0.6rem; cursor: pointer; }
.btn-outline { background: transparent; color: var(--brand); }
.btn:focus-visible, .toggle:focus-visible { outline: 3px solid #f5b400; outline-offset: 2px; }
dialog { width: min(26rem, calc(100% - 2rem)); padding: 1.5rem; border: 0; border-radius: 1rem; box-shadow: 0 20px 50px rgb(0 0 0 / 0.3); }
dialog::backdrop { background: rgb(20 28 32 / 0.55); }
dialog h2 { margin-top: 0; }
label { display: block; margin-bottom: 0.3rem; font-weight: 600; }
input { width: 100%; padding: 0.6rem 0.8rem; font: inherit; border: 1px solid #b9c0c5; border-radius: 0.5rem; }
.actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; }
#message { min-height: 1.5rem; margin: 0.6rem 0 0; color: #0a6a35; }
First release.