Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

fieldset — grouping form controls

The `fieldset` element groups related controls or other content. An optional `legend` captions the group, while `disabled` disables its controls except descendants of its first `legend` child.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<fieldset [disabled] [form="form-id"] [name="group-name"]>
  <legend>Group caption</legend>
  <!-- Related controls and other flow content -->
</fieldset>

fieldset represents a group of form controls or other content. Place an optional legend as its first element child to caption the group. Still use label to identify individual fields. Both opening and closing tags are required.

The presence of disabled disables controls inside the group, except those within its first legend child. Disabled controls are omitted when form data is constructed. With nested groups, removing an inner disabled does not override disabling inherited from an outer group.

form identifies the form associated with the fieldset itself; it does not automatically associate descendant controls with that form. name lets you look up the group through form.elements, but does not create a submitted name–value entry for the group.

The example compares data before and after setting group.disabled = false. The checked control in legend appears in both datasets; email appears only in the second. The code displays the result in result without submitting the form.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>fieldset example</title>
<form id="settings">
  <fieldset id="group" disabled>
    <legend><label><input type="checkbox" name="enabled" checked> Notifications</label></legend>
    <label>Email <input type="email" name="email" value="ada@example.com"></label>
  </fieldset>
</form>
<pre id="result"></pre>
<script>
  const form = document.getElementById('settings');
  const group = document.getElementById('group');
  const snapshot = () => JSON.stringify([...new FormData(form)]);
  const before = snapshot();
  group.disabled = false;
  document.getElementById('result').textContent =
    before + '\n' + snapshot();
</script>
</html>

Result

[["enabled","on"]]
[["enabled","on"],["email","ada@example.com"]]

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources