Saved

Press the star next to a tool's name to save it.

All my tools

HTML Table Generator

Use this html table generator to turn pasted CSV or spreadsheet data, or a blank rows and columns grid, into clean table code with a header row, a caption and a preview.

Paste comma-, semicolon- or tab-separated data, for example copied from a spreadsheet, or leave the box empty and set rows and columns for a blank table. Press Generate for the code and a preview.

The table is built in your browser. Nothing you paste is uploaded.

HTML table code

Paste your data or set the size, then press Generate.

An HTML table generator turns rows of data into clean table markup you can paste into a web page, a CMS or an email template. Paste data copied from a spreadsheet or a CSV file, or leave the box empty and choose how many rows and columns you want. Press Generate and you get the code, ready to copy, with a live preview underneath.

The table follows the structure recommended on MDN [1]: an optional caption, a header section with header cells, and a body with data cells. Every cell’s text is escaped, so characters such as the less-than sign and the ampersand show up as text and never break your page.

How to use the HTML table generator

  1. Paste your data into the box. Commas, semicolons and tabs are detected for you, so you can paste straight from a spreadsheet.
  2. Or leave the box empty and enter the number of rows and columns for a blank grid with placeholder text.
  3. Choose whether the first row is a header, whether header cells get a scope attribute, and how the code is indented.
  4. Add a caption if the table needs a title.
  5. Press Generate, check the preview, then copy the code.

What the generated code contains

ElementPurpose
tableWraps the whole table
captionA short title that says what the table is about
thead and thThe header row and its header cells
tbody and tdThe data rows and their cells
scope="col"Tells assistive technology that a header cell applies to its column

Accessible tables

A caption that states the purpose of the table helps people who use screen readers decide whether to read it, and header cells with a scope attribute connect each data cell to its heading [1]. The generator adds both when you ask for them. For tables with merged cells, MDN advises avoiding row and column spans where you can, because they can confuse screen readers [1]. This tool makes simple tables with one header row, which is the easiest kind to understand.

Pasting CSV data

In CSV, a field that contains a comma, a double quote or a line break is wrapped in double quotes, and a quote inside such a field is written twice [2]. The generator reads those rules, so a cell such as "Smith, Ana" stays in one cell. The first line can be a header with the field names [2], which is why the header option is on by default. Rows with fewer cells than the widest row are padded with empty cells so that the table stays rectangular.

Worked example

Paste these three lines: Name,Age on the first line, Ana,34 on the second and Ben,29 on the third. With the header option on, the first row becomes a thead row with two th cells that have scope="col", and the next two rows become tr elements with td cells. Add the caption People and the result starts with the table tag and a caption element, then the head, then the body. The preview shows the same table so you can check it before you copy.

Tips for good tables

  • Use a table for data that has rows and columns, not to lay out a page.
  • Keep one header row and short header text.
  • Add a caption that describes the table in a few words.
  • Choose One line for the indent when the code goes into a template that adds its own formatting.
  • Style the table with CSS in your site; the generated code has no inline styles, so it takes on your design.
  • For very large tables, split the data into several smaller tables.

Using the code in your page

Paste the generated code where the table should appear in your page’s HTML. In a content management system, switch the editor to its HTML or code view before pasting, otherwise the editor may show the tags as text. Email templates support only a limited set of styles, so test the table in the mail clients you care about.

The code has no styling, so it takes on the look of your site’s CSS. Common additions are borders, padding in the cells, a different background for the header row and a horizontal scroll wrapper for wide tables on phones. Because the markup is clean and uses the standard sections, a few CSS rules are enough.

  • Wrap wide tables in a scrolling container so they do not break the layout on small screens.
  • Keep the caption, because it also helps search engines and screen readers understand the table.
  • Re-generate the table when your data changes instead of editing the cells by hand.

Common mistakes

  • Pasting data with the wrong separator in some rows, which makes columns shift.
  • Forgetting that a blank first row is skipped: empty rows are left out of the table.
  • Expecting formulas or formatting from a spreadsheet to carry over: only the text of the cells is used.
  • Leaving the header option on when the first row is data.

What next

Use this often? Add HTML Table to your Home screen.

Frequently asked questions

What does the html table generator produce?

It produces table markup with an optional caption, a header row with th cells and a body with td cells, plus a preview of how the table looks.

Can I paste data from Excel or Google Sheets?

Yes. Copied spreadsheet cells are separated by tabs, and the generator detects tabs, commas and semicolons for you.

Is the text in the cells escaped?

Yes. Characters such as less-than, greater-than, ampersand and quotes are converted so they appear as text and cannot break your page.

Why add a scope attribute to header cells?

scope="col" tells assistive technology which cells a header applies to, which helps screen reader users understand the table.

Is my data uploaded?

No. The table is built in your browser and nothing is sent to a server.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Developer Tools