CSV to HTML Table

Convert CSV to an HTML table

Try an example

CSV Input

HTML Output

Runs locally · Safe to paste secrets
HTML table will appear here…
First row is header:

What is CSV to HTML Table Conversion?

CSV to HTML table conversion takes comma-separated values and transforms them into structured HTML markup that browsers can render as a visual table. The output uses standard HTML table elements defined in the HTML Living Standard: table, thead, tbody, tr, th, and td. This process maps each CSV row to a tr element and each field to a td or th cell.

CSV files store data as plain text with rows separated by newlines and fields separated by delimiters (typically commas). While CSV works well for data storage and transfer between applications like Excel, Google Sheets, and databases, it has no presentation layer. HTML tables add that layer by wrapping data in semantic markup that supports styling with CSS, sorting with JavaScript, and accessibility through attributes like scope and aria-label.

The conversion must handle several edge cases defined in RFC 4180: quoted fields containing commas or newlines, escaped double quotes within fields, and varying delimiters (semicolons, tabs, pipes). A correct converter also escapes HTML entities in cell content, replacing <, >, &, and quote characters with their entity equivalents to prevent broken markup or XSS vulnerabilities.

Why Use a CSV to HTML Table Converter?

Building HTML tables by hand is tedious and error-prone, especially for datasets with dozens of columns or hundreds of rows. This converter handles the parsing, escaping, and formatting in one step.

Instant table generation
Paste CSV and get a complete HTML table with proper thead and tbody structure. No manual tag writing, no counting cells per row.
🔒
Privacy-first processing
All conversion runs in your browser using JavaScript. Your CSV data is never sent to a server, never logged, and never stored.
🎯
Clean, valid output
The generated HTML follows the HTML Living Standard with correct nesting: table > thead/tbody > tr > th/td. Special characters are entity-escaped to prevent rendering issues.
📋
Flexible input formats
Auto-detects commas, semicolons, tabs, and pipes as delimiters. Handles RFC 4180 quoting rules including escaped double quotes and multiline fields.

CSV to HTML Table Use Cases

Frontend development
Generate an HTML table from sample data to prototype a UI component. Copy the output directly into a React, Vue, or Angular template and apply CSS classes.
Email template building
Email clients (Outlook, Gmail) render HTML tables reliably but reject most CSS layout methods. Convert a CSV contact list or report into a table you can embed in an HTML email.
Static site content
Drop a generated HTML table into a Jekyll, Hugo, or Astro page when your data comes from a spreadsheet export. No build-time plugin needed.
QA test data display
Convert a CSV test matrix into an HTML table for inclusion in a test report or Confluence page. Reviewers can scan results without opening a spreadsheet application.
Data journalism
Turn a CSV dataset into an HTML table that can be styled and embedded in a CMS article. Add CSS for striping, sorting, or responsive wrapping after conversion.
Teaching and documentation
Create HTML table examples from real CSV data for tutorials, API docs, or course materials. Students see both the source format and the rendered output.

HTML Table Element Reference

A well-structured HTML table uses semantic elements that separate headers, body, and footer. Screen readers and search engines use these elements to understand the table structure. Grouping rows with thead, tbody, and tfoot lets browsers apply independent scrolling and repeat header rows in print layouts.

ElementRoleNotes
<table>Table rootWraps the entire table structure
<thead>Header groupContains header rows; browsers repeat on print page breaks
<tbody>Body groupContains data rows; enables independent scrolling with CSS
<tfoot>Footer groupSummary or totals row; renders after tbody
<tr>Table rowGroups cells horizontally
<th>Header cellBold and centered by default; supports scope attribute for accessibility
<td>Data cellStandard content cell; accepts any inline or block HTML
<caption>Table captionVisible title above the table; read by screen readers first
<colgroup>Column groupApplies width or style to entire columns without per-cell classes

CSV vs HTML Table

CSV is a transport format optimized for simplicity, while HTML is a presentation format optimized for rendering, accessibility, and interactivity in browsers.

CSV
Plain text format. No data types: every value is a string. No styling, no nesting, no metadata. Rows are newline-delimited, fields are delimiter-separated. File size is minimal. Universally supported by spreadsheets, databases, and ETL tools. Defined by RFC 4180.
HTML Table
Markup format with semantic structure. Distinguishes headers (th) from data (td). Supports attributes like colspan, rowspan, scope, and class for styling and accessibility. Parsed by browsers into the DOM for CSS and JavaScript interaction. Can be sorted, filtered, or paginated with libraries like DataTables without any server-side processing.

Code Examples

Here is how to convert CSV to HTML tables programmatically in different languages. Each example handles the header row separately and escapes HTML entities in cell content. These snippets are ready to drop into a script, a build pipeline, or a backend API endpoint that generates HTML reports from data exports.

JavaScript (browser / Node.js)
// CSV string → HTML table with thead/tbody
const csv = `name,age,city
Alice,30,Berlin
Bob,25,Tokyo`

