Td

Struct Td 

Source
pub struct Td;
Expand description

The <td> element - defines a data cell in a table.

§Purpose

The <td> element represents a data cell in a table. It contains the actual data values within table rows. Can span multiple rows or columns using rowspan and colspan attributes. Distinguished from <th> header cells which label data.

§Content Categories

  • Sectioning Root

§Permitted Content Model

  • Flow content

§Common Use Cases

  • Displaying data values in tables
  • Creating spreadsheet cells
  • Showing individual records in datasets
  • Building data grids and matrices
  • Presenting structured information

§Key Attributes

  • colspan: Number of columns the cell spans
  • rowspan: Number of rows the cell spans
  • headers: Space-separated list of header cell IDs this cell relates to

§Example

<!-- Basic data cells -->
<table>
  <tr>
    <th>Name</th>
    <th>Score</th>
  </tr>
  <tr>
    <td>Alice</td>
    <td>95</td>
  </tr>
  <tr>
    <td>Bob</td>
    <td>87</td>
  </tr>
</table>

<!-- Cells with colspan -->
<table>
  <tr>
    <td colspan="2">This cell spans two columns</td>
  </tr>
  <tr>
    <td>Column 1</td>
    <td>Column 2</td>
  </tr>
</table>

<!-- Cells with rowspan -->
<table>
  <tr>
    <td rowspan="2">Spans 2 rows</td>
    <td>Row 1, Col 2</td>
  </tr>
  <tr>
    <td>Row 2, Col 2</td>
  </tr>
</table>

<!-- Complex table with headers attribute -->
<table>
  <thead>
    <tr>
      <th id="name">Name</th>
      <th id="math">Math</th>
      <th id="science">Science</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th id="alice">Alice</th>
      <td headers="alice math">95</td>
      <td headers="alice science">92</td>
    </tr>
  </tbody>
</table>

<!-- Rich content in cells -->
<table>
  <tr>
    <td>
      <strong>Product Name</strong><br>
      <small>SKU: 12345</small>
    </td>
    <td>
      <a href="/details">View Details</a>
    </td>
  </tr>
</table>

§Accessibility

  • Use headers attribute to associate cells with headers in complex tables
  • Ensure data cells are properly associated with their headers
  • Keep cell content concise and scannable
  • Use scope on header cells to clarify relationships

§WHATWG Specification

Trait Implementations§

Source§

impl HtmlElement for Td

Source§

const TAG: &'static str = "td"

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<T: FlowContent> CanContain<T> for Td

Source§

impl CanContain<Td> for Tr

Source§

impl CanContain<Text> for Td

Auto Trait Implementations§

§

impl Freeze for Td

§

impl RefUnwindSafe for Td

§

impl Send for Td

§

impl Sync for Td

§

impl Unpin for Td

§

impl UnwindSafe for Td

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.