Build a Reference Table of Common HTML Elements
Goal: Create a reference table of common HTML elements while learning table structure, semantics, and styling. You'll build a usable reference artifact and understand when and why to use tables.
What you'll learn:
<table>, <tr>, <th>, and <td><thead> and <tbody>scope attribute for accessibilityGoal: Build the basic structure of your HTML element reference table.
Tables organize information into rows and columns. Before you start coding, think about what you're organizing: element names, their purposes, and example contexts.
π Research checkpoint: Read MDN: HTML Table Basics through the "Adding headers" section.
Key concepts to understand:
<table> β The container for your entire table<tr> β Table row (each row needs one)<th> β Table header cell (for column headers)<td> β Table data cell (for actual content)<th> and <td>? Header cells tell you what the data means, while data cells contain the actual information.
Your task: In the CodePen workspace on the right, create your table structure:
<!-- START: Student work area --> comment, create a <table> element<tr> (table row)<th> for: "Element", "Purpose", "Example Use"<td> for two HTML elements of your choiceExample structure:
<table>
<tr>
<th>Element</th>
<th>Purpose</th>
<th>Example Use</th>
</tr>
<tr>
<td><p></td>
<td>Paragraph text</td>
<td>Body copy, descriptions</td>
</tr>
<tr>
<td><h1></td>
<td>Main heading</td>
<td>Page title, section headers</td>
</tr>
</table>
<p> in your table without the browser interpreting them as actual tags, use HTML entities: < for < and > for >
<th> tags<td> tagsIn your own words: Why does HTML distinguish between header cells and data cells? What would happen if you used only <td> for everything?
<thead> and <tbody>Goal: Add semantic structure with <thead> and <tbody> to help browsers and assistive technology understand your table.
Right now your table works, but it's just a flat list of rows. Let's give it meaningful sections.
π Research checkpoint: Read MDN: Continue through the HTML Table Basics article (stop before "Allowing columns and rows to span").
Your task:
<th> tags) in <thead> tags<td> tags) in <tbody> tagsYour structure should now look like:
<table>
<thead>
<tr>
<th>Element</th>
<th>Purpose</th>
<th>Example Use</th>
</tr>
</thead>
<tbody>
<tr>
<td><p></td>
<td>Paragraph text</td>
<td>Body copy, descriptions</td>
</tr>
<!-- more rows here -->
</tbody>
</table>
Add 5-8 more rows to your <tbody> with additional HTML elements. Use the sample content provided below to fill your table quickly.
<thead> wrapper around header row<tbody> wrapper around data rows<tbody>Why might separating headers from data matter for accessibility or printing? What does a screen reader gain from this structure?
scope AttributeGoal: Use the scope attribute to explicitly tell assistive technology what each header describes.
Your headers are in <th> tags, which is good. But we can be even more explicit about what they describe.
π Research checkpoint: Read MDN: Advanced features and accessibility.
Your task: Add scope="col" to each <th> in your header row.
Example:
<thead>
<tr>
<th scope="col">Element</th>
<th scope="col">Purpose</th>
<th scope="col">Example Use</th>
</tr>
</thead>
scope="row" for row headers. This helps people using assistive technology understand the relationship between headers and data.
scope="col"How does scope help someone using a screen reader navigate your table? Try to imagine hearing this table read aloud.
Goal: Make your table readable and professional with CSS.
Unstyled tables are hard to scan. Let's add visual structure: borders, spacing, and alternating row colors.
π Research checkpoint: Read MDN: Styling tables.
Key CSS properties you'll use:
border-collapse: collapse; β Removes double borders between cellsborder β Adds borders to table, th, and tdpadding β Adds space inside cellsbackground-color β Colors for headers and alternating rows:nth-child(even) or :nth-child(odd) β Selects alternating rowsYour task: In the CSS panel of your CodePen, add styles to make your table readable. Replace the comment placeholders with actual CSS.
border-collapse: collapse; and width: 100%; to your tableth and td elementsWhat makes a table easy to scan? Which styling choices had the biggest impact on readability?
Goal: Add a caption and explore advanced features.
Your task: Add a <caption> element as the first child of your <table> (right after the opening <table> tag).
Example:
<table>
<caption>Common HTML Elements Reference</caption>
<thead>
<!-- ... -->
</thead>
<!-- ... -->
</table>
Style your caption with CSS:
caption {
caption-side: top;
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 0.75rem;
color: #1e293b;
}
Add a <tfoot> with a note about your sources or last updated date.
Example:
<table>
<caption>Common HTML Elements Reference</caption>
<thead>...</thead>
<tbody>...</tbody>
<tfoot>
<tr>
<td colspan="3">Source: MDN Web Docs, 2024</td>
</tr>
</tfoot>
</table>
colspan="3" attribute makes this cell span across all three columns. This is useful for footer notes that apply to the entire table.
Continue experimenting in your CodePen:
:hover effects for better interactivityrowspan to group related elementsscope="row" to group elements by type (Text Elements, Structure Elements, Media Elements, etc.).
When should you use a table vs. a list? What kinds of data belong in tables?
Save your reflections directly in your CodePen HTML so they're preserved with your work.
π Steps:
</table> tag)<thead> and <tbody> sections<th> with scope="col"Code along as you follow the tutorial β