Fieldset

Struct Fieldset 

Source
pub struct Fieldset;
Expand description

The <fieldset> element - groups related form controls and labels.

§Purpose

The <fieldset> element groups related form controls and labels within a form. Provides semantic grouping and visual separation of form sections. Can be disabled as a group, affecting all contained controls. Typically rendered with a border around the grouped elements.

§Content Categories

  • Flow Content
  • Palpable Content

§Permitted Content Model

  • Optionally a <legend> element (must be first child)
  • Followed by flow content

§Common Use Cases

  • Grouping personal information fields
  • Grouping address fields
  • Grouping related checkboxes or radio buttons
  • Creating form sections with logical divisions
  • Disabling multiple controls at once

§Key Attributes

  • disabled: Disables all form controls within the fieldset
  • form: Associates with a form by ID
  • name: Name for the fieldset (for scripting purposes)

§Example

<!-- Basic fieldset with legend -->
<fieldset>
  <legend>Personal Information</legend>
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname">
   
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname">
</fieldset>

<!-- Radio button group -->
<fieldset>
  <legend>Choose your preferred contact method:</legend>
  <input type="radio" id="email" name="contact" value="email">
  <label for="email">Email</label>
   
  <input type="radio" id="phone" name="contact" value="phone">
  <label for="phone">Phone</label>
   
  <input type="radio" id="mail" name="contact" value="mail">
  <label for="mail">Mail</label>
</fieldset>

<!-- Address fieldset -->
<fieldset>
  <legend>Billing Address</legend>
  <label for="street">Street:</label>
  <input type="text" id="street" name="street">
   
  <label for="city">City:</label>
  <input type="text" id="city" name="city">
   
  <label for="zip">ZIP Code:</label>
  <input type="text" id="zip" name="zip">
</fieldset>

<!-- Disabled fieldset -->
<fieldset disabled>
  <legend>Advanced Settings (Coming Soon)</legend>
  <label for="option1">Option 1:</label>
  <input type="checkbox" id="option1" name="option1">
   
  <label for="option2">Option 2:</label>
  <input type="checkbox" id="option2" name="option2">
</fieldset>

<!-- Nested fieldsets -->
<form>
  <fieldset>
    <legend>Account Information</legend>
     
    <fieldset>
      <legend>Login Credentials</legend>
      <label for="user">Username:</label>
      <input type="text" id="user" name="username">
       
      <label for="pass">Password:</label>
      <input type="password" id="pass" name="password">
    </fieldset>
     
    <fieldset>
      <legend>Contact Details</legend>
      <label for="email">Email:</label>
      <input type="email" id="email" name="email">
    </fieldset>
  </fieldset>
</form>

§Accessibility

  • Use <legend> to provide a clear group label
  • Legends are announced by screen readers when entering the fieldset
  • Helps users understand form structure and relationships
  • Disabled fieldsets clearly indicate unavailable sections
  • Ensure legends are concise and descriptive

§WHATWG Specification

Trait Implementations§

Source§

impl HtmlElement for Fieldset

Source§

const TAG: &'static str = "fieldset"

The HTML tag name (e.g., “div”, “span”, “img”).
Source§

const VOID: bool = false

Whether this is a void element (self-closing, no children allowed).
Source§

impl CanContain<Legend> for Fieldset

Source§

impl<T: FlowContent> CanContain<T> for Fieldset

Source§

impl FlowContent for Fieldset

Source§

impl PalpableContent for Fieldset

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.