Full answer
Sometimes the design shows only an icon, but a screen reader user still needs a text name. The answer is a "visually hidden" class. It shrinks the element to a single pixel, clips it and removes it from the flow, but keeps it in the accessibility tree.
display: none and visibility: hidden do not work for this, because they also hide the text from assistive technology. Moving text far off screen with left: -9999px also works, but it can make the page scroll in right-to-left layouts and can confuse focus tracking.
The button looks like a magnifying glass only. A screen reader announces "Search, button", and the browser's accessibility tree gives the button the name Search. The label is 1px by 1px on screen. The skip link follows the same idea but appears when a keyboard user tabs to it, which is the pattern used so keyboard users can jump past a long menu.
When the text is only for the accessible name, a simpler option is aria-label="Search" on the button. A visually hidden span is better if the text must be translated by the page, or must show in a text-only view.
<style>
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
border: 0;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}
.icon-button { width: 40px; height: 40px; border: 1px solid #333; background: #fff; }
.skip-link:not(:focus):not(:active) {
position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.skip-link:focus { position: static; display: inline-block; padding: 8px; background: gold; }
</style>
<a class="skip-link" href="#main" id="skip">Skip to main content</a>
<button class="icon-button" id="btn" type="button">
<svg width="20" height="20" viewBox="0 0 20 20" aria-hidden="true"><circle cx="8" cy="8" r="6" fill="none" stroke="black" stroke-width="2"/><line x1="13" y1="13" x2="19" y2="19" stroke="black" stroke-width="2"/></svg>
<span class="visually-hidden" id="label">Search</span>
</button>
<main id="main" tabindex="-1">Main content</main>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- Use position: absolute, 1px size, overflow: hidden, clip-path and white-space: nowrap on the text.
- display: none and visibility: hidden hide text from screen readers too.
- Icon buttons need an accessible name; hidden text or aria-label provides it.
- A skip link can use the same technique and become visible on focus.
- Decorative icons should get aria-hidden so they are not announced.
Common mistakes
- hiding the text with display: none and then finding that the button has no name for screen readers.
- forgetting white-space: nowrap. The 1px box can make the text wrap word by word and some screen readers then read it in pieces.
Follow-ups
- when would you use aria-label rather than hidden text?
- When is aria-label a better choice than a hidden span?
- How would you make a skip link that shows only when focused?
Tips
- Hide decorative icons from screen readers with aria-hidden="true" so they are not announced twice.
- Keep the class in your base stylesheet under one agreed name, such as visually-hidden or sr-only, so every team member reuses it.
- Test the result with a screen reader or the accessibility tree in DevTools, not only by looking at the page.