📊 HTML Code Generator

HTML Table & Grid Code Generator

Configure rows, columns, headers, and borders to generate clean semantic HTML table markup with 1-click code copying.

Number of Rows3 Rows
Number of Columns3 Columns
Generated HTML Table Code

The anatomy of an HTML table

An HTML table is built from rows (tr), and each row contains cells: th for header cells and td for data cells. Rows are grouped into a thead for the column headings and a tbody for the data. A tfoot can be added for totals. These groups are not just tidy markup: browsers can repeat thead rows at the top of each printed page, and assistive technology uses them to understand the structure.

For example, a 3 by 3 table with headers contains 12 cells: 3 th cells in one header row and 9 td cells across three body rows. At the generator's maximum of 10 rows and 6 columns you get 6 header cells and 60 data cells.

Making the table accessible

Screen readers announce a cell's header when a user moves through a table, but only if the headers are marked up correctly. The generated skeleton gives you the structure; a few additions make it fully accessible:

  • Fill in the optional Caption field to add a caption element directly after the opening table tag. It acts as the table's title and is read before the table contents.
  • Header cells are generated with scope="col". If the first cell of each body row labels that row, such as a product name, change it to a th with scope="row".
  • Keep one piece of data per cell and avoid empty cells used purely for spacing.
  • Do not use tables for page layout. Screen readers will announce rows and columns that carry no meaning; use CSS Grid or Flexbox for layout instead.

Styling with CSS instead of presentational attributes

Older tutorials style tables with border="1", cellpadding="8" and cellspacing="0". cellpadding and cellspacing are obsolete in the current HTML standard and are flagged by validators, and the border attribute is discouraged in favour of CSS. With Include Basic CSS ticked, this generator instead adds class="data-table" to the table and a small style block: .data-table { border-collapse: collapse; } plus a 1px #ccc border and 8px padding on every th and td.

border-collapse: collapse merges adjacent cell borders into a single line, which is what cellspacing="0" plus a border achieved. Scoping the rules to a class keeps them from restyling other tables on the page; move them into your main stylesheet so every table can be restyled in one place.

HTML email is the exception. Many email clients have limited CSS support, and table attributes such as cellpadding remain a reliable way to control spacing there. Many also ignore style blocks, so for email templates add cellpadding and cellspacing to the table by hand, or inline the styles on each cell, and use CSS everywhere else.

Tables on small screens

A six-column table rarely fits a phone. The simplest fix is to wrap the table in a div with overflow-x: auto, which lets the table scroll sideways inside its container instead of stretching the page. Add a tabindex="0" and an aria-label to that wrapper so keyboard users can scroll it too.

For tables with few columns and many rows, another approach is to switch rows into stacked cards at narrow widths using CSS. That needs more work, because changing the display of table elements can remove their table semantics for screen readers in some browsers, so test with assistive technology before relying on it.

HTML Table Generator: frequently asked questions

Should I use th or td for the first column?

Use th with scope="row" when the first column labels each row, such as names, dates or product titles. Use td when it is just another value. Correct row headers let screen readers announce, for example, the product name before each price.

Is tbody required if I do not have a header?

No. Browsers insert a tbody automatically when the parser sees rows directly inside a table. Writing it explicitly does no harm and makes CSS selectors and scripts more predictable.

How do I merge cells in an HTML table?

Use colspan on a cell to stretch it across several columns, or rowspan to stretch it down several rows. Remove the cells it replaces from the affected rows, otherwise the table will have extra cells and the columns will misalign.

How do I make table columns a fixed width?

Set table-layout: fixed on the table and give it a width, then set widths on the cells of the first row or on col elements. With fixed layout the browser uses those widths instead of measuring every cell's content, which also renders large tables faster.

How do I add zebra striping to a table?

Use a CSS rule such as tbody tr:nth-child(even) { background: #f5f5f5; }. Keep the stripe colour light enough that text contrast in both row colours still meets readability requirements.

All html & javascript utilities