Keyboard Navigation

키보드 내비게이션

The principle that every function must be reachable using only Tab, arrow keys, Enter, and Space — no mouse required.

···
html
<div class="stage">
  <div class="toolbar">
    <button class="it i1"></button>
    <button class="it i2"></button>
    <button class="it i3"></button>
    <button class="it i4"></button>
  </div>
  <div class="key" id="key"></div>
</div>
css
.stage{position:relative;width:92%;height:80%;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14%}
.toolbar{display:flex;gap:6%;padding:6%;border-radius:14px;border:1px solid var(--line);background:var(--surface)}
.it{width:15vmin;max-width:56px;aspect-ratio:1;border-radius:9px;border:1px solid var(--line);background:var(--bg)}
.ring{box-shadow:0 0 0 3px var(--accent)}
.press{background:var(--accent-3) !important}
.key{font:700 13px/1 ui-monospace,monospace;color:var(--muted);min-height:16px}
js
const items = [document.querySelector('.i1'), document.querySelector('.i2'), document.querySelector('.i3'), document.querySelector('.i4')];
const key = document.getElementById('key');
const steps = [
  { i: 0, k: '⇥ Tab' },
  { i: 1, k: '→' },
  { i: 2, k: '→' },
  { i: 2, k: '↵ Enter', press: true },
  { i: 3, k: '→' },
];
let s = 0;
function apply(step) {
  items.forEach(function (el) { el.classList.remove('ring'); });
  items[step.i].classList.add('ring');
  key.textContent = step.k;
  if (step.press) {
    items[step.i].classList.add('press');
    setTimeout(function () { items[step.i].classList.remove('press'); }, 260);
  }
}
function tick() {
  apply(steps[s % steps.length]);
  s++;
}
tick();
setInterval(tick, 750);

Plenty of users navigate the web with nothing but a keyboard — tremor, a temporary injury, a switch device, or simply no mouse at hand. A custom component built to only react to hover or click (a hand-rolled dropdown, a div wearing a button's clothes) is a solid wall for them.

The baseline is simple: Tab/Shift+Tab moves between elements, Enter or Space activates one, and arrow keys move within a list or menu. Real native elements — `<button>`, `<a>`, `<input>` — already ship this behaviour built into the browser, so there's nothing to reimplement.

The demo moves through a 4-item toolbar with Tab, arrow keys, and Enter, with key badges popping up alongside each move.

When to use

Every time you build a new component, try using it start to finish with nothing but Tab. Wherever you get stuck is exactly what needs fixing.