# Grouping & Gauges

> fieldset groups related controls and can disable them all at once. range, output, meter, and progress work together to build interactive numeric displays where one element drives others and the semantic element chosen signals whether a value is a measurement or a task's completion.

Subject: HTML | Lesson 29 of 42 | 6 min read
Interactive lesson: https://codewithanimation.in/html/fieldset-and-gauges
Previous: [select, textarea & buttons](https://codewithanimation.in/html/select-textarea-and-buttons.md) | Next: [Built-in Form Validation](https://codewithanimation.in/html/form-validation.md)

## What it is

`<fieldset>` groups related form controls inside a border. Its `<legend>` child provides the group's accessible name, announced before each control inside. Adding `disabled` to a `<fieldset>` disables every descendant control in one attribute: all inputs, selects, textareas, and buttons become inert and their values are excluded from submission. This makes fieldset the cleanest tool for "loading" or "confirm before edit" states.

`<input type="range">` is a slider with `min`, `max`, and `step` attributes. It submits a string, not a number. It has no native value label, so pair it with an `<output>` element. `<output>` is the semantic element for computed or derived values: its `for` attribute takes a space-separated list of input ids that feed into it, creating a programmatic association assistive technology can use. `<output>` can also carry a `name` attribute and submits its current value with the form.

## Why it matters

`<meter>` and `<progress>` solve different problems and are not interchangeable. `<meter>` represents a scalar measurement within a known range: disk usage, battery level, a test score, blood pressure. It accepts `low`, `high`, and `optimum` attributes that tell the browser where the optimal zone is. A disk usage meter with `optimum="0"` (lower is better) turns yellow as it crosses `high` and red as it enters the critical zone, giving users a color-coded signal without any JavaScript or CSS. `<progress>` represents how far along a task is: an upload, a build, an installation. It does not have good/bad zones; it just fills toward completion.

Choosing the right element communicates intent in the accessibility tree. A screen reader encountering a `<meter>` will announce it as a meter with its current value and range. A `<progress>` is announced as a progress bar. Using a plain `<div>` with an animated width conveys nothing to AT without significant ARIA work.

## How it works

To drive an `<output>` from a range input, give the input an `id` and set the output's `for` to that id. Update the output's text content in JavaScript (or with an `oninput` handler) as the slider moves. The browser does not automatically populate `<output>` from its `for` inputs; `for` is a semantic association, not a live binding.

For `<meter>`, set `min`, `max`, and `value` for the current reading. Add `low` and `high` to mark the boundary between good, acceptable, and concerning ranges. Set `optimum` to indicate which end of the range is preferable: `optimum="0"` (or closer to `min`) means lower values are better (disk usage, error rate). `optimum` closer to `max` means higher is better (fuel level, signal strength). The browser derives the colour automatically from these values.

For `<progress>`, set `max` and `value`. A `value` equal to `max` shows a full bar. Omitting `value` entirely renders an indeterminate animation in most browsers, useful while a task is running but its completion fraction is unknown.

## Common mistake: Using <progress> to show a measurement level instead of task completion

A `<progress>` element used to show disk usage or a health score renders without semantic meaning for that context. Screen readers announce it as a progress bar (implying a task is running), not as a level measurement. It also has no `low`/`high`/`optimum` attributes, so there is no way to convey that 90% is critical rather than nearly done. Use `<meter>` for any value that represents a level and `<progress>` for any value that represents how far along a task is.

## Tip: Disable a whole form section during submission with fieldset disabled

During an async form submission, adding `disabled` to the wrapping `<fieldset>` prevents the user from changing values while the request is in flight. You remove the attribute when the response arrives. One attribute replaces a loop over every input in the section. The disabled state is also visible to AT, which announces disabled controls as unavailable. Pair it with a loading indicator so sighted users also get the signal.

## Try it: Try it

Drag the range slider and watch the output, meter, and progress elements all update from the same source. Toggle the fieldset disabled state to see the cascade.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/html/fieldset-and-gauges

## Check yourself

### Question 1

A form shows the user's profile completion percentage (30% of fields filled). Which element is semantically correct?

- A. <progress>: it represents how far along a task is
- B. <meter>: it displays a percentage within a 0-100 range
- C. Either works identically; both show a filled bar

Correct answer: A

`<progress>` is for task completion. Profile completion is a task ("finish filling in your profile"). `<meter>` is for level measurements where good/bad zones matter.

- Why not B: Profile completion is the progress of a task (filling in fields), not a scalar measurement of a level. <progress> is the right element. <meter> is for level measurements like disk usage or a score.
- Why not C: They render similarly but carry different semantic meaning. Screen readers announce them differently, and <meter> supports low/high/optimum color coding that <progress> does not.

### Question 2

What does adding disabled to a <fieldset> do?

- A. Disables all descendant form controls and excludes their values from submission
- B. Hides the fieldset visually but keeps the controls interactive
- C. Disables only the <legend> child, leaving inputs unaffected

Correct answer: A

`disabled` on a `<fieldset>` disables all descendant form controls at once and excludes them from submission. It is the most efficient way to lock a section of a form during loading or submission.

- Why not B: disabled on <fieldset> does not hide anything. It makes every descendant control inert (no interaction, no focus) and removes their values from the form submission.
- Why not C: The disabled attribute cascades to all form-associated descendants: inputs, selects, textareas, and buttons. The legend itself is not a form control and is unaffected.

### Question 3

What does the for attribute on <output> express?

- A. A semantic association between the output and the inputs whose values it displays
- B. A live data binding that automatically updates the output when those inputs change
- C. The same as the for attribute on <label>: it focuses the named input on click

Correct answer: A

`for` on `<output>` is a semantic declaration, not a live binding. It tells AT which inputs the output value is derived from. You still need JavaScript to update the content as inputs change.

- Why not B: The for attribute on <output> is a semantic association, not a live binding. JavaScript (or oninput handlers) must explicitly update the output's content when inputs change.
- Why not C: <output> is not interactive and does not respond to clicks. Its for attribute declares which inputs contribute to the displayed value, for assistive technology context.

## Remember this

- `disabled` on `<fieldset>` disables all descendant controls at once and removes their values from submission.
- `<output>` is the semantic element for computed values; its `for` links it to its source inputs for AT.
- `<meter>` is for level measurements with `optimum`/`low`/`high`; `<progress>` is for task completion with no good/bad zones.
- `<progress>` with no `value` attribute shows an indeterminate animation while a task's completion fraction is unknown.
