Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fieldsets and legends

Tags:

html

fieldset

Alright, I know how the fieldset/legend works out in HTML. Say you have a form with some fields:

<form>
    <fieldset>
        <legend>legend</legend>
        <input name="input1" />
    </fieldset>
</form>

What should I use the legend for? It's being displayed as a title, but isn't a legend semantically an explanation of the contents? In my view, preferably you'd do something like this:

<form>
    <fieldset>
        <legend>* = required</legend>
        <label for="input1">input 1 *</label><input id="input1" name="input1" />
    </fieldset>
</form>

But that doesn't really work out with how fieldsets are rendered. Is this just a ambigious naming in HTML, or is it my misunderstanding of the English word 'legend'?


Edit: fixed some errors ;-)

like image 709
Erik van Brakel Avatar asked Oct 31 '08 13:10

Erik van Brakel


1 Answers

Yes, the naming is ambiguous. It’s best to consider it as a caption for the fieldset.

See the HTML spec on FIELDSET and LEGEND elements if you haven’t already:

The LEGEND element allows authors to assign a caption to a FIELDSET. The legend improves accessibility when the FIELDSET is rendered non-visually.

like image 165
Gareth Avatar answered Sep 28 '22 08:09

Gareth