
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- 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
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How to add one or more header cells a cell is related to in HTML?
The headers attribute in HTML text along with the td and th tags allows us to add one or more header cells. It holds the value header id, which specifies a list of ids for one or more header cells that the table header cell is associated to, separated by spaces.
Syntax
<td headers="header_id"> Content..</td>
Following are the examples…
Example
In the following example we are using headers to add required headercells in our table.
<!DOCTYPE html> <html> <style> table { border: 3px solid black; } td { border: 1px solid green; text-align: center; } </style> <body> <center> <table style="width:500px"> <tr> <th id="CARS" colspan="3"> LIST OF CARS </th> </tr> <tr> <td Headers="CARS">BENTLEY</td> <td Headers="CARS">AUDI RS7</td> <td Headers="CARS">DUCATI</td> </tr> <tr> <th id="BIKES" colspan="3"> LIST OF BIKES </th> </tr> <tr> <td Headers="BIKES">KAWASAKI</td> <td Headers="BIKES">HAYABUSA</td> <td Headers="BIKES">DODGE TOMAHAWK</td> </table> </center> </body> </html>
Output
On executing the above script, the table was created with different header cells in our web page.
Example
Another example using the headers attribute is given below −
<!DOCTYPE html> <html> <head> <style> table, th, td { border: 2px solid blue; } </style> </head> <body> <table style = "width:100%"> <tr> <th id = "name">Subject ID</th> <th id = "email">Subject Name</th> </tr> <tr> <td headers = "name">001</td> <td headers = "email">Mathematics</td> </tr> </table> </body> </html>
Output
On executing the above script, the output is obtained in the form of a table with two columns subject ID and subject name with header consisting the name and email address of students.
- Related Articles
- How To Add Text Cells Together Into One Cell In Excel?
- How do we specify whether a header cell is a header for a column, row, or group of columns or rows in HTML?
- How to pass more than one header in a request in Rest Assured?
- How to Convert One Cell to Multiple Cells/Rows in Excel?
- How to add header or footer to all worksheets/pages in Excel?
- How to create a header cell in a table using HTML5
- How to Add Prefix or Suffix to a Range of Cells in Excel
- How to add header or footer to first page only in an Excel worksheet?
- How to add header row to a Pandas Dataframe?
- How to create table header in HTML?
- In HTML how to create table header?
- How to add two or more strings in MySQL?
- Is it possible to add a set of elements in one cell with MySQL?
- How to add header item for Listview in Android?
- How to Convert an Excel Sheet or Cells to an HTML Table?

Advertisements