pub struct Table;Expand description
The <table> element - represents tabular data in rows and columns.
§Purpose
The <table> element represents data with more than one dimension in the form of a table.
Tables should be used for tabular data, not for layout purposes (use CSS for layout).
Provides semantic structure for organizing related information in rows and columns.
§Content Categories
- Flow Content
- Palpable Content
§Permitted Content Model
- Optional
<caption>element - Zero or more
<colgroup>elements - Optional
<thead>element - Either: zero or more
<tbody>elements, or one or more<tr>elements - Optional
<tfoot>element
§Common Use Cases
- Displaying datasets and spreadsheet-like data
- Pricing tables and comparison charts
- Financial reports and statistics
- Schedules and calendars
- Product specifications and feature comparisons
§Key Attributes
- Global attributes only (older attributes like
borderare obsolete)
§Example
<!-- Basic table -->
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alice</td>
<td>30</td>
<td>New York</td>
</tr>
<tr>
<td>Bob</td>
<td>25</td>
<td>Los Angeles</td>
</tr>
</tbody>
</table>
<!-- Table with caption and footer -->
<table>
<caption>Quarterly Sales Report</caption>
<thead>
<tr>
<th>Quarter</th>
<th>Revenue</th>
<th>Growth</th>
</tr>
</thead>
<tbody>
<tr>
<td>Q1</td>
<td>$100,000</td>
<td>5%</td>
</tr>
<tr>
<td>Q2</td>
<td>$120,000</td>
<td>20%</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total</td>
<td>$220,000</td>
<td>12.5%</td>
</tr>
</tfoot>
</table>
<!-- Complex table with column groups -->
<table>
<colgroup>
<col>
<col span="2" class="financial">
</colgroup>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Stock</th>
</tr>
</thead>
<tbody>
<tr>
<td>Widget</td>
<td>$10</td>
<td>50</td>
</tr>
</tbody>
</table>§Accessibility
- Use
<th>elements for headers withscopeattribute - Provide a
<caption>for table context - Use
headersattribute for complex tables - Ensure proper header association for screen readers
- Consider using
aria-describedbyfor additional context - Make tables responsive for mobile devices
§WHATWG Specification
Trait Implementations§
Source§impl HtmlElement for Table
impl HtmlElement for Table
impl CanContain<Caption> for Table
impl CanContain<Colgroup> for Table
impl CanContain<Script> for Table
impl CanContain<Tbody> for Table
impl CanContain<Template> for Table
impl CanContain<Tfoot> for Table
impl CanContain<Thead> for Table
impl CanContain<Tr> for Table
impl FlowContent for Table
impl PalpableContent for Table
Auto Trait Implementations§
impl Freeze for Table
impl RefUnwindSafe for Table
impl Send for Table
impl Sync for Table
impl Unpin for Table
impl UnwindSafe for Table
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more