CSS display: table, table-row, and table-cell Explained
Set display: table on the container, table-row on each row, and table-cell on the items to align the column edges. The example arranges names and values from an HTML description list. Use an HTML <table> for data whose row and column relationships need to be conveyed.
Set display on the container, rows, and cells
| Value | Layout role |
|---|---|
table |
Container for the whole table |
table-row |
A row |
table-cell |
A cell within a row |
table-row-group |
A group of rows |
table-header-group, table-footer-group |
Header or footer row group |
table-column, table-column-group |
A column or column group |
table-caption |
The table caption |
The container holds rows, and the rows hold cells. Browsers can create anonymous boxes to fill missing layers, but writing all three layers makes it easier to find the rule that sets width or alignment. Use table-row-group to group rows or table-caption to create a CSS caption box when needed. CSS Display · table-cell
Build a two-column description list
Save the code as display-table.html and open it. The dl contains two groups with a name in dt and its description in dd. At larger widths the names share a column width. A longer description in the second row makes that entire row taller. HTML Standard · dl
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Align a description list with CSS table layout</title>
<style>
body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
* { box-sizing: border-box; }
.details { display: table; width: 100%; max-width: 650px; margin: 0;
table-layout: fixed; border-collapse: collapse; }
.row { display: table-row; }
.details dt, .details dd { display: table-cell; padding: 12px;
border: 1px solid #97a9bb; overflow-wrap: anywhere; }
.details dt { width: 30%; background: #edf3fa; font-weight: 700; vertical-align: middle; }
.details dd { margin: 0; vertical-align: top; }
@media (max-width: 480px) {
.details, .row, .details dt, .details dd { display: block; }
.details dt { width: auto; }
}
</style>
</head>
<body>
<h1>Course information</h1>
<dl class="details">
<div class="row">
<dt><span>Course name</span></dt>
<dd>CSS basics</dd>
</div>
<div class="row">
<dt><span>How to study</span></dt>
<dd>Save the example file and open it in a browser.<br>Change one value at a time to see how it affects the layout.</dd>
</div>
</dl>
</body>
</html>
The container fills the available width up to 650px. With table-layout: fixed, the first column gets 30% and the description takes the rest. Change only 30% to 40%, compare the narrower description column, and restore the value. overflow-wrap: anywhere lets long strings wrap when needed.
Adjust column widths, alignment, and spacing
The name is centered vertically in its cell with vertical-align: middle, while the description aligns to the top. Change the name cell to top and compare. Use padding for space inside a cell. For gaps between cells, use border-collapse: separate and border-spacing on the container. Spacing does not apply in the collapsed model. CSS 2.2 · Table layout
Choose a structure for narrow screens and data tables
At 480px or less each element becomes block and the name width resets to auto. Each description follows its name, and the HTML order stays the same. For a data table, use <th> headers and <td> data cells to express header relationships. For ordinary page or card layouts, consider Grid or Flexbox.




