A11Y 101: Missing form labels

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
In this series I'll explore the basics of accessibility and you can join me on this learning trip.
We developers tend to hide elements by using display: none or visibility: hidden. And this works perfectly fine actually to hide elements from the screen. However, be aware this does precisely what we tell it. It hides things from the screen, which i...
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

When working with forms, we should always opt to have form labels describing the label.
However, many designers want to hide these labels in modern-day applications as they make things bulky.
Some good examples of forms without labels can be:


The common thing we see in both examples is a form with only one field and a button. Often, it can be clear enough as to what the form is for and what is expected of the user.
I use a placeholder to describe it for the visual reader in my example. However, it might be unclear what this form is for visually impaired people.
To make this form accessible, we should use invisible labels to describe the field. There are three options we can use.
This is the most semantic way of adding the label to describe the form field.
We set it up as we would add a regular label for a form field but use CSS to hide it from the browser. Screen readers will still be able to read it this way.
<label class="hidden" for="search">Search</label>
<input type="text" id="search" />
To make elements hidden for screen readers, we have to use specific CSS; I'll write a bit more in detail in the following article as there are multiple options again.
Another way of making the screen readers aware of what an input field is for is to add a title attribute to the input field.
However, this comes with the drawback of it showing this title attribute to visual users.
It's up to you if that's acceptable for your use case.
<input id="search" type="text" title="Search" />
The last method is to use aria-label. It works the same as the title method but doesn't show up for visual users.
This is the safest way of adding descriptive text without messing with hidden styles.
<input id="search" type="text" aria-label="Search" />
There are three ways of making form fields without labels accessible, all three have their use-cases, and it's up to the developer to decide which one works best.
I like the aria-label approach as it's least intrusive in adding elements nobody will see, but the hidden label is just as good. I would advise only resort to the title if you have no other choice.
Note: You should only use one of the three methods, don't combine them as screen readers will read your information twice.
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter