Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

HTML table generator

This HTML table generator turns typed or pasted cells into table code you can paste into a page. The sample grid becomes 26 lines and 731 characters of markup, with a header, scope attributes, right-aligned numbers and the ampersand written as an entity.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Or type in the grid, and set each column's alignment above it.
Table parts
HTML table code

3 columns by 4 rows26 lines of HTML

<table> <thead> <tr> <th scope="col" style="text-align: left">Item</th> <th scope="col" style="text-align: right">Qty</th> <th scope="col" style="text-align: right">Price</th> </tr> </thead> <tbody> <tr> <td style="text-align: left">Notebook</td> <td style="text-align: right">3</td> <td style="text-align: right">4.50</td> </tr> <tr> <td style="text-align: left">Pen &amp; ink set</td> <td style="text-align: right">10</td> <td style="text-align: right">1.20</td> </tr> <tr> <td style="text-align: left">Stapler</td> <td style="text-align: right">1</td> <td style="text-align: right">7.00</td> </tr> </tbody> </table>
  • 1 character written as entities
  • 731 characters
Preview
ItemQtyPrice
Notebook34.50
Pen & ink set101.20
Stapler17.00
Columns
3
Rows
4
Lines
26
Characters
731

How to use the HTML Table Generator

  1. Paste cells copied from a spreadsheet, or CSV text, into Paste spreadsheet cells or CSV and press Load into the grid. You can also type straight into the grid.
  2. Pick an alignment above each column, and use Add row, Add column and the remove buttons to change the size.
  3. Tick or untick Table parts: a header row, a footer row, scope on header cells and written alignment.
  4. Add an optional Caption and Class on the table, choose the Indentation, then press Copy or Download .html.

How do I make an HTML table from rows of data?

A table is a <table> element with one <tr> per row and one <th> or <td> per cell. This generator writes those tags for you from a grid. A table with two columns, a header row and one data row comes out as <table><thead><tr><th scope="col">Item</th><th scope="col">Qty</th></tr></thead><tbody><tr><td>Pen</td><td>3</td></tr></tbody></table> when indentation is switched off.

The header row goes in <thead> and the data rows in <tbody>. Without a header, the first row is plain data and the thead block is left out: the same grid then gives <table><tbody><tr><td>Item</td><td>Qty</td></tr><tr><td>Pen</td><td>3</td></tr></tbody></table>. The page keeps the sections in the order the HTML standard asks for: caption first, then the header, then the body, then the footer.

Pasting is the quick route. The text Name<tab>Qty followed by two data rows, with a comma inside one cell, loads as 3 rows by 2 columns, and the cell Ink, blue stays whole because the tab is the separator. Quoted CSV cells can hold commas and line breaks too.

Size of the sample table (4 rows, 3 columns) for each setting
SettingCharacters
Two spaces, scope and alignment (the default)731
Four spaces843
Tab675
Two spaces, no alignment written423
Two spaces, no scope695
Two spaces, no scope and no alignment387
One line, no scope and no alignment249

Which characters need escaping in a table cell?

Three characters have a meaning in markup, so the generator replaces them in every cell and in the caption. An ampersand becomes &amp;, a less-than sign becomes &lt; and a greater-than sign becomes &gt;. The cell Fish & chips is written as Fish &amp; chips, and a < b > c as a &lt; b &gt; c. Without this a stray angle bracket can swallow the cells after it.

A line break inside a cell is written as <br>: the two lines line one and line two come out as line one<br>line two. Quotation marks need no escaping in element text, so they stay as typed. The page counts what it changed and shows the number under the code, which makes a surprise visible, for example when a pasted cell already held an entity such as &amp;, which is written again as &amp;amp; because the text is treated as plain text.

What do the header, scope, caption and footer options do?

The scope attribute on a header cell says whether it describes a column or a row. The HTML standard lists the values col, row, colgroup and rowgroup, and this page writes scope="col" on every cell of the header row so that tools reading the table out loud can tie each value to its column. Leave it off if your style guide forbids it.

A caption is the table's title and must be the first child of the table, so it is written before everything else. The standard suggests using a figure caption instead when the table is the only content of a figure. With the caption Price list and the class prices, a one column grid becomes <table class="prices"><caption>Price list</caption><thead><tr><th scope="col">a</th></tr></thead><tbody><tr><td>b</td></tr></tbody></table>. The class must start with a letter or a low line and hold only letters, digits, hyphens and low lines, so the page refuses a quote or a bracket rather than writing broken markup.

The footer option moves the last row into <tfoot>, handy for totals. With rows Tea 3, Cake 5 and Total 8 the output ends in </tbody><tfoot><tr><td>Total</td><td>8</td></tr></tfoot></table>. The footer is written after the body, which is where the standard puts it in the content model.

How do I align columns and keep the table small?

The align attribute on table cells is obsolete and authors must not use it. The generator writes style="text-align: right" on each cell of an aligned column instead. Untick Write column alignment if you set alignment in a stylesheet. Dropping the written alignment in the sample cuts the markup from 731 to 423 characters, and dropping scope as well gives 387.

Indentation is for people reading the source. Two spaces, four spaces and a tab produce 731, 843 and 675 characters for the sample, and the one line option removes all of it. Browsers show the same table either way. For a Markdown version of the same grid use the Markdown table generator, and to see how many words a table cell block holds try the word counter.

Use it with

Questions

How do I create an HTML table?

Put cells in the grid or paste them from a spreadsheet. The code appears at once with a thead, a tbody and one tr per row. Press Copy and paste it into your page.

Can I paste from Excel or Google Sheets?

Yes. Copied spreadsheet cells arrive separated by tabs, which the loader reads directly. CSV text with commas, semicolons or pipes works as well, including quoted cells.

Does it escape special characters?

Yes. Ampersands and angle brackets in cells and in the caption are written as entities, and the number of changes is shown under the code.

What is the scope attribute for?

It states whether a header cell applies to a column or a row. The page writes scope="col" on the header row cells, and you can switch it off.

How do I center or right-align a column?

Choose Center or Right above the column. The code then carries a text-align style on each cell of that column.

Is my table sent to a server?

No. The grid, the paste box and the preview all work in this tab, and the page sends no request carrying your cells.

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.