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.
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>
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.
<thead style="CSS-styles">
Value | Description |
---|---|
CSS-styles | One or more CSS property/value pairs separated by semicolons (;). |
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>
The style attribute assigns a background color to the <thead> element.
Clicking the button calls JavaScript which toggles the background to another color.
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 |
Back to <thead>