Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <thead> style Attribute

A style attribute on a <thead> tag assigns a unique style to the table header.

Its value is CSS that defines the appearance of the thead element.

Example

#

A style attribute on a <thead> element.

First name Last name
Denice Hobermann
Paulo Cornell
<style>
  table.tb { width:300px; border-collapse: collapse; }
  .tb th, .tb td { border: solid 1px #777; padding: 5px; }
</style>

<table class="tb">
  <thead style="background: navy; color: white;">
    <tr>
      <th>First name</th>
      <th>Last name</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>Denice</td>
      <td>Hobermann</td>
    </tr>
    <tr>
      <td>Paulo</td>
      <td>Cornell</td>
    </tr>
  </tbody>
</table>

Using style

The style attribute specifies the style, i.e. look and feel, of the <thead> element.

A style contains any number of CSS property/value pairs, separated by semicolons (;).

The style attribute overrides any other style that was defined in a <style> tag or an external CSS file.

This inline styling affects the current <thead> element only.


Syntax

<thead style="CSS-styles">

Values

#

Value Description
CSS-styles One or more CSS property/value pairs separated by semicolons (;).

More Examples

A style attribute on a <thead> element.
Clicking the button toggles the background color.

First name Last name
Denice Hobermann
Paulo Cornell

<style>
  table.tbl { width:300px; border-collapse: collapse; }
  .tbl th, .tbl td { border: solid 1px #777; padding: 5px; }
</style>

<table class="tbl">
  <thead id="mythead" style="background: navy; color:white;">
    <tr>
      <th>First name</th>
      <th>Last name</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>Denice</td>
      <td>Hobermann</td>
    </tr>
    <tr>
      <td>Paulo</td>
      <td>Cornell</td>
    </tr>
  </tbody>
</table>

<br />
<button type="button" onclick="toggle();">Toggle style</button>

<script>
  let toggle = () => {
     let element = document.getElementById("mythead");

     if (element.style.backgroundColor === "navy") {
       element.style.backgroundColor = "royalblue";
    } else {
       element.style.backgroundColor = "navy";
    }
  }
</script>

Code explanation

The style attribute assigns a background color to the <thead> element.

Clicking the button calls JavaScript which toggles the background to another color.


Browser support

Here is when style support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <thead>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides