How not to use the label element


HTML is magic. It comes with all sorts of great usability and accessibility features. But people often ignore them or misuse them.

Take a look at these checkboxen:

If you click on this label, nothing happens.

This is important. Tapping on tiny squares is hard for lots of people. Whether they have visual impairments, motor issues, or just a dirty touchscreen. You should give your user the biggest possible target area to interact with an element.

How is this possilbe? Here's the code for the second checkbox.

HTML HTML<input type="checkbox" id="c1"/>
<label for="c1"> If you click on this label, the checkbox will toggle</label>

The text is wrapped in the <label> element, which is linked to the <input>'s 'id attribute via the for attribute.

The reason I bring this up, is because recently I had to sign up to the Miro website. I tried to click to agree to their terms and conditions, but I couldn't click the text. Hard to click checkbox.

Let's take a look at the code behind it: HTML Source Code. The <input> element has the CSS property set to display: none;. It is invisible to the user.

The <label> is an SVG image. The text is not part of the label and thus is not clickable.

I have no idea why they've done this.

You can use CSS to make ridiculously beautiful input elements. But Miro's replacement for a dull square is... a slightly different dull square!

Default: Miro:

Even if that square is a vital part of their brand guidelines, it would have been simple to put the text inside the <label>.

Designers and developers - please take a moment to make sure your labels are fully clickable. Thanks!


Theories

Why do this?

Nope!


Share this post on…

  • Mastodon
  • Facebook
  • LinkedIn
  • BlueSky
  • Threads
  • Reddit
  • HackerNews
  • Lobsters
  • WhatsApp
  • Telegram

3 thoughts on “How not to use the label element”

  1. says:

    I’ve just learnt that an input can have multiple labels, so they could really easily make the label a label, without having to touch the CSS or the existing label.

    Reply
  2. for the "why" ... this seems like a borked implementation to have "fancy" stylable checkboxes (using SVG). noting that this approach will also not work for keyboard users, screen reader users, etc.

    Reply

What are your reckons?

All comments are moderated and may not be published immediately. Your email address will not be published.

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <p> <pre> <br> <img src="" alt="" title="" srcset="">