Hello! This is about the HTML lesson in which we learn about radio buttons. I’d like to know why we need to put each button nested inside it’s own label tag. I did it with only one label tag (nesting both buttons) and it worked the same as using one label tag for each button/option.
This is the code from the lesson. The radio button part is towards the end.
Thank you!
There’s a concept called “Semantics” which is about how properly you name everything in HTML. It helps with rendering and accessibility.
Make sure to do a quick humble research on Semantic HTML and you can learn a lot about it.
Happy Coding
Semantic HTML, I didn’t think of this! I actually tried googling just my question straight up, and didn’t find satisfactory results.
Thank you for explaining the general idea and guiding me towards a more effective search.
Go back to the lesson and just wrap both radio buttons in label element.
Go to the preview and then click on each of the radio button labels.
Now do as the lesson describes and wrap each radio button in its own label element.
Go to the preview and then click on each of the radio button labels. Notice the effect?
And my advice still stands.
Using the first code, that is one label element with both radio buttons nested, and click on each radio buttons label.
The labels are “indoor” and “outdoor” respectively. Not the radio buttons, the labels.
Now nest each radio button in its own label element and click on each individual label. Again, the labels are “indoor” and “outdoor”.
Ah, now I understand what you were talking about. That’s really cool! It really makes such a difference. Even if I click the latter label, it’ll mark the first button.
Now I understand why put each button nested in its own label. Makes much more sense now. Thank you so much!
It’s good that you’re not just rushing through the lessons and are trying different things. It’s the way to learn.
Keep it up. And don’t be afraid to ask questions on what you don’t understand.