HTML

Search Form with Accessible Label

admin by @admin ADMIN
Jun 19, 2026
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
A search input usually has a visible-only icon — but screen readers need a real label. Pair a visually-hidden `<label>` with the icon, OR use `aria-label` on the input.
HTML
Raw
<form role="search" action="/search">
    <label for="site-search" class="visually-hidden">Search</label>
    <input
        type="search"
        id="site-search"
        name="q"
        placeholder="Search…"
        autocomplete="off"
        autocapitalize="off"
        spellcheck="false"
        required>
    <button type="submit" aria-label="Submit search">
        <svg width="16" height="16" viewBox="0 0 24 24" aria-hidden="true">
            <path d="M21 21l-4.35-4.35M11 19a8 8 0 1 1 0-16 8 8 0 0 1 0 16z"
                  stroke="currentColor" stroke-width="2" fill="none"/>
        </svg>
    </button>
</form>

<style>
.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
</style>
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.