Styling Complex Labels

Danielle Romo has a write-up on the HTML pattern to reach for when an <label> is wordy and gets fancy styling for an <input type="radio">.

The technique: pair a <span class="hidden-visually"> holding the text you want read out with a <span aria-hidden="true"> that carries only the visual content.


What stands out is how frequently people arrive at this same pattern. Ethan Marcotte's The World-Wide Work is one example — the drop-cap pattern discussed there lands on essentially the same approach.

<span aria-hidden="true">
  Markup for the visual experience only,
  where you can (somewhat safely) use markup 
  that would be crap for screen readers.  
</span>

<span class="visually-hidden">
  Markup for the read experience only, that
  you keep very clean on purpose.
</span>

The hidden-visually class referenced above is described here.

Originally covered at Cloud Four.