DEV Community

Discussion on: Create custom keyboard accessible radio buttons

Collapse
 
link2twenty profile image
Andrew Bone

Is there a reason you went for wrapping each input-label combo in a div rather than using the label element?

<div class="radio-wrapper">
  <input type="radio" name="animal" id="elephant" />
  <label for="elephant">Elephant</label>
</div>

Rather than

<label class="radio-wrapper">
  <input type="radio" name="animal" />
  Elephant
</label>

Or is it a simple case of either will do but you went with the div? 🙂

Collapse
 
lkopacz profile image
Lindsey Kopacz

Because I wanted to.

Collapse
 
link2twenty profile image
Andrew Bone

Cool, thanks 🙂

Was just checking there wasn't some reason I wasn't aware of 🙂

Thread Thread
 
lkopacz profile image
Lindsey Kopacz

haha It's how I prefer to write my inputs.

Collapse
 
lkopacz profile image
Lindsey Kopacz

I would take a look at the responses to this. I prefer explicit association but others put their reasons in.

Collapse
 
elizabethschafer profile image
Elizabeth Schafer

One reason to do it this way is that explicit labels (input+label combo) have better support with assistive tech. Implicit labels (label wrapping an input) don't work with Dragon Naturally Speaking.

a11ysupport.io/tech/html/label_ele...