The HTML <fieldset> tag
- Previous Page <embed>
- Next Page <figcaption>
Definition and Usage
<fieldset>
The tag is used to group related elements in a form.
<fieldset>
The tag draws a box around the related elements.
<legend>
The tag defines a title for the fieldset element.
See also:
HTML DOM Reference Manual:Fieldset Object
Example
Example 1
Group related elements in the form:
<form action="/action_page.php"> <fieldset> <legend>Personal Information:</legend> <label for="fname">First Name:</label> <input type="text" id="fname" name="fname"><br><br> <label for="lname">Last Name:</label> <input type="text" id="lname" name="lname"><br><br> <label for="email">Email:</label> <input type="email" id="email" name="email"><br><br> <label for="birthday">Birthday:</label> <input type="date" id="birthday" name="birthday"><br><br> <input type="submit" value="Submit"> </fieldset> </form>
Example 2
Use CSS to set the styles of <fieldset> and <legend>:
<html> <head> <style> fieldset { background-color: #eeeeee; } legend { background-color: gray; color: white; padding: 5px 10px; } input { margin: 5px; } </style> </head> <body> <form action="/action_page.php"> <fieldset> <legend>Personal Information:</legend> <label for="fname">First Name:</label> <input type="text" id="fname" name="fname"><br><br> <label for="lname">Last Name:</label> <input type="text" id="lname" name="lname"><br><br> <label for="email">Email:</label> <input type="email" id="email" name="email"><br><br> <label for="birthday">Birthday:</label> <input type="date" id="birthday" name="birthday"><br><br> <input type="submit" value="Submit"> </fieldset> </form> </body> </html>
Tips and comments
Tip:The <legend> tag is used to define the title for the <fieldset> element.
Attribute
Attribute | Value | Description |
---|---|---|
disabled | disabled | Specifies that a group of related form elements should be disabled. |
form | form_id | Specifies which form the fieldset belongs to. |
name | Text | Specifies the name of the fieldset. |
Global attributes
<fieldset>
The tag also supports Global attributes in HTML.
Event attributes
<fieldset>
The tag also supports Event attributes in HTML.
Default CSS Settings
Most browsers will display the following default values <fieldset>
Element:
fieldset { display: block; margin-left: 2px; margin-right: 2px; padding-top: 0.35em; padding-bottom: 0.625em; padding-left: 0.75em; padding-right: 0.75em; border: 2px groove (internal value); }
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
- Previous Page <embed>
- Next Page <figcaption>