Thead

Struct Thead 

Source
pub struct Thead;
Expand description

The <thead> element - groups header rows in a table.

§Purpose

The <thead> element groups one or more <tr> elements that contain table headers. It defines the header section of a table, typically containing column labels. Browsers can use this to enable scrolling of the table body independently of the header, and to repeat headers when printing multi-page tables.

§Content Categories

  • None (only valid within <table>)

§Permitted Content Model

  • Zero or more <tr> elements

§Common Use Cases

  • Defining column headers for tables
  • Creating sticky headers that remain visible while scrolling
  • Enabling header repetition in printed tables
  • Semantically separating headers from data
  • Styling table headers distinctly from data

§Key Attributes

  • Global attributes only

§Example

<!-- Basic table header -->
<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Email</th>
      <th>Role</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>John Doe</td>
      <td>john@example.com</td>
      <td>Developer</td>
    </tr>
  </tbody>
</table>

<!-- Multi-row header -->
<table>
  <thead>
    <tr>
      <th rowspan="2">Name</th>
      <th colspan="2">Contact</th>
    </tr>
    <tr>
      <th>Email</th>
      <th>Phone</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Alice</td>
      <td>alice@example.com</td>
      <td>555-0001</td>
    </tr>
  </tbody>
</table>

<!-- Sticky header -->
<table>
  <thead style="position: sticky; top: 0; background: white;">
    <tr>
      <th>Product</th>
      <th>Price</th>
      <th>Stock</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Widget</td>
      <td>$10</td>
      <td>50</td>
    </tr>
    <!-- Many more rows... -->
  </tbody>
</table>

§Accessibility

  • Use <th> elements within <thead> for proper header semantics
  • Add scope attributes to header cells for complex tables
  • Ensure header text is descriptive and concise

§WHATWG Specification

Trait Implementations§

Source§

impl HtmlElement for Thead

Source§

const TAG: &'static str = "thead"

The HTML tag name (e.g., “div”, “span”, “img”).
Source§

const VOID: bool = false

Whether this is a void element (self-closing, no children allowed).
Source§

impl CanContain<Script> for Thead

Source§

impl CanContain<Template> for Thead

Source§

impl CanContain<Thead> for Table

Source§

impl CanContain<Tr> for Thead

Auto Trait Implementations§

§

impl Freeze for Thead

§

impl RefUnwindSafe for Thead

§

impl Send for Thead

§

impl Sync for Thead

§

impl Unpin for Thead

§

impl UnwindSafe for Thead

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.