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 fieldsetform: Associates with a form by IDname: 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
impl HtmlElement for Fieldset
impl CanContain<Legend> for Fieldset
impl<T: FlowContent> CanContain<T> for Fieldset
impl FlowContent for Fieldset
impl PalpableContent for Fieldset
Auto Trait Implementations§
impl Freeze for Fieldset
impl RefUnwindSafe for Fieldset
impl Send for Fieldset
impl Sync for Fieldset
impl Unpin for Fieldset
impl UnwindSafe for Fieldset
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more