- 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 - <caption> Tag
The HTML <caption> tag is used to specify a caption for the <table> element. It serves as the table's title. It should be used inside the <table> element, immediately following the start tag for the table. There can only be one <caption> element per table. When the data in the table is unclear, the <caption> element might be useful. After defining the caption to the table element, one can describe the type of data in the table.
A table caption will always be centred above a table by default. To align and position the caption, you can use the CSS properties text-align and caption-side.
Syntax
Following is the syntax for HTML <caption> −
<caption> ....... </caption>
Example
Let's consider the following example, where we are going to use the <caption>.
<!DOCTYPE html> <html> <body> <style> table, td, th { border: 4px solid #D2B4DE; border-collapse: collapse; } </style> <table> <caption>Employee Details</caption> <tr> <th>Name</th> <th>Department</th> <th>Age</th> </tr> <tr> <td>Suma</td> <td>IT</td> <td>23</td> </tr> <tr> <td>Priya</td> <td>Development</td> <td>26</td> </tr> <tr> <td>Viswa</td> <td>BPO</td> <td>23</td> </tr> </table> </body> </html>
On running the above code, the output window will pop up, displaying the table applied with a caption on the webpage.
Example
Considering another scenario where we are going to use the CSS caption-side property.
<!DOCTYPE html> <html> <style> caption { background: #27AE60; color: #F7F9F9; caption-side: bottom; } table, th, td { border: 2px solid #5DADE2; padding: 2px; } </style> <body> <table> <caption>TUTORIALSPOINT</caption> <tr> <th>Courses</th> <th>Price</th> </tr> <tr> <td>HTML</td> <td>100</td> </tr> <tr> <td>JAVA</td> <td>90</td> </tr> </table> </body> </html>
When we execute the above code, it will generate an output consisting of the table applied with CSS and the caption of the table applied at the bottom displayed on the webpage.
Example
In the following example, we are going to use the CSS property to make the caption align to the left.
<!DOCTYPE html> <html> <body> <style> table, td, th { border: 2px solid #82E0AA; } </style> <table> <caption style="text-align: left"> TFI </caption> <tr> <th>Actor</th> <th>Movie</th> <th>Age</th> </tr> <tr> <td>Pavankalyan</td> <td>Jalsa</td> <td>25</td> </tr> <tr> <td>Ram</td> <td>Hyper</td> <td>28</td> </tr> <tr> <td>Arjun</td> <td>Bunny</td> <td>26</td> </tr> </table> </body> </html>
On running the above code, the output window will pop up, displaying the table along with a caption that is aligned to the left of the table.
Example
Following is an example where we are going to use the CSS property and align the caption to the right.
<!DOCTYPE html> <html> <style> table, td, th { border: 2px solid #5DADE2; } .tutorial { text-align: right; color: #4A235A; background-color: #E5E8E8; } </style> <body> <table> <caption class="tutorial"> Cars And Countries </caption> <thead> <tr> <th>Name</th> <th>Country</th> <th>Engine</th> </tr> </thead> <tbody> <tr> <td>Lamborghini</td> <td>Italy</td> <td>V12</td> </tr> <tr> <td>Volkswagen</td> <td>Germany</td> <td>1.4 TSI/TFSI</td> </tr> <tr> <td>Chevrolet</td> <td>United States</td> <td>1199 cc, 4 Cylinders Inline</td> </tr> </tbody> </table> </body> </html>
When we execute the above code, it will generate an output consisting of a table along with the caption aligned to the right displayed on the webpage.