function csvToHtmlTable(csv) {
  const rows = csv.trim().split('\n').map(r => r.split(','))
  const [headers, ...data] = rows
  const ths = headers.map(h => `<th>${h}</th>`).join('')
  const trs = data.map(row =>
    '    <tr>' + row.map(c => `<td>${c}</td>`).join('') + '</tr>'
  ).join('\n')
  return `<table>
  <thead><tr>${ths}</tr></thead>
  <tbody>
${trs}
  </tbody>
</table>`
}

console.log(csvToHtmlTable(csv))
// → <table><thead><tr><th>name</th>...</tr></thead><tbody>...</tbody></table>
Python
import csv, io, html

csv_string = """name,age,city
Alice,30,Berlin
Bob,25,Tokyo"""

reader = csv.reader(io.StringIO(csv_string))
headers = next(reader)

lines = ['<table>', '  <thead>', '    <tr>']
for h in headers:
    lines.append(f'      <th>{html.escape(h)}</th>')
lines += ['    </tr>', '  </thead>', '  <tbody>']

for row in reader:
    lines.append('    <tr>')
    for cell in row:
        lines.append(f'      <td>{html.escape(cell)}</td>')
    lines.append('    </tr>')

lines += ['  </tbody>', '</table>']
print('\n'.join(lines))
# → well-formed HTML table with escaped special characters
PHP
<?php
$csv = "name,age,city\nAlice,30,Berlin\nBob,25,Tokyo";
$rows = array_map('str_getcsv', explode("\n", trim($csv)));
$headers = array_shift($rows);

echo "<table>\n  <thead>\n    <tr>\n";
foreach ($headers as $h) {
    echo "      <th>" . htmlspecialchars($h) . "</th>\n";
}
echo "    </tr>\n  </thead>\n  <tbody>\n";

foreach ($rows as $row) {
    echo "    <tr>\n";
    foreach ($row as $cell) {
        echo "      <td>" . htmlspecialchars($cell) . "</td>\n";
    }
    echo "    </tr>\n";
}
echo "  </tbody>\n</table>";
// → <table><thead>...<th>name</th>...</thead><tbody>...</tbody></table>
CLI (awk / csvtool)
# Using awk — quick one-liner for simple CSV (no quoted fields)
awk -F, 'NR==1{print "<table><thead><tr>";for(i=1;i<=NF;i++)print "<th>"$i"</th>";print "</tr></thead><tbody>"}
NR>1{print "<tr>";for(i=1;i<=NF;i++)print "<td>"$i"</td>";print "</tr>"}
END{print "</tbody></table>"}' data.csv

# Using Python one-liner for RFC 4180-compliant parsing
python3 -c "
import csv, sys, html
r=csv.reader(sys.stdin); h=next(r)
print('<table><thead><tr>')
print(''.join(f'<th>{html.escape(c)}</th>' for c in h))
print('</tr></thead><tbody>')
for row in r:
    print('<tr>'+''.join(f'<td>{html.escape(c)}</td>' for c in row)+'</tr>')
print('</tbody></table>')
" < data.csv

Frequently Asked Questions

How do I convert CSV to an HTML table?
Paste your CSV into the input panel. The converter parses each row, maps the first row to th elements inside thead, and wraps remaining rows in td elements inside tbody. The output is a complete, copy-ready HTML table.
Is the generated HTML accessible?
The output uses thead and th elements, which give screen readers structural information about the table. For full WCAG 2.1 compliance, you should add scope attributes to header cells and a caption element describing the table content.
What happens to special characters like < and & in my CSV?
The converter escapes all HTML-sensitive characters: < becomes &lt;, > becomes &gt;, & becomes &amp;, and double quotes become &quot;. This prevents broken markup and protects against XSS if you embed the table in a web page.
Can I convert a semicolon-separated or tab-separated file?
Yes. The tool auto-detects the delimiter by analyzing the first row of your input. It supports commas, semicolons, tabs, and pipes. You do not need to pre-convert your file to comma-separated format.
What is the difference between CSV to HTML and CSV to Markdown tables?
CSV to HTML produces browser-renderable markup with semantic elements (thead, tbody, th, td) and supports styling via CSS classes. CSV to Markdown produces pipe-delimited plain text tables used in GitHub READMEs and documentation. Use HTML when you need styling control or email compatibility; use Markdown for docs and repositories.
Does the converter handle CSV files with quoted fields?
Yes. The parser follows RFC 4180 rules: fields wrapped in double quotes can contain commas, newlines, and literal double quotes (escaped as two consecutive double quotes). The quotes are stripped from the output, and the field content is placed inside the HTML cell.
Can I style the generated HTML table with CSS?
The output is plain HTML without inline styles or classes, so you can apply any CSS you want. Add a class to the table element, then use selectors like table th for headers, table td for cells, and table tr:nth-child(even) for zebra striping. Frameworks like Bootstrap and Tailwind have built-in table utility classes.