HTML <fieldset> Element

Publish in HTML Tutorial el 23/05/2025 23:07

The <fieldset> element is used to group related form controls together, creating a visual and semantic connection between them. It's particularly useful for long forms that need to be organized into logical sections. When combined with the <legend> element, it provides a visible caption for the grouped elements.


Key features of <fieldset>:

  • Creates a box around grouped form elements
  • Improves form accessibility by providing context
  • Can be styled with CSS for better visual presentation
  • Works well with screen readers when properly labeled
  • Can be disabled to disable all contained form controls


Basic Syntax


Examples of <fieldset> Usage

Example 1: Basic Fieldset with Legend

This shows the most fundamental usage of fieldset with a legend.

Play Code


Example 2: Styled Fieldset

This example demonstrates how to style a fieldset with CSS.

Play Code


Example 3: Disabled Fieldset

Shows how to disable all controls within a fieldset by disabling the fieldset itself.

Play Code


Example 4: Fieldset with JavaScript Toggle

This example uses JavaScript to toggle the disabled state of a fieldset.

Play Code


Example 5: Nested Fieldsets

Demonstrates how fieldsets can be nested for complex form organization.

Play Code


Tips and Tricks

  • Accessibility: Always use a <legend> element to describe the group of form controls.
  • Styling: You can remove the default border with border: none; and create custom borders.
  • Flexbox/Grid: Fieldsets can be used as flex or grid containers for modern layouts.
  • JavaScript: Use the disabled property to enable/disable entire sections of a form.
  • Validation: Group related validation messages within the same fieldset for better user experience.


Browser Support

The <fieldset> element is supported by all modern browsers and has excellent support even in older browsers. The only notable issue is that some older versions of Internet Explorer had quirky behavior with fieldset positioning and sizing, but these issues are largely irrelevant today.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...