
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- 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 Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- 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 - Document Object Model (DOM)
- 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 Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character 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 - <label> Tag
The HTML <label> tag is used to represent a caption for an item in a UI(user interface), or to add labels to form controls like text, textarea, checkbox, radio button, etc.
The for attribute is a default attribute of the <label> tag, and is automatically added when creating the <label> tag. Multiple label elements can have the same value for their <for> attribute.
To explicitly associate a <label> element with an <input> element, first add an id attribute to the <input> element. Then, add the for attribute to the <label> tag, ensuring the value of the for attribute matches the id of the <input> element.
Syntax
Following is the syntax of <label> tag −
<label> ... </label>
Attributes
The HTML <label> tag supports Global and Event attributes of HTML. It also accept specific, which are listed bellow.
Attribute | Value | Description |
---|---|---|
form | form_id | Specifies one or more forms to which the label belongs. |
for | element_id | Specifies the input control associated with this label. The value must match the "id" attribute of the input control. |
Example: Creating <label> Element
In the following program, we use the <label> tag to create a label in HTML without any attributes. Running the code will generate an output displaying the label field on the webpage.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML Label tag</title> </head> <body> <label>Your name: </label> </body> </html>
Example: Styling <label> Element
Here is another example of the HTML <label> tag. We are creating a table using the <label> tag and applying CSS for styling. Running the code will display the label field styled with CSS on the webpage.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML Label tag</title> <style> label { font-size: 20px; font-style: italic; color: green; } </style> </head> <body> <label for="name">Name: </label> </body> </html>
Example: Including <label> into Form
Here is another example of the HTML <label> tag. We are creating a table using the <label> tag and applying CSS for styling. Running the code will display the label field styled with CSS on the webpage.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML Label tag</title> <style> form { width: 250px; height: 180px; border: 1px solid green; } label { color: blueviolet; font-size: 20px; } </style> </head> <body> <form> <label for="uname">Username: </label> <input type="text" id='uname'> <br> <label for="lang">Chose languages: </label> <br> <input type="checkbox" id='english'> <label for="english">English</label> <br> <input type="checkbox" id='hindi'> <label for="hindi">Hindi</label> <br> <label for="intro">Your short intro....</label> <br> <textarea id='intro'></textarea> </form> </body> </html>
Supported Browsers
Tag | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
label | Yes | Yes | Yes | Yes | Yes |