Copied successfully!
Introduction to <th>
tag
The <th>tag in HTML stands for "table header." It is used to define header cells in a table, typically containing information that describes the content of the column or row it heads. The <th>element is essential for creating accessible and semantically meaningful tables, providing context to users and search engines.
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 <th> 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
Attributes | Description |
---|---|
accesskey | Specifies a shortcut key to activate or focus an element. |
autocapitalize | Controls whether and how text input is automatically capitalized. |
class | Specifies one or more class names for the element, allowing CSS styling and JavaScript manipulation. |
contenteditable | Specifies whether the content of an element is editable or not. |
contextmenu | Specifies a context menu for the element. |
dir | Defines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto". |
draggable | Specifies whether an element is draggable. Possible values are "true" or "false". |
enterkeyhint | Specifies the action label or icon to be shown for the enter key on virtual keyboards. |
hidden | Indicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set. |
id | Specifies a unique identifier for the element. |
inputmode | Provides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants. |
is | Allows you to specify the type of custom element. |
lang | Specifies the language of the element's content. |
nonce | A 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. |
part | Specifies the element’s part in the shadow DOM. |
slot | Assigns a slot in a shadow DOM shadow tree. |
spellcheck | Indicates whether the element is subject to spell checking. |
style | Provides inline CSS styling for the element. |
tabindex | Specifies the tab order of the element. |
title | Adds extra information about the element, displayed as a tooltip when hovering over the element. |
translate | Specifies whether the content of the element should be translated. Possible values are "yes" or "no". |
HTML Attributes | Global Attributes | Event Attributes |
---|---|---|
To view the full list | To view the full list | To view the full list |
elements | |||||
---|---|---|---|---|---|
<th> | Yes | Yes | Yes | Yes | Yes |
Improve Our Platform
Did you find what you were looking for?
Learn how to contribute.Last updated on by our contributors.
View this page on GitHub• Report an issue with this content