Welcome to Vanilla Breeze
This bell pulls live notifications from /go/notify/messages — the same contract documented at /docs/concepts/service-contracts/. Static articles like this one are the no-JS / no-backend fallback.
This bell pulls live notifications from /go/notify/messages — the same contract documented at /docs/concepts/service-contracts/. Static articles like this one are the no-JS / no-backend fallback.
Automatically focuses an element when the page loads or a dialog opens. Use sparingly — unexpected focus changes can disorient users.
The autofocus attribute automatically moves keyboard focus to an element when the page loads, or when a popover or <dialog> opens. It is a boolean attribute — its presence activates the behavior.
Applies to: <input>, <select>, <textarea>, <button>, and any element with tabindex
| Value | Behavior |
|---|---|
autofocus (present) | Element receives focus automatically when the page loads or its dialog/popover opens |
| (absent) | No automatic focus. The default. |
<!-- Focus the search box on page load --><label for="search">Search</label><input type="search" id="search" autofocus placeholder="Search..." /> <!-- Focus a select menu --><label for="priority">Priority</label><select id="priority" autofocus> <option>Low</option> <option>Medium</option> <option>High</option></select>
Only one per page. If multiple elements have autofocus, the browser focuses the last one in DOM order. This is rarely intentional — use it on exactly one element.
Inside a <dialog>, the autofocus attribute fires when the dialog opens via showModal() or show(), not on page load. This is the recommended way to control initial focus inside modals.
If no element inside the dialog has autofocus, the dialog itself receives focus. For confirmation dialogs, place autofocus on the least-destructive action (typically "Cancel").
<dialog id="confirm-dialog"> <h2>Confirm Deletion</h2> <p>This action cannot be undone.</p> <footer> <button autofocus>Cancel</button> <button class="danger">Delete</button> </footer></dialog> <script>document.getElementById('confirm-dialog').showModal();// The "Cancel" button receives focus when the dialog opens,// not when the page loads.</script>
The same deferred behavior applies to popover elements. The autofocus fires when the popover is shown, giving you control over which element receives initial focus inside the popover.
<button popovertarget="settings-panel">Settings</button> <div id="settings-panel" popover> <h3>Quick Settings</h3> <label for="theme">Theme</label> <select id="theme" autofocus> <option>Light</option> <option>Dark</option> <option>System</option> </select></div>
A login page where the username field is focused on load, letting the user start typing immediately.
<form class="stacked" action="/login" method="post"> <label for="username">Username</label> <input type="text" id="username" autofocus autocomplete="username" /> <label for="password">Password</label> <input type="password" id="password" autocomplete="current-password" /> <button type="submit">Log In</button></form>
preventScroll with element.focus({ preventScroll: true }) in JavaScript if you need focus without scrolling.element.focus() instead.autofocus.