td

The td element defines a data cell in a table. Vanilla Breeze styles cells with a thin bottom border and top vertical alignment. Supports data attributes for numeric alignment, custom sort/filter values, and responsive card-mode labels.

Description

The <td> (table data) element contains a cell of data in a table. Data cells are associated with header cells (<th>) through the table structure, primarily via the scope attribute on headers.

Vanilla Breeze styles data cells with consistent padding (var(--size-s) var(--size-m)), top vertical alignment, and a thin bottom border (var(--border-width-thin)). Row hover effects highlight the entire <tr> containing the cell.

When to Use

  • Data values: All cells containing actual data (not headers)
  • tbody cells: The primary content within <tbody> rows
  • tfoot cells: Summary/total values in <tfoot>
  • Empty cells: Placeholder cells to maintain column alignment (use "N/A" or "-" rather than leaving blank)

When to Use th Instead

Examples

Basic Data Cells

Data cells contain the values described by column and row headers.

Numeric Data

Use the data-numeric attribute for cells containing numbers. This right-aligns the content and applies font-variant-numeric: tabular-nums so digits align vertically across rows.

Explicit Alignment

Use data-align when the default (start) or data-numeric (end) are not appropriate for the content.

Custom Sort Values

Use data-sort-value when the display text differs from the value that should be used for sorting. The <data-table> component reads this attribute during sort operations.

Custom Filter Values

Use data-filter-value when the cell's display content does not capture all the text a user might search for. The <data-table> component uses this for its filter/search feature.

Responsive Card-Mode Labels

On narrow screens, the <data-table> component can switch from a traditional table layout to a stacked card layout. Add data-label to each <td> to provide the column header text that appears as a label in card mode.

Complex Header Associations

For tables with multiple levels of headers where automatic association via scope is insufficient, use the headers attribute to explicitly list the IDs of the associated header cells.

VB Data Attributes

Attribute Values Description
data-numeric Boolean attribute Right-aligns content and uses tabular numerals
data-align start, center, end Explicit text alignment override
data-sort-value String Value used for sorting (overrides display text)
data-filter-value String Value used for filtering/search (overrides display text)
data-label String Column header label for responsive card mode

Standard HTML Attributes

Attribute Values Description
colspan Positive integer Number of columns the cell spans
rowspan Positive integer Number of rows the cell spans
headers Space-separated IDs Explicitly associates cell with header cells

CSS Reference

Accessibility

  • Header associations: Data cells are automatically associated with their column and row headers through the table structure and scope
  • Screen reader navigation: When navigating to a <td>, screen readers announce the associated headers
  • Complex tables: Use the headers attribute when automatic association is insufficient
  • Avoid empty cells: Use meaningful placeholders like "N/A" or "-" for better screen reader experience
  • Rich content: When cells contain structured content (links, buttons, status badges), ensure all interactive elements are keyboard accessible

Related

  • <th> - Header cells (describe td content)
  • <tr> - Table rows containing td cells
  • <tbody> - Primary container for data rows
  • <tfoot> - Contains summary/total cells
  • <table> - The table container
  • <data-table> - Interactive table component that uses data-sort-value, data-filter-value, and data-label