Forum Moderators: open
Grouping related form controls makes forms more understandable for all users, as related controls are easier to identify. It also makes it easier for people to focus on smaller and more manageable groups rather than try to grasp the entire form at once.
Grouping needs to be carried out visually and in the code, for example, by using the <fieldset> and <legend> elements to associate related form controls.
Grouping controls is most important for related radio buttons and checkboxes.
...
Because they are multiple controls, it is particularly important that they be grouped semantically so they can be more easily treated as a single control. ...
It can also be useful to group other sets of controls that are not as tightly related as sets of radio buttons and checkboxes. For instance, several fields that collect a user's address might be grouped together with a legend of "Address".
fieldset { border: none; margin-left: 0; padding-left: 0 } // Using a unique ID
<div id="named_element">
<b>These are checkboxes</b><br>
<br>
<input type="checkbox" name="checkbox_1"> 1<br>
<input type="checkbox" name="checkbox_2"> 2
</div>
// Using fieldset
<fieldset style="border: none; margin-left: 0; padding-left: 0">
<legend><b>These are checkboxes</b></legend>
<br>
<input type="checkbox" name="checkbox_1"> 1<br>
<input type="checkbox" name="checkbox_2"> 2
</fieldset> Well, in practice I discovered that a FIELDSET has built-in styling... placing a border around the whole thing, a margin-left and padding-left, and if you use a LEGEND then it positions the text of the legend vertically centered on top of the border
Authors sometimes avoid using the fieldset element because of the default display in the browser, which draws a border around the grouped controls. This visual grouping is also useful and authors should seriously consider retaining it (or some form of visual grouping). The visual effect can be modified in CSS by overriding the "border" property of the fieldset and the "position" property of the legend.