--- url: "https://web.dev/articles/labels-and-text-alternatives" titulek: "Labels and text alternatives | web.dev" h1: "Labels and text alternatives Stay organized with collections Save and categorize content based on your preferences." popis: "For a screen reader to present a spoken UI to the user, meaningful elements must have proper labels or text alternatives." jazyk: "en" kanonicka: "https://web.dev/articles/labels-and-text-alternatives" drobecky: ["web.dev", "Resources"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-13 23:13:02" znaku: 7847 slov: 1233 kodovani: "iso-8859-2" sha256: "71cbf0de916709e8751b80c173b4877532d8b2b0bb1df09f995efd5eccdeefc0" --- Labels and text alternatives Stay organized with collections Save and categorize content based on your preferences. Rob Dodson In order for a screen reader to present a spoken UI to the user, meaningful elements must have proper labels or text alternatives. A label or text alternative gives an element its accessible **name**, one of the key properties to [express element semantics in the accessibility tree](/articles/semantics-and-screen-readers#semantic_properties_tree). When an element's name is combined with the element's **role**, it gives the user context so they can understand what type of element they're interacting with and how it is represented on the page. If a name is not present, then a screen reader only announces the element's role. Imagine trying to navigate a page and hearing, "button," "checkbox," "image" without any additional context. This is why labeling and text alternatives are crucial to a good, accessible experience. Inspect an element's name You can check an element's accessible name in Chrome's DevTools: Right-click on an element and choose **Inspect**. This opens the DevTools Elements panel. In the Elements panel, look for the **Accessibility** pane. It may be hidden behind a `»` symbol. In the **Computed Properties** drop-down, look for the **Name** property. DevTools accessibility pane showing the computed name for a button. Whether you're looking at an `img` with `alt` text or an `input` with a `label`, all of these scenarios result in the same outcome: giving an element its accessible name. Check for missing names There are different ways to add an accessible name to an element, depending on its type. The following table lists the most common element types that need accessible names and links to explanations for how to add them. Element type How to add a name HTML document Label documents and frames `` or `` While an `iframe`'s contents may contain their own internal `title` element, a screen reader usually stops at the frame boundary and announces the element's role—"frame"—and its accessible name, provided by the `title` attribute. This lets the user decide if they want to enter the frame or bypass it. Include text alternatives for images and objects An `img` should always be accompanied by an [`alt`](https://developer.mozilla.org/docs/Web/HTML/Element/img#Attributes) attribute to give the image its accessible name. If the image fails to load, the `alt` text is used as a placeholder so users have a sense of what the image was trying to convey. Writing good `alt` text is a bit of an art, but there are a couple of guidelines you can follow: Determine if the image provides content that would otherwise be difficult to attain from reading the surrounding text. If so, convey the content as succinctly as possible. If the image acts as decoration and does not provide any useful content, you can give it an empty `alt=""` attribute to remove it from the accessibility tree. Images as links and inputs An image wrapped in a link should use the `img`'s `alt` attribute to describe where the user will navigate to if they click the link: ` Google's wikipedia page ` Similarly, if an `` element is used to create an image button, it should contain `alt` text that describes the action that occurs when the user clicks on the button: `
` Embedded objects `` elements, which are typically used for embeds like Flash, PDFs, or ActiveX, should also contain alternative text. Similar to images, this text is displayed if the element fails to render. The alternative text goes inside the `object` element as regular text, like "Annual report" below: ` Annual report. ` Label buttons and links Buttons and links are often crucial to the experience of a site, and it is important that both have good accessible names. Buttons A `button` element always attempts to compute its accessible name using its text content. For buttons that are not part of a `form`, writing a clear action as the text content may be all you need to create a good accessible name. `` One common exception to this rule is icon buttons. An icon button may use an image or an icon font to provide the text content for the button. For example, the buttons used in a WYSIWYG (What You See Is What You Get) editor to format text are typically just graphic symbols: When working with icon buttons, it can be helpful to give them an explicit accessible name using the `aria-label` attribute. `aria-label` overrides any text content inside the button, letting you clearly describe the action to anyone using a screen reader. `` Links Similar to buttons, links primarily get their accessible name from their text content. A nice trick when creating a link is to put the most meaningful piece of text into the link itself, rather than filler words like "Here" or "Read More." Not descriptive enough Check out our guide to web performance here. Useful content! Check out our guide to web performance. This is especially helpful for screen readers that offer shortcuts to list all of the links on the page. If links are full of repetitive filler text, these shortcuts become much less useful: Example of VoiceOver, a screen reader for macOS, showing the navigate by links menu. Label form elements There are two ways to associate a label with a form element such as a checkbox. Either of the methods causes the label text to also become a click target for the checkbox, which is also helpful for mouse or touchscreen users. To associate a label with an element, either: Place the input element inside of a label element `` Or use the label's `for` attribute and refer to the element's `id` ` ` When the checkbox has been labeled correctly, the screen reader can report that the element has a role of checkbox, is in a checked state, and is named "Receive promotional offers?" like in this VoiceOver example: Except as otherwise noted, the content of this page is licensed under the [Creative Commons Attribution 4.0 License](https://creativecommons.org/licenses/by/4.0/), and code samples are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0). For details, see the [Google Developers Site Policies](https://developers.google.com/site-policies). Java is a registered trademark of Oracle and/or its affiliates. Last updated 2018-11-18 UTC.