HTML Table Styling with CSS

It's easy to create beutiful HTML tables with the online styler. All you have to do is activate the "Style CSS" button, select a template or start blank. You can set the styles of the whole table, body, header and footer in separate panels.

html css table styler
Activate the Online Table Styler in the Table Generator.

Change the font, border, colors, cell padding, sizes and other styles.

The Same Table With Different Styles

Below you can see the same HTML table with three different CSS styles. They have the same source code, with different class names assigned to them.

default unstyled table
Unstyled HTML table, with default Google Chrome styles.

<table>
  <thead>
    <tr>
      <th>Model</th>
      <th>Price</th><th>Range</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Model S</td>
      <td>83,900</td><td>405 mi</td>
    </tr>
    <tr>
      <td>Model 3</td>
      <td>42,900</td><td>272 mi</td>
    </tr>
    <tr>
      <td>Model X</td>
      <td>99,990</td><td>351 mi</td>
    </tr>
    <tr>
      <td>Model Y</td>
      <td>54,990</td><td>330 mi</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td></td><td>USD</td><td>Miles</td>
    </tr>
  </tfoot>
</table>
ModelPriceRange
Model S83,900405 mi
Model 342,900272 mi
Model X99,990351 mi
Model Y54,990330 mi
USDMiles
ModelPriceRange
Model S83,900405 mi
Model 342,900272 mi
Model X99,990351 mi
Model Y54,990330 mi
USDMiles
ModelPriceRange
Model S83,900405 mi
Model 342,900272 mi
Model X99,990351 mi
Model Y54,990330 mi
USDMiles

Most Important Table Styles

table border settingsBelow you will find the most important table styling options. Use the online styler or do them manually. Watch out and avoid obsolete methods.

Border

Setting table border with the "border" tag attribute is obsolete and we should use CSS instead.

The table generator allows you to set border for the whole table and the body individually. You can set the width with a slider and adjust the color in a color picker. Uncheck the checkbox to disable this feature.

<table border="2">  Obsolete! 
table border obsolete
W3 markup validator throws an error for using the border attribute for a table tag.

<table style="border: 5px dashed grey">
  <tr style="border: 5px solid green">
    <td style="border: 5px dotted blue">
      AAA
    </td>
    <td>BBB</td>
  </tr>
  <tr>
    <td>CCC</td>
    <td>DDD</td>
  </tr>
</table>
AAA BBB
CCC DDD

A small table with dashed grey border, solid green row border and a cell with dotted blue border.

border css generator
Online Border CSS Generator

Border-collapse

The border-collapse CSS property defines whether the table and its cells borders should collapse into a single border or be separated. The border-spacing property has to be at least one pixel for this style to have any effect.

.myStyle {
   border-collapse: collapse;
}
AAA BBB
CCC DDD
.myStyle {
   border-collapse: separate;
   border-spacing: 4px;
}
AAA BBB
CCC DDD

Border-spacing

Border spacing CSS property sets the space between the borders when the border-collapse style is set to "separate".

.myStyle {
   border-collapse: separate;
   border-spacing: 4px;
   border: 4px solid green;
}
.myStyle td {
   border: 4px solid grey;
}
AAA BBB
CCC DDD

border-collapse: collapse and border-spacing: 0 have the similar visual effect.

Vertical-align

Use the vertical-align CSS property to align the text vertically and text-align for horizontal alignment.

<table>
  <tr>
    <td><strong>vertical-<br>align</strong></td>
    <td style="vertical-align:top">top</td>
    <td style="vertical-align:middle">middle</td>
    <td style="vertical-align:bottom">bottom</td>
  </tr>
</table>
vertical-
align
top middle bottom

Aligning the text to the top, middle and bottom of the cell.

<table>
  <tr><td><strong>
    text-align&nbsp;CSS
  </strong></td></tr>
  <tr><td style="text-align:left">left</td></tr>
  <tr><td style="text-align:center">center</td></tr>
  <tr><td style="text-align:right">right</td></tr>
</table>
text-align CSS
left
center
right

Set the text to align to the left, center and right side of the cell

Table layout

We can change how the table lays out its content through the table-layout property. This property tells the browser how to arrange the cells in the table.

There are two possible values for this property: auto and fixed.

<table style="table-layout: auto;
              width: 300px">
  <tr>
    <td>Word</td>
    <td>LongerWord</td>
    <td>A_pretty_cool_long_word</td>
  </tr>
</table>
Word LongerWord A_pretty_cool_long_word

table-layout: auto - the cells are adjusting their width to fit their content. The table is wider than the defined 300 px to make room for the long word.
<table style="table-layout: fixed;
              width: 300px">
  <tr>
    <td>Word</td>
    <td>LongerWord</td>
    <td>A_pretty_cool_long_word</td>
  </tr>
</table>
Word LongerWord A_pretty_cool_long_word

table-layout: fixed - Every cell is 100 pixels wide and the long word is sticking out.

Div Table CSS

div table generatorThe online table generator will help you to create div tables easily.

Switch to use <div> tags instead of <table> tags, then select the desired dimensions, optionally activate header and footer. Take the generated HTML code and use in your project. Make sure to include the CSS styles below to make the structured <div> tags behave like table rows and cells.

Learn more about div tables on its dedicated page.

.divTable { display: table; }
.divTableRow { display: table-row; }
.divTableHeading { display: table-header-group; }
.divTableCell, .divTableHead { display: table-cell; }
.divTableHeading { display: table-header-group; }
.divTableFoot { display: table-footer-group; }
.divTableBody { display: table-row-group; }
<div class="divTable">
  <div class="divTableHeading">
    <div class="divTableRow">
      <div class="divTableHead">Head1</div>
      <div class="divTableHead">Head2</div>
    </div>
  </div>
  <div class="divTableBody">
    <div class="divTableRow">
      <div class="divTableCell">AA</div>
      <div class="divTableCell">BB</div>
    </div>
    <div class="divTableRow">
      <div class="divTableCell">CC</div>
      <div class="divTableCell">DD</div>
    </div>
  </div>
  <div class="divTableFoot tableFootStyle">
    <div class="divTableRow">
      <div class="divTableCell">Foot1</div>
      <div class="divTableCell">Foot2</div>
    </div>
  </div>
</div>
Head1
Head2
AA
BB
CC
DD
Foot1
Foot2

How to Use the Online HTML Table Styler

The HTML table generator and CSS style generator below will help you set up the perfect table for your project very quickly.

2 × 2

Table

Style Name
Georgia
Georgia
Palatino
Times New Roman
Arial
Arial Black
Comic Sans
Impact
Lucida Sans
Tahoma
Trebuchet
Verdana
Courier
Lucida Console
Left Center Right
px
px

Body

Left Center Right

HTML
Preview Apply »
HTML Copy
CSS « Apply