Tag th In HTML
The purpose of this post is to explore Tag th <th> with examples so that it may be of assistance to you.
The <th> tag in HTML is used to define a header cell in a table. It is used in combination with the <tr> and <td> tags to structure tabular data and provide additional context and information to users
Tag th stands for table head – The following is an basic HTML table with rows and table head cells:
Example: 
An example of a table with two rows and two head cells, with the content inside the head cells aligned to the center with CSS:
Example: 
Here is an example to creation of table headers in HTML table:
Example: 
Here is an example of how to create a table with a caption in HTML:
Example: 
Here is an example of how the <th> tag can be used to create a unique table cell in HTML:
Example: 
You can use the vertical align property in CSS to align the content inside a <th> ement vertically. Here is an example:
Example: 
You can use the width property in CSS to set the width of a table header cell <th> tag. Here is an example:
Example: 
Table cells can span several rows or columns using the <rowspan> and <colspan> attributes on the <td> and <th> elements.
Below table has cells that span rows and columns:
Example: 
Tag th Usage
The Tag th <th> indicates a regular header cell in an HTML table.
There are two types of cells in an HTML table:
- The header cells – hold the header information (made by the <th> tag)
- The data cell – holds data (made with the <td> element)
Whenever we discuss of Tag <th>, the text in <th> tags is automatically bold and centered. Text within <th> elements is standard and aligned to the left as default.
Common Uses
Here are some of the main uses of the <th> tag:
- The <th> tag is commonly used to define the header cells in a table. By using <th> cells, developers can provide additional context and information about the data in the table, such as column or row titles, data units, or data types. This can make the table easier to understand and interpret for users.
- The use of <th> cells in tables can help to improve the accessibility of web pages for users who rely on assistive technologies, such as screen readers. By using <th> cells to structure table data, developers can provide additional information about the table structure and data, which can help to improve the user experience for all users.
- The <th> tag can be styled differently from the <td> tag, which is used for regular table cells. This can help to distinguish the header cells from the data cells in the table, making the table easier to read and understand.
- Many table sorting plugins and libraries use the <th> tag to identify the header cells that can be used for sorting. By adding sorting functionality to tables, users can more easily manipulate and analyze the data presented in the table.
Attributes
Global
The Tag th <th> are compatible with the Global Attributes in HTML.
Event
The Tag <th> also accepts the Event Attributes in HTML.
Attributes List
Attribute | Value | Overview |
---|---|---|
abbr | text | Indicates an abbreviated form of the text that appears in a header cell. |
colspan | number | Determines how many columns a cell should have |
headers | header_id | Indicates which header cells a cell belongs to |
rowspan | number | Determine how many rows should be displayed in a cell |
scope | col colgroup row rowgroup | Describes if a header cell is a header for a column, row, or collection of columns or rows. |
Browser Compatibility
Element | |||||
---|---|---|---|---|---|
<th> | Yes | Yes | Yes | Yes | Yes |
Predefined CSS
The following Tag <th> values are used by major browsers for displaying the <th> element:
th { display: table-cell; vertical-align: inherit; font-weight: bold; text-align: center; }
HTML Tag th Benefits
The <th> tag in HTML has several benefits, including:
- By using <th> cells to define the header cells in a table, developers can improve the readability of the table for users. The use of header cells can help to provide context and information about the data in the table, making it easier to understand and interpret.
- The use of <th> cells in tables can help to improve the accessibility of web pages for users who rely on assistive technologies, such as screen readers. By providing additional information about the structure and data of the table, users with disabilities can more easily understand and navigate the content.
- The <th> tag is often used to identify header cells that can be used for sorting. This can be useful for users who need to analyze and manipulate large amounts of data in the table.
- The <th> tag can be styled differently from the <td> tag, which is used for regular table cells. This can help to distinguish the header cells from the data cells in the table, making the table easier to read and understand.
- The use of <th> cells in tables can improve the semantic structure of the HTML document. By using the appropriate HTML tags for different types of content, developers can create documents that are more easily understood by both humans and machines.