HTML Table Headers: A Comprehensive Guide

0
11كيلو بايت

HTML table headers are used to define the columns or rows of a table. They are typically styled differently from data cells to visually distinguish them.

Basic Usage

HTML
<table>
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
    <th>Header 3</th>
  </tr>
  <tr>
    <td>Cell 1</td>
    <td>Cell 2</td>
    <td>Cell 3</td>
  </tr>
</table>

In the example above, <th> tags are used to create the table headers.

Styling Headers

You can style table headers using CSS properties like:

  • font-weight: Sets the font weight (e.g., bold).
  • text-align: Sets the text alignment (e.g., center).
  • background-color: Sets the background color.
  • color: Sets the text color.

Example with Styling

HTML
<table>
  <tr>
    <th style="font-weight: bold; text-align: center; background-color: #f2f2f2;">Header 1</th>
    <th style="font-weight: bold; text-align: center; background-color: #f2f2f2;">Header 2</th>
    <th style="font-weight: bold; text-align: center; background-color: #f2f2f2;">Header 3</th>
  </tr>
  <tr>
    <td>Cell 1</td>
    <td>Cell 2</td>
    <td>Cell 3</td>
  </tr>
</table>

Header Scope

The scope attribute of the <th> element can be used to specify the scope of a header. This information is helpful for screen readers and assistive technologies.

  • col: Indicates that the header is related to a column.
  • row: Indicates that the header is related to a row.

Example with Scope

HTML
<table>
  <thead>
    <tr>
      <th scope="col">Header 1</th>
      <th scope="col">Header 2</th>
      <th scope="col">Header 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Cell 1</td>
      <td>Cell 2</td>
      <td>Cell 3</td>   
    </tr>
  </tbody>
</table>

The <thead>, <tbody>, and <tfoot> Elements

  • <thead>: Contains the table header rows.
  • <tbody>: Contains the table body rows.
  • <tfoot>: Contains the table footer rows.

By using these elements and styling techniques, you can create visually appealing and informative table headers that enhance the readability and usability of your HTML tables.

Like
1
البحث
الأقسام
إقرأ المزيد
Computer Programming
HTML Table Borders: A Closer Look
HTML table borders are used to outline the individual cells and rows within a table, making it...
بواسطة HTML PROGRAMMING LANGUAGE 2024-09-06 01:25:50 0 11كيلو بايت
Technology
Decision Support Systems (DSS)
Decision Support Systems (DSS) are computerized information systems designed to assist in...
بواسطة Business Information Systems (BIS) Course 2024-08-01 17:00:08 0 9كيلو بايت
Business
Small Businesses: The Backbone of the Economy and Pillars of Community Growth
In the intricate fabric of our global economy, small businesses are the threads that hold it...
بواسطة ALAGAI AUGUSTEN 2024-08-03 15:15:09 0 10كيلو بايت
Chemistry
S.4 CHEMISTRY WAKATA PRE MOCK QUESTIONS 2
https://acrobat.adobe.com/id/urn:aaid:sc:EU:85bd6cfc-45b5-4737-b430-d0e1fce698e9
بواسطة Landus Mumbere Expedito 2024-07-19 23:27:53 0 9كيلو بايت
Technology
Ethical Code of Conduct
An ethical code of conduct is a set of principles and guidelines designed to help professionals...
بواسطة ALAGAI AUGUSTEN 2024-07-16 17:00:57 0 9كيلو بايت
Tebtalks https://forum.tebtalks.com