Staaarter

HTML Table to CSV Converter

Finds the first <table> element in a pasted HTML fragment and extracts its rows into CSV, reading <th>/<td> cell text via a real browser HTML parser. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-29
By Staaarter Team
conversionstructured-datahtml

Overview

Introduction

Copying a table off a web page usually leaves you with an HTML snippet, not usable data. This tool parses that snippet's first <table> and turns it straight into CSV.

It uses the browser's own HTML parser rather than regular expressions, so it handles real-world, slightly messy markup the same way a browser would.

What Is HTML Table to CSV Converter?

An HTML-table-to-CSV converter that locates the first <table> in a pasted HTML fragment and reads every <tr>'s <th>/<td> cell text into a row of CSV.

It relies on DOMParser, a standard browser API, to build a real DOM tree from the input rather than attempting to scrape tags with regular expressions.

How HTML Table to CSV Converter Works

The input string is parsed into a document via `new DOMParser().parseFromString(html, "text/html")`, then the first matching <table> element is located with a CSS selector.

Every <tr> inside that table is walked in order, and each row's <th>/<td> children have their trimmed text content collected into one CSV row; rows are then padded to a rectangle and serialized with RFC 4180 quoting.

When To Use HTML Table to CSV Converter

Use it when you've copied an HTML table from a web page, email, or exported report and need the data as CSV for a spreadsheet or script.

It's also useful for quickly checking how many rows and columns a scraped or copy-pasted table snippet actually contains.

Features

Advantages

  • Uses a real browser HTML parser (DOMParser), so it tolerates imperfect or unclosed tags the way a browser would.
  • Automatically finds the first <table> in a larger HTML document, so you don't have to hand-trim the snippet first.
  • Output is properly RFC 4180-quoted CSV, safe for any downstream spreadsheet or parser.

Limitations

  • Only the first <table> in the input is converted; additional tables are ignored.
  • colspan and rowspan aren't expanded, so merged cells produce a row with fewer cells than expected rather than being duplicated across the merge.

Examples

Converting a simple HTML table

Input

<table>
  <tr><th>id</th><th>name</th></tr>
  <tr><td>1</td><td>Ada Lovelace</td></tr>
  <tr><td>2</td><td>Alan Turing</td></tr>
</table>

Output

id,name
1,Ada Lovelace
2,Alan Turing

Each <tr>'s <th>/<td> cells become one CSV row, in the order they appear in the table.

Best Practices & Notes

Best Practices

  • If a page has multiple tables, isolate the one you want with your browser's 'copy element' or 'inspect' tool before pasting it in.
  • Watch for merged cells (colspan/rowspan) in the source table; verify the row count in the output matches what you expect.
  • Use CSV to HTML Converter afterward to confirm a round trip reproduces the same table structure.

Developer Notes

Using DOMParser instead of a regex scrape is deliberate: HTML tag soup (unclosed <tr>, attributes with unescaped quotes, mixed case tags) is exactly what a general-purpose parser is built to normalize, and reimplementing that with regular expressions would be both slower to write and far more fragile.

HTML Table to CSV Converter Use Cases

  • Extracting a table copied from a web page or Wikipedia article into CSV
  • Pulling structured data out of an HTML email or exported report
  • Quickly checking the row/column count of a scraped table snippet

Common Mistakes

  • Pasting an entire HTML page and expecting every table to convert; only the first one is used.
  • Assuming merged cells (colspan/rowspan) will be duplicated across columns; they aren't, so rows can come out misaligned.

Tips

  • If the output looks jagged, check the source table for colspan/rowspan and consider un-merging those cells first.
  • Pair with CSV to HTML Converter to verify the round trip before relying on the extracted data.

References

Frequently Asked Questions