Horje
HTML <fieldset> Tag

The <fieldset> tag is used to group related elements in a form.

The <fieldset> tag draws a box around the related elements.


Tips and Notes

Tip: The <legend> tag is used to define a caption for the <fieldset> element.


How to create HTML <fieldset> Tag

Group related elements in a form
index.html
Example: HTML
<form action="/action_page.php">
  <fieldset>
    <legend>Personalia:</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> 

Output should be:

How to create HTML <fieldset> Tag

Which browser will support for HTML <fieldset> Tag

Which browser will support for HTML <fieldset> Tag

Attributes for HTML <fieldset> Tag

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 a name for the fieldset

How to Use CSS to style <fieldset> and <legend>

The fieldset element + CSS
index.html
Example: HTML
<form action="/action_page.php">
  <fieldset>
    <legend>Personalia:</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>

Output should be:

How to Use CSS to style <fieldset> and <legend>

How to set Default CSS Settings for HTML <fieldset> Tag

Most browsers will display the <fieldset> element with the following default values:
index.html
Example: HTML
<style>
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);
}
</style>

Output should be:

How to set Default CSS Settings for HTML <fieldset> Tag

How to add HTML <fieldset> disabled Attribute

Disable a group of related form elements.

Definition and Usage

The disabled attribute is a boolean attribute.

When present, it specifies that a group of related form elements (a fieldset) should be disabled.

A disabled fieldset is unusable and un-clickable.

The disabled attribute can be set to keep a user from using the fields until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the fieldset usable again.


Browser Support

The numbers in the table specify the first browser version that fully supports the attribute.

Syntax

<fieldset disabled>

index.html
Example: HTML
<form>
<form action="/action_page.php">
  <fieldset disabled>
    <legend>Personalia:</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>
</form>

Output should be:

How to add HTML <fieldset> disabled Attribute

How to add HTML <fieldset> form Attribute

A <fieldset> element located outside a form (but still a part of the form).

Definition and Usage

The form attribute specifies the form the fieldset belongs to.

The value of this attribute must be equal to the id attribute of a <form> element in the same document.

Browser Support

Syntax

<fieldset form="form_id">

Attribute Values

Value Description
form_id Specifies the form element the <fieldset> element belongs to. The value of this attribute must be the id attribute of a <form> element in the same document.
index.html
Example: HTML
<form action="/action_page.php" method="get" id="form1">
  <label for="favcolor">What is your favorite color?</label>
  <input type="text" id="favcolor" name="favcolor">
  <input type="submit">
</form>

<fieldset form="form1">
  <legend>Personalia:</legend>
  <label for="fname">First name:</label>
  <input type="text" id="fname" name="fname" form="form1"><br><br>
  <label for="lname">Last name:</label>
  <input type="text" id="lname" name="lname" form="form1">
</fieldset> 

Output should be:

How to add HTML <fieldset> form Attribute

How to add HTML <fieldset> name Attribute

A <fieldset> with a name attribute.

Definition and Usage

The name attribute specifies a name for a fieldset.

The name attribute is used to reference elements in a JavaScript, or to reference form data after a form is submitted.


Browser Support

Syntax

<fieldset name="text">

Attribute Values

Value Description
name Specifies the name of the fieldset
index.html
Example: HTML
<form action="/action_page.php" method="get">
  <fieldset name="personalia">
    <label for="fname">First name:</label>
    <input type="text" id="fname" name="fname">
  </fieldset>
  <br>
  <button type="button"
  onclick="form.personalia.style.backgroundColor='yellow'">
  Change background color of fieldset</button>
  <input type="submit">
</form> 

Output should be:

How to add HTML <fieldset> name Attribute





