Thẻ <legend> trong HTML được dùng để đặt tiêu đề (caption) cho phần tử <fieldset>. Vai trò của fieldset là nhóm các phần tử như button, input, radio, v.v.
Cú pháp
Cú pháp như sau:
<fieldset> <legend> Đặt tiêu đề </legend> </fieldset>
Ví dụ
Ví dụ triển khai thẻ <legend>:
<!DOCTYPE html> <html> <body>
<h2>Xếp hạng theo môn học</h2>
<form>
<fieldset>
<legend>Xếp hạng (tiêu đề)</legend>
<label for="stinfo">Học sinh:</label>
<input type="text" id="stinfo" value="Steve"><br>
<label for="sub">Môn học:</label>
<input type="text" value="Khoa học"><br>
<label for="rank">Xếp hạng:</label>
<input type="number" value="1"><br>
<label for="marks">Điểm:</label>
<input type="number" value="98"><br>
</fieldset>
</form>
</body> </html>
Kết quả
Đoạn mã trên sẽ tạo ra kết quả như sau:

Trong ví dụ trên, chúng ta đặt tiêu đề dùng <legend> bên trong <fieldset>:
<fieldset> <legend>Xếp hạng (tiêu đề)</legend> ...các phần tử form... </fieldset>
<fieldset> nhóm các phần tử form bên trong <form>:
<form> <fieldset> <legend>Xếp hạng (tiêu đề)</legend> ...các phần tử form... </form>