I have a question about the use of a check box in an implicit label element.

Asked 1 years ago, Updated 1 years ago, 125 views

How to make a check box and how to check the check box even if you click on the text area

<input type="checkbox" id="check01">
<label for="check01">check01</label>

Like this, I mainly used the method of making an input by connecting id and label with for

<label>
    <input type="checkbox"> check01
</label>

I found out that there is also a way to make it by putting input elements in the label tag. If you do this, you don't have to use the id and for properties.

I wonder if the latter method is against the web standard or not. [MDN label] https://developer.mozilla.org/ko/docs/Web/HTML/Element/label introduces the same method as the latter... I wonder if it fits the web standard!

I'm sharing the code pen that I made as an example. https://codepen.io/Neodahl/pen/YjaMPX

fast-frontend label html implicit-link input

2022-09-22 12:31

2 Answers

Hello NeoDahl, ^ - ^

There are two ways to link labels and input elements: explicit and implicit.

Explicit connection

Explicit connection refers to the explicit connection of the for property of the label element and the id property of the input element using the same value.

<label for="user-id">ID</label>
<input type="text" id="user-id">

Implicit connection

Implicit connection is a method of connecting an input element by wrapping it around a label element.

<label>ID <input type="text"></label>

Both explicit and implicit connections provide the same results. However, there are differences in accessibility.

Explicit connections are easy to use when different HTML elements are included between labels and input elements.

Using explicit connections improves accessibility because linking the input element with the label element makes it clear what to type in the input element. Also, when users click on linked label content, the check status of the input element changes, so usability is also improved

For implicit connections, Some information and communication aids do not recognize the connection so using explicit connections is more recommended if you are mindful of access. (Generally, explicit labels are better supported by assistive technology)

.

But Most of the information and communication aids used today are implicit Supports connections. Therefore, there is a large use of implicit connection methods I don't think it'll be a problem. Google Guide - Accessibility Please refer to the tree article and read it.

.

However, if accessibility issues arise in the future, it may be necessary to modify and supplement them from implicit to explicit.


2022-09-22 12:31

[strong] Both are standard uses. For example, Bootstrap uses the input attribute assuming that only check box/radio button is used without a label tag.


2022-09-22 12:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.