- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <legend> Tag
HTML <legend> tag is used to specify the caption of <fieldset> element. It typically rests on top of the frame because it is a caption. A border is drawn around an element's content using the <fieldset> tag on that border we can set the caption using the <legend> tag. It helps us to indentify the wraped group by following that caption set by the legend tag.
Syntax
<legend>.......</legend>
Attribute
HTML legend tag supports Global and Event attributes of HTML. And a specific attribute as well which are listed bellow.
Attribute | Value | Description |
---|---|---|
align | left right center justify |
This is used to set the alignment of the element horizontally. |
Examples of HTML legend Tag
Bellow examples will illustrate the usage of legend tag. Where, when and how to use it to create caption and how we can style that caption using CSS.
Creating caption using <legend> tag
In the following example, we are using the HTML <legend> tag to define the caption for its parent <fieldset> tag. The legend tag can be used on any element to give a caption but better to use it with fieldset elements.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML legend tag</title> </head> <body> <fieldset> <!-- Using legend Tag to Create Caption --> <legend>Cpation</legend> </fieldset> </body> </html>
Styling the caption using CSS
In this example, we are using the HTML <legend> tag to create a caption named "Message" for its parent tag <fieldset>. Using the CSS, we are trying to give some styling to the HTML <legend> tag.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML legend tag</title> <style> legend { color: blue; font-size: 25px; width: 100px; background-color: aquamarine; padding-left: 5px; } </style> </head> <body> <fieldset> <!-- Using legend Tag to Create Caption --> <legend>Message</legend> <p> Tutorials Point is an online learning platform providing free tutorials, paid premium courses, and eBooks. Learn the latest technologies and programming languages SQL, MySQL, Python, C, C++, Java, Python, PHP, Machine Learning, data science, AI, Prompt Engineering and more. </p> </fieldset> </body> </html>
Caption on a Login form
Considering the following example, we are creating a caption(title) named "User Details" for HTML <fieldset> element using the HTML <legend> tag. The created caption will represent the title of the form.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML legend tag</title> <style> legend { color: rgb(168, 10, 193); font-size: 25px; width: 100px; background-color: rgb(164, 205, 14); } fieldset{ width: 50%; } label{ font-size: 24px; } input { border-radius: 5px; width: 95%; } </style> </head> <body> <fieldset> <!-- Using legend Tag to Create Caption and align attribute to align the caption --> <legend align="center">Login</legend> <form> <label for="">Username</label> <br> <input type="text"> <br> <label for="">Password</label> <br> <input type="password"> <br><br> <button>Submit</button> </form> </fieldset> </body> </html>
Supported Browsers
Tag | |||||
---|---|---|---|---|---|
legend | Yes | Yes | Yes | Yes | Yes |
To Continue Learning Please Login
Login with Google