https://ericwbailey.website/published/aria-label-is-a-code-smell/ Skip to main content Updating in the open Things might look a little janky for a bit, but that's okay! I am in the process of refreshing the design. Home Writing aria-label is a code smell The aria-label property is made available to us by the Accessible Rich Internet Applications (ARIA) standard. It allows a property/ value declaration in HTML as a way of providing an accessible name for an interactive element. Accessible names Accessible names use text to identify interactive elements on a page. They allow someone using assistive technology to understand, and then take action on those interactive elements. Keeping accessible names concise and descriptive is one of the most important things when coding things in an accessible way. A great example of an accessible name is the content placed between opening and closing a tags: Duck breeds Accessible names are computed via an algorithmic process derived from Accessible Name and Description Computation. Here, an algorithm evaluates each DOM node's text content, attribute content, and associated elements to determine which declaration is the most relevant. This information is then exposed to the browser's Accessibility Tree. Assistive technology consumes information generated by the accessibility tree. This in turn enables people using the assistive technology to understand the makeup of a website or web app's content and take action on it. Code smell The term "code smell" refers to small, repeated patterns or one-off, atypical code constructs that indicate something is worth paying attention to. To quote Martin Fowler: "...smells don't always indicate a problem. [...] You have to look deeper to see if there is an underlying problem there--smells aren't inherently bad on their own--they are often an indicator of a problem rather than the problem themselves." In my experience, the term code smell usually has a negative connotation when someone mentions it. It's a lot like a noticeable smell emanating from the office refrigerator. Ideally it's some delicious homemade kimchi someone brought in, but more often than not it's something like some forgotten fish sticks rotting in the back. To stretch this metaphor to its breaking point, I also don't think the forgotten food is the result of malice. The person who left the fish sticks might: * Not be aware of the unwritten rules about bringing fish to the office, * Have forgotten they placed them there, * Have been reassigned to a different office and didn't get a chance to remove them, * Be getting continuously distracted by other responsibilities, * etc. aria-label as a code smell Sadly, I run into aria-label declarations a lot more than I'd expect to. There are probably a whole host of reasons for this, but if I could name some of the more popular factors they may be: * Unfamiliarity with ARIA leading to using code written by other developers unfamiliar with ARIA, * Trying to work within the conventions imposed by a lot of contemporary development frameworks, * Working with limitations of immature component architecture, or * Wanting to type less into their code editor. When I encounter too much, or mis-applied aria-label it makes me take notice. This code smell puts me on alert to investigate things more thoroughly, as it most likely indicates accessibility issues. Before you scoff at this, I'd encourage you to read the WebAIM Million report. This evaluation of the accessibility of the top 1,000,000 homepages revealed: "Increased ARIA usage on pages correlated to higher detected errors. The more ARIA attributes that were present, the more detected accessibility errors could be expected." That's a big ol' oof right there. ARIA has varying levels of support Web developers are used to thinking of support as a binary yes or no. However, ARIA is a bit unique in that it's support is more conditional, and what it actually does is highly contingent on: 1. How it is being used, and 2. The surrounding context of the rest of the overall experience. Determining actual ARIA support is a bit more complicated than other web technologies, in that it relies on the: * Operating system being used, * Operating system's version, * Browser being used, * Browser's version, * Assistive technology being used, * Assistive technology's version, and * Complexity of the underlying code. Sadly, you can't take a browser, operating system, or assistive technology manufacturer's word at good faith. Determining support means performing manual tests to determine what assistive technology actually reports. What's the difference between text content and attribute content? Before we get any further into it, I think it is important to outline the difference between text content and attribute content. The written words on a website or web app are typically what the W3C calls either heading content or phrasing content. Combined, they make up the vast majority of written content on the web. Attribute content is content that comes from the value of things like aria-label, title, data-*, etc. Its purpose is for more niche development concerns. Code sample featuting a button element and an iframe element. The button has a text label of 'save', and the iframe has a title attribute with a value set to 'YouTube: Crab rave'. Lines are drawn from the text label and iframe title to show the difference between text content and attribute content. Both text content and attribute content have purpose and utility when creating accessible content for the web. Why I think overuse of aria-label is a code smell There are a few factors to be aware of. Let's go over each: 1. aria-label's varied support when declared on a non-interactive element First off, aria-label is intended to only be used on interactive elements, and not non-interactive ones. If you need a refresher on what HTML elements are interactive, they are: * Anchors, when the href attribute is present, *