How to Convert an HTML Table to CSV
Copy the table markup from the page source, paste it into a converter, and each row becomes a CSV line with cells separated by commas and quoted where needed. The two things that break alignment are merged cells, which occupy more columns than they declare, and nested tables, which produce rows that do not belong to the outer table.
HTML Table to CSV
Pull a table out of a web page and turn it into CSV.
Copying a table straight from a rendered page usually loses the structure: the browser hands over text with tabs or spaces, and any cell containing a line break destroys the row alignment. Working from the markup avoids that entirely, because the cell boundaries are explicit.
The awkward cases are all structural. A table designed for human reading may merge cells across columns or rows, and CSV has no way to express that — so the converter has to make a decision about where the missing values go.
Step by step
-
Copy the markup, not the rendered table
Right-click the table, choose Inspect, then copy the outer HTML of the table element. Selecting the table on the page and copying gives you text whose columns are only visually aligned, which is not recoverable.
-
Include the whole table element
Start at the opening table tag and end at its closing tag. A fragment beginning mid-row leaves the parser without the row structure, and header cells outside the copied section are lost.
-
Decide how header cells are treated
Header cells usually become the first CSV row. If the table has two header rows — a grouped header above a detailed one — you will normally want to keep only the detailed row and rename the columns afterwards.
-
Check rows with merged cells
A cell spanning two columns produces one value where the other rows have two, so everything after it shifts left. Compare the cell count of a merged row against a normal one, and insert the empty cells the span implied.
-
Verify the quoting on text columns
Any cell containing a comma must be quoted in the output, or the spreadsheet will split it. Check one long text cell before trusting the whole file, and remember that Excel can still damage the result when opening it.
Example
A small table and the CSV it produces. The comma inside a cell forces quoting.
HTML
<table>
<tr><th>City</th><th>Country</th></tr>
<tr><td>Leeds</td><td>England</td></tr>
<tr><td>Cork</td><td>Ireland, Munster</td></tr>
</table>
CSV
City,Country
Leeds,England
Cork,"Ireland, Munster"
Frequently asked questions
Why not just copy and paste the table into Excel?
What happens to merged cells?
Can I convert a table that is generated by JavaScript?
What about nested tables?
Will the CSV open correctly in Excel?
Tools used in this guide
All tools →- HTML Table to CSV Pull a table out of a web page and turn it into CSV. In your browser
- CSV to JSON Converter Turn CSV rows into a clean JSON array of objects. In your browser
- HTML to Text Converter Extract readable plain text from HTML, keeping the structure. In your browser
- CSV Column Extractor Keep only the columns you need from a CSV file. In your browser
Related guides
All guides →- How to Convert CSV to JSON Turn a spreadsheet export into a clean JSON array, with the delimiter and header options that matter.
- How to Fix CSV Files Broken by Excel Leading zeros stripped, dates reformatted, long numbers turned into scientific notation, and accents turned to mojibake.
- How to Make a Markdown Table Build a pipe table, set alignment, and handle the content Markdown tables cannot hold.
Last reviewed .