Introduction to <thead>tag

The <thead>tag in HTML is used to group the header content of a table. It helps to improve the readability and organization of a table by clearly defining the section that contains column headings.

Copy to clipboard
<!DOCTYPE html>
    <html lang="en">
    <head>
      <!-- Basic Meta Tags -->
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <meta name="description" content="A modern and attractive table design using advanced CSS within a style tag, including styled <th> elements.">
      
      <!-- Title of the Page -->
      <title>title of <thead> tag</title>
    </head>
    <body>
    
      <!-- Table Example -->
      <table class="modern-table">
        <thead>
          <tr>
            <th>Name</th>
            <th>Age</th>
            <th>City</th>
            <th>Occupation</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td data-label="Name">John Doe</td>
            <td data-label="Age">30</td>
            <td data-label="City">New York</td>
            <td data-label="Occupation">Software Engineer</td>
          </tr>
          <tr>
            <td data-label="Name">Jane Smith</td>
            <td data-label="Age">25</td>
            <td data-label="City">San Francisco</td>
            <td data-label="Occupation">Graphic Designer</td>
          </tr>
          <tr>
            <td data-label="Name">Emily Johnson</td>
            <td data-label="Age">40</td>
            <td data-label="City">Los Angeles</td>
            <td data-label="Occupation">Marketing Manager</td>
          </tr>
          <tr>
            <td data-label="Name">Michael Brown</td>
            <td data-label="Age">35</td>
            <td data-label="City">Chicago</td>
            <td data-label="Occupation">Product Manager</td>
          </tr>
        </tbody>
        <tfoot>
          <tr>
            <td colspan="4">Total Employees: 4</td>
          </tr>
        </tfoot>
      </table>
    
    </body>
    </html>
Copy to clipboard
body {
      font-family: 'Roboto', sans-serif;
      background: linear-gradient(135deg, #1e3c72, #2a5298, #ff6e7f, #bfe9ff);
      background-size: 400% 400%;
      color: #333;
      margin: 0;
      padding: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
      animation: gradientShift 15s ease infinite;
    }
    
    /* Keyframes for Gradient Animation */
    @keyframes gradientShift {
      0% { background-position: 0% 50%; }
      50% { background-position: 100% 50%; }
      100% { background-position: 0% 50%; }
    }
    
    /* Modern Table Styling */
    .modern-table {
      width: 90%;
      max-width: 1000px;
      border-collapse: collapse;
      background-color: #fff;
      border-radius: 12px;
      overflow: hidden;
      box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
    }
    
    .modern-table thead {
      background: linear-gradient(to right, #007bff, #00c6ff);
      color: white;
      text-transform: uppercase;
      letter-spacing: 0.1em;
      font-size: 0.9rem;
    }
    
    .modern-table thead th {
      padding: 15px;
      font-weight: bold;
      text-align: left;
      border-bottom: 2px solid #006bb3;
      border-right: 1px solid #006bb3;
    }
    
    .modern-table thead th:last-child {
      border-right: none; /* Remove right border from the last header cell */
    }
    
    .modern-table tbody {
      background-color: #f9f9f9;
    }
    
    .modern-table tbody tr {
      transition: background-color 0.3s ease;
    }
    
    .modern-table tbody tr:hover {
      background-color: #f1f1f1;
    }
    
    .modern-table tbody td {
      padding: 15px;
      color: #333;
      border-bottom: 1px solid #dddddd;
      border-right: 1px solid #dddddd;
    }
    
    .modern-table tbody td:last-child {
      border-right: none; /* Remove the right border from the last column */
    }
    
    .modern-table tbody tr:last-child td {
      border-bottom: none; /* Remove the bottom border from the last row */
    }
    
    /* Tfoot Styling */
    .modern-table tfoot {
      background-color: #007bff;
      color: white;
      text-align: right;
      font-size: 1rem;
    }
    
    .modern-table tfoot td {
      padding: 15px;
      font-weight: bold;
      border-top: 2px solid #006bb3;
      border-right: 1px solid #006bb3;
    }
    
    .modern-table tfoot td:last-child {
      border-right: none; /* Remove the right border from the last column in the footer */
    }
    
    /* Responsive Table */
    @media (max-width: 768px) {
      .modern-table, .modern-table thead, .modern-table tbody, .modern-table th, .modern-table td, .modern-table tr {
        display: block;
        width: 100%;
      }
    
      .modern-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
      }
    
      .modern-table tr {
        margin: 0 0 1rem 0;
        border-bottom: 1px solid #ddd;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
      }
    
      .modern-table td {
        border: none;
        position: relative;
        padding-left: 50%;
        text-align: right;
        border-right: none;
      }
    
      .modern-table td::before {
        position: absolute;
        top: 50%;
        left: 10px;
        transform: translateY(-50%);
        width: 45%;
        white-space: nowrap;
        content: attr(data-label);
        font-weight: bold;
        text-align: left;
      }
    }

Global Attributes

AttributesDescription
accesskeySpecifies a shortcut key to activate or focus an element.
autocapitalizeControls whether and how text input is automatically capitalized.
classSpecifies one or more class names for the element, allowing CSS styling and JavaScript manipulation.
contenteditableSpecifies whether the content of an element is editable or not.
contextmenuSpecifies a context menu for the element.
dirDefines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto".
draggableSpecifies whether an element is draggable. Possible values are "true" or "false".
enterkeyhintSpecifies the action label or icon to be shown for the enter key on virtual keyboards.
hiddenIndicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set.
idSpecifies a unique identifier for the element.
inputmodeProvides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants.
isAllows you to specify the type of custom element.
langSpecifies the language of the element's content.
nonceA cryptographic nonce ("number used once") that can be used by Content Security Policy (CSP) to determine whether or not a given fetch will be allowed to proceed.
partSpecifies the element’s part in the shadow DOM.
slotAssigns a slot in a shadow DOM shadow tree.
spellcheckIndicates whether the element is subject to spell checking.
styleProvides inline CSS styling for the element.
tabindexSpecifies the tab order of the element.
titleAdds extra information about the element, displayed as a tooltip when hovering over the element.
translateSpecifies whether the content of the element should be translated. Possible values are "yes" or "no".
HTML AttributesGlobal AttributesEvent Attributes
To view the full list
To view the full list
To view the full list
elementsChrome BrowsersMicrosoft Edge BrowserFirefox BrowsersSafari BrowserOpera Browser
<thead>YesYesYesYesYes