How to Display a CSV File as an HTML Table on Your Website
By the DataSwitch Pro team · · 3 min read
Quick answer
To show CSV data on a web page, convert it into an HTML <table> with the header row in <thead> as <th scope="col"> cells and the data rows in <tbody>, escaping characters such as < and &. Generate the markup with a CSV to HTML table converter or a few lines of code, paste it into your page (in WordPress, a Custom HTML block), and style it with CSS. For data that changes often, load the CSV with JavaScript instead of pasting static HTML.
Price lists, opening hours, product specifications and results tables often start in a spreadsheet. Publishing them as a real HTML table — rather than a screenshot — keeps the text searchable, copyable, accessible to screen readers and readable on phones.
What good table markup looks like
HTML
<table class="data-table">
<caption>Shipping rates (EUR)</caption>
<thead>
<tr><th scope="col">Zone</th><th scope="col">Standard</th><th scope="col">Express</th></tr>
</thead>
<tbody>
<tr><td>Morocco</td><td>4.90</td><td>9.90</td></tr>
<tr><td>Europe</td><td>12.00</td><td>24.00</td></tr>
</tbody>
</table>
<caption>gives the table a title that screen readers announce.<th scope="col">marks header cells, so assistive technology can read “Express: 9.90” instead of a bare number.<thead>and<tbody>separate structure from data and make styling easy.- Values must be escaped: a product name containing
<or&would otherwise break the page or, worse, inject markup.
Step 1: Generate the HTML
- Export the sheet as CSV, or copy the range.
- Paste it into the CSV to HTML Table converter. The first row becomes the header, and special characters are escaped.
- Copy the generated markup.
In Python, pandas.read_csv("rates.csv").to_html(index=False) produces similar markup in one line.
Step 2: Style it with CSS
CSS
.data-table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
.data-table caption { text-align: left; font-weight: 600; margin-bottom: .5rem; }
.data-table th, .data-table td { padding: .5rem .75rem; border-bottom: 1px solid #e2e8f0; text-align: left; }
.data-table thead th { background: #f1f5f9; }
.data-table td:nth-child(n+2) { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
Right-aligning numeric columns and using tabular figures keeps decimals lined up. Wrap wide tables in <div class="table-wrap"> so they scroll horizontally on phones instead of breaking the layout.
Step 3: Add it to your site
- WordPress (block editor): add a Custom HTML block and paste the table, or paste into a Table block for simple tables you want to edit visually.
- Static sites: paste the markup into the page template or Markdown file (most generators allow raw HTML).
- Email newsletters: many email clients ignore external CSS, so use inline styles on cells and keep the table simple.
Sorting and searching
For a few dozen rows, plain HTML is enough. For longer tables, a small script can make columns sortable by clicking the header, or add a search box that hides non-matching rows. Libraries such as DataTables or List.js do this with a few lines of setup; keep the table readable without JavaScript so search engines and visitors with scripts disabled still see the data.
Static HTML or live data?
Pasting generated HTML is ideal for data that changes rarely. If the spreadsheet is updated every week, keep a CSV file on the server and render it in the page with JavaScript (for example with fetch and a CSV parser), or publish a Google Sheet and embed it. You then update one file instead of regenerating HTML each time.
Other output options
For a README or documentation that uses Markdown, generate a Markdown table instead with CSV to Markdown. To go the other way and pull a table off a web page into a spreadsheet, see copying a table from a website into Excel.
Try it on your own file. Free, private, and processed in your browser.
Frequently asked questions
Is an HTML table better than an image of a table for SEO?
Yes. Search engines can read the text in an HTML table, and visitors can copy it, zoom it and use screen readers.
How do I make a table responsive?
Wrap it in a container with overflow-x: auto so it scrolls horizontally on small screens, and keep columns few and short.
Can I convert Excel directly to an HTML table?
Export the sheet as CSV (or use Excel to CSV) and convert that. Excel's own “Save as Web Page” adds a lot of extra markup.
Do I need to escape characters?
Yes. <, > and & in values must be written as entities; a converter does this automatically.