There is a <fieldset>
tag for a set of fields.
Why isn't there a hierarchical child for fieldsets?
<form>
<fieldset>
<legend>Thin Sandwich Options</legend>
<field>
<label>Meat</label>
<div class='inputs'>
<label>
<input type="radio" name="meat" value="turkey" />Turkey</label>
<label>
<input type="radio" name="meat" value="monkey" />Monkey</label>
</div>
<div class='desc'>Pick one meat for the thin sandwich.</div>
</field>
<field>
<label>Cheese</label>
<div class='inputs'>
<label>
<input type="checkbox" name="cheese" value="chedder" />Cheddar</label>
<label>
<input type="checkbox" name="cheese" value="swiss" />Swiss</label>
</div>
<div class='desc'>Pick one meat for the thin sandwich.</div>
</field>
</fieldset>
<fieldset>
<legend>Beverage Options</legend>
<field>
<label for="carbonated">Carbonated</label>
<div class='inputs'>
<label>
<input type="radio" name="carbonated" value="coke" />Coke</label>
<label>
<input type="radio" name="carbonated" value="mtn-dew" />Dew</label>
</div>
<div class='desc'>Pick one beverage per combo.</div>
</field>
<field>
<label for="non-carbonated">Non Carbonated</label>
<div class='inputs'>
<label>
<input type="radio" name="non-carbonated" value="tea-sweet" />Tea (non sweetend)</label>
<label>
<input type="radio" name="non-carbonated" value="tea" />Tea</label>
</div>
</field>
</fieldset>
</form>
I keep coming back to this question whenever I am working on my HTML form layouts.
As MDN defines it:
The HTML
<fieldset>
element is used to group several controls as well as labels () within a web form.
I see a <field>
element as grouping a single control (or set of radio buttons) with a single label and a description. The field tag would have some of the same attributes that the input tag has, readonly, required, etc.
Why does bootstrap use the class 'form-group'?
Why does Wufoo use li tags for each field?
Enclosing related form elements into fields would add clarity.
Every major front-end framework has some class or tag to differentiate each field.
Why the heck don't we have a single HTML tag to bring some normality to form design?
Update: added a better HTML example of the usage of a <field>
tag.
div
for this. It's just not there... But hey we have astrong
tag so we can replaceb
with it. Thanks W3C, just what we needed.<div class="field"><label...><input...></div>
to create any sort of containing element for fields. IMO field would be semantically useful / natural. As to other people's arguments about "Why would you need this?", why do we need amain
,header
, orfooter
tag? It's readable and is about semantics.