
- 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 - <caption> Tag
Introduction to <caption> Tag
The HTML <caption> tag is used to provide a title or descriptive headings for a <table> element. It provides context to the tables content and helps users to understand its purpose. It is placed directly after the <table> tag and before any other table elements, such as <thead> or <tr>.
The <caption> tag improves the accessibility of a webpage, making the tables easier to understand for screen readers. By default, it is displayed above the table, but its position can be altered using CSS.
Syntax
Following is the syntax of HTML <caption> tag −.
<caption> ..... </caption>
Attributes
HTML caption tag supports Global and Event attributes of HTML. A Specific attribute as well which is listed bellow.
Attribute | Value | Description |
---|---|---|
align | left right center justify |
Specifies the alignment of text content(Deprecated). |
Example : Basic Usage
Let's look at the following example, where we are going to consider the basic usage of the <caption> tag.
<!DOCTYPE html> <html> <body> <style> table, td, th { border: 4px solid #D2B4DE; border-collapse: collapse; } </style> <table> <caption>Monthly Sales</caption> <tr> <th>Month</th> <th>Sales</th> </tr> <tr> <td>October</td> <td>$10,000</td> </tr> <tr> <td>November</td> <td>$20,000</td> </tr> <tr> <td>December</td> <td>$30,000</td> </tr> </table> </body> </html>
Example : Applying with CSS
Consider the following example, where we are going to apply the CSS on the <caption> tag.
<!DOCTYPE html> <html> <body> <style> table, td, th { border: 4px solid #D2B4DE; border-collapse: collapse; } caption { font-weight: bold; color: blue; text-align: center; } </style> <table> <caption>Students Grades</caption> <tr> <th>Name</th> <th>Grade</th> </tr> <tr> <td>Ramu</td> <td>A+</td> </tr> <tr> <td>Sunitha</td> <td>A</td> </tr> </table> </body> </html>
Example : Using id Attribute
In the following example, we are going to use the id attribute along with the <caption> tag.
<!DOCTYPE html> <html> <body> <style> table, td, th { border: 4px solid #D2B4DE; border-collapse: collapse; } </style> <table> <caption id="tp">Bills</caption> <tr> <th>Product</th> <th>Amount</th> </tr> <tr> <td>pencils</td> <td>10</td> </tr> <tr> <td>Pens</td> <td>25</td> </tr> </table> <script> document.getElementById('tp').style.color = 'green'; </script> </body> </html>
Supported Browsers
Tag | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
caption | Yes | Yes | Yes | Yes | Yes |