<fieldset>

Draft

Definition

The <fieldset> HTML element is used to group related form elements together and create a visual and semantic boundary around them. It is commonly used to create a logical grouping of form controls, such as checkboxes, radio buttons, input fields, and labels.

Here’s an example of how to use the <fieldset> element:

<form>
  <fieldset>
    <legend>Contact Information</legend>
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" required />

    <label for="email">Email:</label>
    <input type="email" id="email" name="email" required />

    <label for="message">Message:</label>
    <textarea id="message" name="message" required></textarea>
  </fieldset>

  <button type="submit">Submit</button>
</form>

In this example, the <fieldset> element groups the contact information form controls together. The <legend> element is used as a caption or title for the fieldset, providing a descriptive label for the related form controls.

By default, the <fieldset> element creates a visual boundary around the grouped form controls, making it easier for users to understand the relationship between the controls. It also helps assistive technologies to identify and navigate the grouped controls.

The <fieldset> element can contain any form-related elements, such as labels, input fields, checkboxes, radio buttons, or even nested fieldsets. It helps improve the accessibility and organization of complex forms by grouping related controls together.

You can apply CSS styles to the <fieldset> element to customize its appearance, such as setting borders, backgrounds, margins, or padding.