Related Articles
HTML <!--...--> Tag HTML Tag
HTML <!DOCTYPE> Declaration HTML Tag
HTML Elements and Doctypes HTML Tag
HTML <a> Tag HTML Tag
HTML <abbr> Tag HTML Tag
HTML <acronym> Tag HTML Tag
HTML <address> Tag HTML Tag
HTML <applet> Tag HTML Tag
HTML <area> Tag HTML Tag
HTML <article> Tag HTML Tag
HTML <aside> Tag HTML Tag
HTML <audio> Tag HTML Tag
HTML <b> Tag HTML Tag
HTML <base> Tag HTML Tag
HTML <basefont> Tag HTML Tag
HTML <bdi> Tag HTML Tag
HTML <bdo> Tag HTML Tag
HTML <big> Tag HTML Tag
HTML <blockquote> Tag HTML Tag
HTML <body> Tag HTML Tag
HTML <br> Tag HTML Tag
HTML <button> Tag HTML Tag
HTML <canvas> Tag HTML Tag
HTML <caption> Tag HTML Tag
HTML <center> Tag HTML Tag
HTML <cite> Tag HTML Tag
HTML <code> Tag HTML Tag
HTML <col> Tag HTML Tag
How to create HTML <colgroup> Tag HTML Tag
HTML <data> Tag HTML Tag
HTML <datalist> Tag HTML Tag
HTML <dd> Tag HTML Tag
HTML <del> Tag HTML Tag
HTML <details> Tag HTML Tag
HTML <dfn> Tag HTML Tag
HTML <dialog> Tag HTML Tag
HTML <dir> Tag HTML Tag
HTML <div> Tag HTML Tag
HTML <dl> Tag HTML Tag
HTML <dt> Tag HTML Tag
HTML <em> Tag HTML Tag
HTML <embed> Tag HTML Tag
HTML <fieldset> Tag HTML Tag
HTML <figcaption> Tag HTML Tag
HTML <figure> Tag HTML Tag
HTML <font> Tag HTML Tag
HTML <footer> Tag HTML Tag
HTML <form> Tag HTML Tag
HTML <frame> Tag HTML Tag
HTML <frameset> Tag HTML Tag
HTML <h1> to <h6> Tags HTML Tag
HTML <head> Tag HTML Tag
HTML <header> Tag HTML Tag
HTML <hgroup> Tag HTML Tag
HTML <hr> Tag HTML Tag
HTML <html> Tag HTML Tag
HTML <i> Tag HTML Tag
HTML <iframe> Tag HTML Tag
HTML <img> Tag HTML Tag
HTML <input> Tag HTML Tag
HTML <ins> Tag HTML Tag
HTML <kbd> Tag HTML Tag
HTML <label> Tag HTML Tag
HTML <legend> Tag HTML Tag
HTML <li> Tag HTML Tag
HTML <link> Tag HTML Tag
HTML <main> Tag HTML Tag
HTML <map> Tag HTML Tag
HTML <mark> Tag HTML Tag
HTML <menu> Tag HTML Tag
HTML <meta> Tag HTML Tag
HTML <meter> Tag HTML Tag
HTML <nav> Tag HTML Tag
HTML <noframes> Tag HTML Tag
HTML <noscript> Tag HTML Tag
HTML <object> Tag HTML Tag
HTML <ol> Tag HTML Tag
HTML <optgroup> Tag HTML Tag
HTML <option> Tag HTML Tag
HTML <output> Tag HTML Tag
HTML <p> Tag HTML Tag
HTML <param> Tag HTML Tag
HTML <picture> Tag HTML Tag
HTML <pre> Tag HTML Tag
HTML <progress> Tag HTML Tag
HTML <q> Tag HTML Tag
HTML <rp> Tag HTML Tag
HTML <rt> Tag HTML Tag
HTML <ruby> Tag HTML Tag
HTML <s> Tag HTML Tag
HTML <samp> Tag HTML Tag
HTML <script> Tag HTML Tag
HTML <search> Tag HTML Tag
HTML <section> Tag HTML Tag
HTML <select> Tag HTML Tag
HTML <small> Tag HTML Tag
HTML <source> Tag HTML Tag
HTML <span> Tag HTML Tag
HTML <strike> Tag HTML Tag
HTML <strong> Tag HTML Tag
HTML <style> Tag HTML Tag
HTML <sub> Tag HTML Tag
HTML <summary> Tag HTML Tag
HTML <sup> Tag HTML Tag
HTML <svg> Tag HTML Tag
HTML <table> Tag HTML Tag
HTML <tbody> Tag HTML Tag
HTML <td> Tag HTML Tag
HTML <template> Tag HTML Tag
HTML <textarea> Tag HTML Tag
HTML <tfoot> Tag HTML Tag
HTML <th> Tag HTML Tag
HTML <thead> Tag HTML Tag
HTML <time> Tag HTML Tag
HTML <title> Tag HTML Tag
HTML <tr> Tag HTML Tag
HTML <track> Tag HTML Tag
HTML <tt> Tag HTML Tag
HTML <u> Tag HTML Tag
HTML <ul> Tag HTML Tag
HTML <var> Tag HTML Tag
HTML <video> Tag HTML Tag
How to add HTML <wbr> Tag HTML Tag

Single Articles
How to create HTML <fieldset> TagHTML Tag
Which browser will support for HTML <fieldset> TagHTML Tag
Attributes for HTML <fieldset> TagHTML Tag
How to Use CSS to style <fieldset> and <legend>HTML Tag
How to set Default CSS Settings for HTML <fieldset> TagHTML Tag
How to add HTML <fieldset> disabled AttributeHTML Tag
How to add HTML <fieldset> form AttributeHTML Tag
How to add HTML <fieldset> name AttributeHTML Tag

Category:
Web Tutorial
Sub Category:
HTML Tag
Uploaded by:
Admin


Reffered: https://www.w3schools.com/tags/tag_fieldset.asp