Structure of a Table in HTML
In HTML, tables are used to display data in a structured grid of rows and columns. The main elements for creating a table are <table>, <tr>, <th>, and <td>.
<table>: Defines the table container.
<tr> (Table Row): Defines a row in the table.
<th> (Table Header): Defines a header cell, usually bold and centered by default.
<td> (Table Data): Defines a standard data cell.
<caption>: Optional element to provide a title or description for the table.
<thead>, <tbody>, <tfoot>: Optional elements to group header, body, and footer rows for better semantics and styling.
In short: Use <table> as the container, <tr> for rows, <th> for header cells, and <td> for data cells. Optional grouping and caption elements improve semantics and accessibility.
We have a mock-up of a pricing page with three plans, each showing features, prices, and a signup button. How would you structure this using semantic HTML table elements so that screen readers can easily associate the features with the correct plan?
Imagine you've built a table, but the header row is stretching weirdly and some cells aren't aligning with their columns. What elements or attributes like colspan or rowspan would you check to debug this alignment issue?
We're building a financial dashboard with a dense data table. On mobile screens, the table gets cut off and looks broken. How would you refactor the HTML structure or apply CSS to make this table responsive without losing the semantic relationship of the data?
A developer on your team built a table using nested div elements styled with CSS Grid to look like a table. What are the accessibility and SEO implications of this approach compared to using native table tags, and how would you advise them?
You are designing a reusable DataTable component for a design system that needs to support sorting, filtering, and multi-level nested headers (e.g., 'Q1' nested under '2024'). How would you structure the HTML and use attributes like scope or id/headers to ensure screen readers navigate this complex hierarchy correctly?
We have a legacy application rendering a massive table with thousands of rows, causing noticeable layout shifts and rendering lag on load. How would you optimize the HTML structure and CSS properties (like table-layout: fixed) to improve the browser's rendering performance?
Our enterprise platform has dozens of teams building their own custom tables, leading to inconsistent accessibility compliance and performance issues. How would you architect a standardized data-grid solution at the organization level, and what architectural boundaries would you set between native HTML tables and ARIA grid roles?
We are migrating a legacy, server-rendered table system to a modern client-side virtualized list. How do you balance the performance gains of virtualization (which unmounts off-screen DOM nodes) with the accessibility requirements of screen readers that expect a complete, semantic HTML table structure?