Group related elements in a form:
<form action="/action_page.html">
<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>
Try it Yourself »
More "Try it Yourself" examples below.
The <fieldset>
tag is used to group related elements in a form.
The <fieldset>
tag draws a box around the related elements.
Tip: The <legend> tag is used to define a caption for the <fieldset>
element.
Element | |||||
---|---|---|---|---|---|
<fieldset> | Yes | Yes | Yes | Yes | Yes |
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 |
The <fieldset>
tag also supports the Global Attributes in HTML.
The <fieldset>
tag also supports the Event Attributes in HTML.
Use CSS to style <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.html">
<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>
</body>
</html>
Try it Yourself »
HTML DOM reference: Fieldset Object
Most browsers will display the <fieldset>
element with the following default values:
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);
}
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!