Thẻ <fieldset> HTML


Thí dụ

Nhóm các phần tử có liên quan trong một biểu mẫu:

<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>

Thêm các ví dụ "Hãy tự mình thử" bên dưới.


Định nghĩa và Cách sử dụng

Thẻ <fieldset>được sử dụng để nhóm các phần tử có liên quan trong một biểu mẫu.

Thẻ <fieldset>vẽ một hộp xung quanh các phần tử có liên quan.


Mẹo và lưu ý

Mẹo: Thẻ <legend> được sử dụng để xác định phụ đề cho <fieldset>phần tử.


Hỗ trợ trình duyệt

Element
<fieldset> Yes Yes Yes Yes Yes

Thuộc tính

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

Thuộc tính toàn cầu

Thẻ <fieldset>cũng hỗ trợ Thuộc tính chung trong HTML .


Thuộc tính sự kiện

Thẻ <fieldset>cũng hỗ trợ Thuộc tính sự kiện trong HTML .



Các ví dụ khác

Thí dụ

Sử dụng CSS để tạo kiểu cho <fieldset> và <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>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>

Các trang liên quan

Tham chiếu DOM HTML: Đối tượng Fieldset


Cài đặt CSS mặc định

Hầu hết các trình duyệt sẽ hiển thị <fieldset>phần tử với các giá trị mặc định sau:

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);
}