HTML/CSS components Free template

Responsive navbar and dialog

An accessible navigation bar that turns into a menu on phones, plus a modal dialog built on the native dialog element.

Live preview

The preview runs in a sandbox: it cannot reach your account, cookies or the network.

About this template

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.

navbarmenudialogmodalaccessibility

Look under the hood

Included source files

1,466 bytes
<!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>

Update history

  1. 1.0.0

    First release.