pub struct Caption;Expand description
The <caption> element - represents the title of a table.
§Purpose
The <caption> element provides a title or caption for its parent <table>. It gives
users context about the table’s content before they start reading the data. Must be the
first child of the table if present. Screen readers announce captions to help users
understand table purpose.
§Content Categories
- None (only valid as first child of
<table>)
§Permitted Content Model
- Flow content (excluding table elements)
§Common Use Cases
- Providing descriptive titles for data tables
- Summarizing table content and purpose
- Adding context for screen reader users
- Labeling financial reports and statistics
- Titling comparison and pricing tables
§Key Attributes
- Global attributes only
§Example
<!-- Simple caption -->
<table>
<caption>Employee Directory</caption>
<thead>
<tr>
<th>Name</th>
<th>Department</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>Engineering</td>
<td>john@example.com</td>
</tr>
</tbody>
</table>
<!-- Caption with additional context -->
<table>
<caption>
<strong>Quarterly Sales Data</strong>
<br>
<small>Fiscal Year 2024</small>
</caption>
<thead>
<tr>
<th>Quarter</th>
<th>Sales</th>
</tr>
</thead>
<tbody>
<tr>
<td>Q1</td>
<td>$50,000</td>
</tr>
</tbody>
</table>
<!-- Styled caption -->
<table>
<caption style="caption-side: bottom;">
Table 1: Customer satisfaction ratings by region
</caption>
<thead>
<tr>
<th>Region</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
<tr>
<td>North</td>
<td>4.5/5</td>
</tr>
</tbody>
</table>§Accessibility
- Always provide a caption for data tables
- Keep captions concise but descriptive
- Screen readers announce captions before table content
- Use CSS
caption-sideproperty for visual positioning
§WHATWG Specification
Trait Implementations§
Source§impl HtmlElement for Caption
impl HtmlElement for Caption
impl CanContain<Caption> for Table
impl<T: FlowContent> CanContain<T> for Caption
impl CanContain<Text> for Caption
Auto Trait Implementations§
impl Freeze for Caption
impl RefUnwindSafe for Caption
impl Send for Caption
impl Sync for Caption
impl Unpin for Caption
impl UnwindSafe for Caption
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