How to convert CSV to an HTML table
A CSV file is plain rows of values. An HTML table is the same grid written as tags. To convert csv to an html table, the tool reads each row, splits it into cells with the separator it detects, and writes a <tr> for each row and a cell tag for each value. Take this CSV:
Product,Units
Desk lamp,1200
Chair,85With Bare HTML and the caption Stock, it becomes:
<table>
<caption>Stock</caption>
<thead>
<tr>
<th scope="col">Product</th>
<th scope="col">Units</th>
</tr>
</thead>
<tbody>
<tr>
<td>Desk lamp</td>
<td>1200</td>
</tr>
<tr>
<td>Chair</td>
<td>85</td>
</tr>
</tbody>
</table>The status line reports 2 rows and 2 columns. Rows counted are data rows, so the header row is not included.
Accessible table markup: thead, scope and caption
The header row is written inside <thead> and its cells use <th scope="col">. Screen readers use that to announce a column name before each value, so a reader hears Units, 1200 and not just 1200. The caption is the table's title and is read first. Turn on First column is a row header and the first cell of every row becomes <th scope="row">, which suits tables where each row is named, such as a price list.
Turn First row is the header off for data with no header. The table then has only a <tbody> and no <th> cells. That is accurate markup, but it gives assistive software less to work with, so keep a header whenever the data has one.
Special characters and line breaks are escaped
A cell can contain characters that mean something in HTML. If they were copied into the table as they are, a cell holding a tag would be read by the browser as markup. The tool replaces the ampersand, the angle brackets and the double quote with their entities, and turns a line break inside a quoted cell into <br>:
<td>R&D <team></td>
<td>Said "hi"<br>then left</td>That output came from the cells R&D <team> and a quoted cell that contained a line break. If you need to escape or decode entities in other text, HTML Encoder and HTML Decoder do that on their own.
CSV to HTML table for email, with inline styles
Some email apps ignore or remove a style block in the message. The usual fix is to put the style on every tag. The Email, inline styles preset does that, so the table keeps its borders and padding without a style block. For a two-column table the first body row looks like this:
<tr>
<td style="border:1px solid #d0d5dd;padding:8px 12px;text-align:left;">Pen</td>
<td style="border:1px solid #d0d5dd;padding:8px 12px;text-align:right;">$2.50</td>
</tr>The result is longer than a table with a style block, which is the cost of that approach. Send yourself a test message before you rely on it, because email apps differ and no converter can promise how each will draw it.
Convert an Excel or Google Sheets range to an HTML table
Cells copied from Excel or Google Sheets reach the clipboard as text with a tab between columns. Paste them into the box and the tool detects the tab on its own, so no export step is needed. The Separator menu lets you force a comma, semicolon or tab when the detection guesses wrong, which can happen if the first line has no separator at all.
Only the values come across, not the formatting. Cell colors, merged cells and formulas are not part of the clipboard text. For the other direction, from a table on a web page back to a spreadsheet file, use HTML Table to CSV.
Styles and options explained
- Bare HTML: only the table tags, with no class or style. Use it when your site or CMS already styles tables.
- Simple CSS: a short style block with collapsed borders, padding and a shaded header, plus a class on the table. The class defaults to data-table.
- Striped CSS: the same, with every other body row shaded.
- Email, inline styles: all styling on the tags and no style block or class.
- Right-align numbers: a column is aligned right when every non-empty cell in it is a number, such as 1200, -2.5, 3% or $18,000.00. A date or an ID with letters is left alone. Bare HTML has no styling, so this has no effect there.
- Caption and class name: the caption is written as a caption element. The class name is cleaned to letters, digits, dashes and underscores.
- Separator: Detect looks at the first line. Choose comma, semicolon or tab to override it.
Do you need the same data as a Markdown table instead? CSV to Markdown writes it, and HTML Table to Markdown converts a table that already exists on a page. If you have several CSV files with the same columns, Merge CSV Files joins them first.
CSV to HTML table in Python
With the pandas package installed, one line writes a table:
import pandas as pd
df = pd.read_csv('data.csv')
print(df.to_html(index=False))Pandas escapes cell text by default and adds a dataframe class. It does not add scope attributes, a caption or email-ready styles, so you edit the result afterwards. This page produces those directly and lets you see the table before you copy it.
Limits
- The tool writes a static table. It adds no sorting, search or paging scripts.
- Merged cells cannot be created from CSV, so every row has the same number of cells. Short rows are padded with empty cells and the notes tell you how many.
- Empty lines are skipped, and cells are trimmed of spaces at both ends.
- Links and formatting in a cell are written as plain text, not as tags.
- Data is limited to 1,000,000 cells and 2,000 columns. A very long table is shown in the preview as its first 200 rows, while the code, Copy and Download contain all of it.
- Cells that begin with = + - or @ are kept as text. That is correct for a web page. Check data from sources you do not trust before you paste the same values into a spreadsheet.
Your data is converted in your browser. It is not uploaded or stored. See the Privacy Policy for details.