Pure CSS Table

By Xah Lee. Date: . Last updated: .

CSS can emulate HTML Table tag. So, traditional layout using the table tag can be done with pure CSS.

Here is a example of CSS table rendered in your browser:

one
two
three
four
five
six

Here is the HTML code:

<div class="xtable722">
  <div class="xrow72">
    <div class="xcell72">one</div>
    <div class="xcell72">two</div>
  </div>
  <div class="xrow72">
    <div class="xcell72">three</div>
    <div class="xcell72">four</div>
  </div>
  <div class="xrow72">
    <div class="xcell72">five</div>
    <div class="xcell72">six</div>
  </div>
</div>

Here is the CSS code:

.xtable722 {
border:solid thin red;
display:table;
}

.xrow72 {
display:table-row;
}

.xcell72, .xcell72 {
display:table-cell;
border:solid thin red;
}

CSS Attributes for Table Layout

Here is a full list of values for the display attribute to emulate table tags.

Basic HTML Table “display” values
CSSHTML
display:tableHTML table
display:table-rowtr (row)
display:table-celltd (table cell)
caption, header, footer, “display” values
CSSHTML
display:table-captioncaption
display:table-header-groupthead (table header row; th group)
display:table-footer-grouptfoot (table footer row)

[see HTML Table, thead, tbody, tfoot]

column, row, group “display” values
CSSHTML
display:table-row-grouptbody
display:table-columncol
display:table-column-groupcolgroup

[see HTML Table, colgroup, col]

HTML Table

CSS Layout

CSS Layers

JavaScript Using Css Layers