{"id":1648,"date":"2025-07-14T11:14:19","date_gmt":"2025-07-14T11:14:19","guid":{"rendered":"https:\/\/html5accessibility.com\/stuff\/?p=1648"},"modified":"2025-07-14T19:21:21","modified_gmt":"2025-07-14T19:21:21","slug":"a-label-and-a-name-walk-into-a-bar","status":"publish","type":"post","link":"https:\/\/html5accessibility.com\/stuff\/2025\/07\/14\/a-label-and-a-name-walk-into-a-bar\/","title":{"rendered":"a label and a name walk into a bar"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1650 size-full\" src=\"https:\/\/html5accessibility.com\/stuff\/wp-content\/uploads\/2025\/07\/Screenshot-2025-07-13-143809.jpg\" alt=\"Patrick Lauke sitting at a table in a bar in Toronto. He has a smug look on his face, as usual.\" width=\"600\" height=\"437\" srcset=\"https:\/\/html5accessibility.com\/stuff\/wp-content\/uploads\/2025\/07\/Screenshot-2025-07-13-143809.jpg 600w, https:\/\/html5accessibility.com\/stuff\/wp-content\/uploads\/2025\/07\/Screenshot-2025-07-13-143809-300x219.jpg 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>When is a label also an (accessible) name, when is it not and when is it neither?<\/strong><\/p>\n<h2>WCAG definitions:<\/h2>\n<h3><a href=\"https:\/\/www.w3.org\/TR\/WCAG22\/#dfn-labels\">label<\/a><\/h3>\n<blockquote><p><a id=\"ref-for-dfn-text-10\" class=\"internalDFN\" title=\"sequence of characters that can be programmatically determined, where the sequence is expressing something in human language\" href=\"https:\/\/www.w3.org\/TR\/WCAG22\/#dfn-text\" data-link-type=\"dfn\">text<\/a>\u00a0or other component with a\u00a0<a id=\"ref-for-dfn-text-alternative-3\" class=\"internalDFN\" title=\"Text that is programmatically associated with non-text content or referred to from text that is programmatically associated with non-text content. Programmatically associated text is text whose location can be programmatically determined from the non-text content.\" href=\"https:\/\/www.w3.org\/TR\/WCAG22\/#dfn-text-alternative\" data-link-type=\"dfn\">text alternative<\/a>\u00a0that is presented to a user to identify a component within web\u00a0<a id=\"ref-for-dfn-content-3\" class=\"internalDFN\" title=\"information and sensory experience to be communicated to the user by means of a user agent, including code or markup that defines the content's structure, presentation, and interactions\" href=\"https:\/\/www.w3.org\/TR\/WCAG22\/#dfn-content\" data-link-type=\"dfn\">content<\/a><\/p><\/blockquote>\n<p class=\"note\">A <a href=\"https:\/\/html.spec.whatwg.org\/multipage\/input.html#attr-input-placeholder\"><code>placeholder<\/code><\/a> can be an accessible name, but can never be a <a href=\"https:\/\/www.w3.org\/TR\/WCAG22\/#dfn-labels\">label<\/a><\/p>\n<p class=\"note\">A <a href=\"https:\/\/html.spec.whatwg.org\/multipage\/forms.html#the-label-element\"><code>label<\/code> element<\/a> can be a <a href=\"https:\/\/www.w3.org\/TR\/WCAG22\/#dfn-labels\">label<\/a> when it is visible and contains text that identifies a component.<\/p>\n<h3>(accessible) <a href=\"https:\/\/www.w3.org\/TR\/WCAG22\/#dfn-name\">name<\/a><\/h3>\n<blockquote><p>text by which software can identify a component within web content to the user<\/p><\/blockquote>\n<p class=\"note\">A <a href=\"https:\/\/html.spec.whatwg.org\/multipage\/forms.html#the-label-element\"><code>label<\/code> element<\/a> can be a <a href=\"https:\/\/www.w3.org\/TR\/WCAG22\/#dfn-labels\">name<\/a> when it is visible and contains text that is programmatically associated with the component it identifies.<\/p>\n<h2>When is a label also an (accessible) name?<\/h2>\n<p>When it is visible text and the text is programmatically associated with the control it labels.<\/p>\n<h3>Example code<\/h3>\n<p><code>label<\/code> element is visible, contains label text and a HTML <a href=\"https:\/\/html.spec.whatwg.org\/multipage\/forms.html#category-label\">labelable element<\/a><\/p>\n<pre>&lt;label&gt;First name\r\n&lt;input type=\"text\" placeholder=\"Our Dave\"&gt;\r\n&lt;\/label&gt;<\/pre>\n<ul>\n<li>label = <em>First name<\/em><\/li>\n<li>accessible name = <em>First name<\/em><\/li>\n<\/ul>\n<h3>Example code<\/h3>\n<p><code>label<\/code> element is visible, and is <em>explicitly<\/em> (<code>for\/id<\/code>) associated with a HTML <a href=\"https:\/\/html.spec.whatwg.org\/multipage\/forms.html#category-label\">labelable element<\/a><\/p>\n<pre>&lt;label for=\"fname\"&gt;First name&lt;\/label&gt;\r\n&lt;input id=\"fname\" type=\"text\" placeholder=\"Herbie\"&gt;<\/pre>\n<ul>\n<li>label = <em>First name<\/em><\/li>\n<li>accessible name = <em>First name<\/em><\/li>\n<\/ul>\n<h3>Example code<\/h3>\n<p>Element containing label text is visible, and is <em>explicitly<\/em> (<code>aria-labelledby<\/code>) associated with an HTML element<\/p>\n<pre>&lt;label id=\"fname\"&gt;First name&lt;\/label&gt;\r\n&lt;input aria-labelledby=\"fname\" type=\"text\" placeholder=\"Herbie\"&gt;\r\n\r\n&lt;span id=\"fname1\"&gt;First name&lt;\/span&gt; \r\n&lt;input aria-labelledby=\"fname1\" type=\"text\" placeholder=\"Herbie\"&gt;<\/pre>\n<ul>\n<li>label = <em>First name<\/em><\/li>\n<li>accessible name = <em>First name<\/em><\/li>\n<\/ul>\n<h3>Example code<\/h3>\n<p><code>label<\/code> element containing visible label text and a custom control which builds on a HTML <a href=\"https:\/\/html.spec.whatwg.org\/multipage\/forms.html#category-label\">labelable element<\/a><\/p>\n<pre>&lt;label&gt;First name\r\n&lt;input type=\"combobox\" placeholder=\"Jonny\"&gt;\r\n&lt;\/label&gt;<\/pre>\n<ul>\n<li>label = <em>First name<\/em><\/li>\n<li>accessible name = <em>First name<\/em><\/li>\n<\/ul>\n<h2>When is it not?<\/h2>\n<p>When it is not visible, when it is not programmatically, or only visible before data input<\/p>\n<h3>Example code<\/h3>\n<p>label text not programmatically associated<\/p>\n<pre>&lt;label&gt;First name&lt;\/label&gt;\r\n&lt;input type=\"text\" placeholder=\"Jonny\"&gt;<\/pre>\n<ul>\n<li>label = <em>First name<\/em><\/li>\n<li>accessible name = Jonny<\/li>\n<\/ul>\n<h3>Example code<\/h3>\n<p>label text not programmatically associated<\/p>\n<pre>&lt;span&gt;First name&lt;\/span&gt;\r\n&lt;input type=\"text\" placeholder=\"Pattypoo\"&gt;<\/pre>\n<ul>\n<li>label = <em>First name<\/em><\/li>\n<li>accessible name = <em>Pattypoo<\/em><\/li>\n<\/ul>\n<h3>Example code<\/h3>\n<p>When the label element is <code>display:none<\/code> and <code>aria-labelledby<\/code> is used to associate the hidden label text with a control<\/p>\n<pre>&lt;label for=\"fname1\" class=\"hidden\" id=\"poot\"&gt;First name&lt;\/label&gt;\r\n&lt;input id=\"fname1\" aria-labelledby=\"poot\" type=\"text\" \r\nplaceholder=\"Bonny\"&gt;\r\n\r\n.hidden {\r\ndisplay:none\r\n}<\/pre>\n<ul>\n<li>label = <em>none<\/em><\/li>\n<li>accessible name = <em>First name<\/em><\/li>\n<\/ul>\n<h3>Example code<\/h3>\n<p><code>label<\/code> element wrapped around a custom control built upon a non interactive (<code>span<\/code>) element:<\/p>\n<pre>&lt;label&gt;First name\r\n&lt;span tabindex=\"0\" role=\"textbox\"&gt;&lt;\/span&gt;&lt;\/label&gt;<\/pre>\n<ul>\n<li>label = First name<\/li>\n<li>accessible name = <em>none<\/em><\/li>\n<\/ul>\n<h2>When is it neither?<\/h2>\n<h3>Example code<\/h3>\n<p>Although it has the <code>for\/id<\/code> attributes set, because the <code>label<\/code> element is hidden (<code>display:none<\/code>), it is neither a label or an accessible name<\/p>\n<pre>&lt;label for=\"fname\" class=\"hidden\"&gt;First name&lt;\/label&gt;\r\n&lt;input id=\"fname\" type=\"text\" placeholder=\"Throater\"&gt;\r\n\r\n.hidden {\r\ndisplay:none\r\n}<\/pre>\n<ul>\n<li>label = <em>none<\/em><\/li>\n<li>accessible name = <em>Throater<\/em><\/li>\n<\/ul>\n<h3>Example code<\/h3>\n<p>When a <a href=\"https:\/\/html.spec.whatwg.org\/multipage\/input.html#attr-input-placeholder\"><code>placeholder<\/code><\/a> attribute value is used as the only label text<\/p>\n<pre>&lt;input type=\"text\" placeholder=\"Little King\"&gt;<\/pre>\n<ul>\n<li>label = <em>none<\/em><\/li>\n<li>accessible name = Little King<\/li>\n<\/ul>\n<h2>Code examples brought to life<\/h2>\n<p class=\"codepen\" style=\"height: 300px; box-sizing: border-box; display: flex; align-items: center; justify-content: center; border: 2px solid; margin: 1em 0; padding: 1em;\" data-height=\"300\" data-default-tab=\"result\" data-slug-hash=\"EaVaeWQ\" data-pen-title=\"label and name examples\" data-user=\"stevef\">See the Pen <a href=\"https:\/\/codepen.io\/stevef\/pen\/EaVaeWQ\"><br \/>\nlabel and name examples<\/a> by steve faulkner (<a href=\"https:\/\/codepen.io\/stevef\">@stevef<\/a>)<br \/>\non <a href=\"https:\/\/codepen.io\">CodePen<\/a>.<\/p>\n<p><script async src=\"https:\/\/public.codepenassets.com\/embed\/index.js\"><\/script><\/p>\n<h2>Further reading<\/h2>\n<ul>\n<li><a href=\"https:\/\/html5accessibility.com\/stuff\/2021\/02\/14\/re-upped-placeholder-the-piss-take-label\/\">placeholder \u2013 the piss-take label<\/a><\/li>\n<li><a href=\"https:\/\/html5accessibility.com\/stuff\/2025\/06\/07\/aria-html-relationship-severence\/\">ARIA\/HTML relationship Severance<\/a><\/li>\n<li><a href=\"https:\/\/html5accessibility.com\/stuff\/2024\/05\/22\/not-so-short-note-on-aria-label-usage-big-table-edition\/\">Not so short note on aria-label usage \u2013 Big Table Edition<\/a><\/li>\n<\/ul>\n<h2>Ramones &#8211; Somebody Put Something In My Drink<\/h2>\n<p><iframe loading=\"lazy\" title=\"YouTube video player\" src=\"https:\/\/www.youtube.com\/embed\/p_6f3Ik7Suw?si=yhPL4FHqG1TswKpE\" width=\"560\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<details>\n<summary>Lyrics<\/summary>\n<pre>Somebody, somebody put something in my drink, somebody\r\nAnother night out on the street\r\nStopping for my usual seat\r\nOh, bartender, please\r\nTanqueray and tonic's my favorite drink\r\nI don't like anything colored pink\r\nThat just stinks, it's not for me\r\nIt feels like somebody put something\r\nSomebody put something in my drink\r\nSomebody put something\r\nSomebody put something\r\nBlurred vision and dirty thoughts\r\nFeel out of place, very distraught\r\nFeel something coming on\r\nYeah, kick the jukebox, slam the floor\r\nDrink, drink, drink, drink some more\r\nI can't think\r\nHey, what's in this drink?\r\nIt feels like somebody put something\r\nSomebody put something in my drink\r\nSomebody put something\r\nSomebody put something in my drink\r\nSomebody put something\r\nSomebody put something in my drink\r\nSomebody put something\r\nIn my drink\r\nIn my drink\r\nIn my drink\r\nIn my drink\r\nSo you think it's funny, a college prank\r\nGoin' insane for something to drink\r\nFeel a little dry\r\nOh, I couldn't care what you think of me\r\n'Cause somebody put something in my drink\r\nI can't think\r\nHey, give me a drink\r\nIt feels like somebody put something\r\nSomebody put something in my drink\r\nSomebody put something\r\nSomebody put something in my drink\r\nSomebody put something\r\nSomebody put something in my drink\r\nSomebody put something\r\nSomebody put something in my drink\r\nSomebody put something (in my drink)\r\nSomebody put something in my drink\r\nSomebody put something (in my drink)\r\nSomebody put something in my drink\r\nSomebody put something (in my drink)\r\nSomebody put something in my drink\r\n<\/pre>\n<\/details>\n","protected":false},"excerpt":{"rendered":"<p>When is a label also an (accessible) name, when is it not and when is it neither? WCAG definitions: label text\u00a0or other component with a\u00a0text alternative\u00a0that is presented to a user to identify a component within web\u00a0content A placeholder can be an accessible name, but can never be a label A label element can be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1648","post","type-post","status-publish","format-standard","hentry","category-htmlaccessibility"],"_links":{"self":[{"href":"https:\/\/html5accessibility.com\/stuff\/wp-json\/wp\/v2\/posts\/1648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/html5accessibility.com\/stuff\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/html5accessibility.com\/stuff\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/html5accessibility.com\/stuff\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/html5accessibility.com\/stuff\/wp-json\/wp\/v2\/comments?post=1648"}],"version-history":[{"count":21,"href":"https:\/\/html5accessibility.com\/stuff\/wp-json\/wp\/v2\/posts\/1648\/revisions"}],"predecessor-version":[{"id":1671,"href":"https:\/\/html5accessibility.com\/stuff\/wp-json\/wp\/v2\/posts\/1648\/revisions\/1671"}],"wp:attachment":[{"href":"https:\/\/html5accessibility.com\/stuff\/wp-json\/wp\/v2\/media?parent=1648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/html5accessibility.com\/stuff\/wp-json\/wp\/v2\/categories?post=1648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/html5accessibility.com\/stuff\/wp-json\/wp\/v2\/tags?post=1648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}