Xerobit

HTML Table Generator: Convert CSV to HTML Table Code

Paste comma-separated or tab-separated values into this html table generator to produce clean, properly indented HTML table markup. It handles header rows, captions, CSS classes and escapes special characters automatically. Everything runs locally in your browser, so no data is uploaded anywhere.

Paste your delimited data here.

HTML Output

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Age</th>
      <th>City</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Alice</td>
      <td>30</td>
      <td>New York</td>
    </tr>
    <tr>
      <td>Bob</td>
      <td>25</td>
      <td>London</td>
    </tr>
  </tbody>
</table>

How to use the html table generator

  1. Paste your CSV or TSV data into the text area.
  2. Select the correct delimiter (comma or tab) for your data.
  3. Check First row is header if your first line contains column names.
  4. Optionally add a caption and CSS classes for styling.
  5. Copy the generated html table code from the output area.

How the HTML table code is built

The html table generator parses each line of your input according to the selected delimiter. When the delimiter is a comma, it follows standard CSV rules: fields wrapped in double quotes can contain commas, and literal quote marks inside those fields are represented by two consecutive double quotes (""). Tab-separated values split strictly on the tab character.

After splitting the text into rows and cells, every cell value is passed through an escape function that replaces & with &amp;, < with &lt; and > with &gt;. This prevents any pasted content from being interpreted as markup. The escaped cells are then wrapped in <th> tags for the header row or <td> tags for body rows, and the whole structure is indented using the number of spaces you selected.

Example output

Here is what the tool produces for a simple two-row CSV with a header:

Input CSVGenerated HTML
Name,Age
Alice,30
<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Age</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Alice</td>
      <td>30</td>
    </tr>
  </tbody>
</table>

If you add the CSS class striped and the caption Users, the opening tag becomes <table class="striped"> and a <caption>Users</caption> element is inserted immediately after it.

Practical use cases

Converting spreadsheet exports to HTML is the most common reason people use a csv to html table workflow. You can copy a range directly from Excel or Google Sheets, paste it here with the tab delimiter selected, and get ready-to-use markup for a web page or email template.

Developers building static sites often need to create html table elements quickly without writing the repetitive tags by hand. By adding a framework class like table table-bordered in the CSS classes field, the output integrates directly with Bootstrap or Tailwind setups.

Technical writers and documentation maintainers also benefit when they need to embed structured data in Markdown files that support raw HTML blocks, or when preparing content for systems where a markdown table generator would not provide enough control over attributes like class or caption.

Common mistakes to avoid

Choosing the wrong delimiter is the most frequent error. If your data uses tabs but you leave the setting on comma, the entire row will be treated as a single cell. Always verify whether your source data is comma-separated or tab-separated before generating the html table code.

Another issue arises with unescaped characters. If your data contains ampersands or angle brackets and you bypass a tool like this to write the markup manually, browsers may interpret them as broken tags. This generator always escapes &, < and > so the content renders safely. For more complex encoding needs, you can pair this with an html encoder.

Finally, inconsistent row lengths can produce malformed tables. While browsers are forgiving and will render missing cells as empty space, it is best practice to ensure every row has the same number of columns. Check your source data for trailing delimiters or missing values before pasting.

HTML table element reference

Understanding the elements this tool generates helps you customize the result further. Here is a quick reference of the tags used:

ElementPurpose
<table>Root container for the tabular data.
<caption>Title or description displayed above the table.
<thead>Groups the header row(s) for semantic structure.
<tbody>Groups the main data rows.
<tr>Defines a single table row.
<th>Header cell, typically bold and centered by default.
<td>Standard data cell.

The class attribute on the <table> element allows you to attach stylesheets without modifying the generated structure. The <caption> element improves accessibility by giving screen readers a summary of the table contents.

Worked examples

ExampleInputResult
Simple CSV with headerCSV or TSV data: a,b / 1,2; Delimiter: comma; First row is header: yes; Indentation: 2<table> / <thead> / <tr> / <th>a</th> / <th>b</th> / </tr> / </thead> / <tbody> / <tr> / <td>1</td> / <td>2</td> / </tr> / </tbody> / </table>
TSV with caption and classesCSV or TSV data: Name Age / Alice 30 / Bob 25; Delimiter: tab; First row is header: yes; Caption (optional): Team Members; CSS classes (optional): table dark; Indentation: 4<table class="table dark"> / <caption>Team Members</caption> / <thead> / <tr> / <th>Name</th> / <th>Age</th> / </tr> / </thead> / <tbody> / <tr> / <td>Alice</td> / <td>30</td> / </tr> / <tr> / <td>Bob</td> / <td>25</td> / </tr> / </tbody> / </table>
Quoted CSV fieldsCSV or TSV data: "Smith, John",30 / "Doe, Jane",25; Delimiter: comma; First row is header: no; Indentation: 2<table> / <tbody> / <tr> / <td>Smith, John</td> / <td>30</td> / </tr> / <tr> / <td>Doe, Jane</td> / <td>25</td> / </tr> / </tbody> / </table>

FAQ

Does this html table generator handle quoted CSV fields?

Yes. When the delimiter is set to comma, fields enclosed in double quotes are parsed correctly. Commas inside quotes are treated as part of the cell value, and two consecutive double quotes inside a quoted field are converted to a single literal quote.

Are special characters escaped in the output?

Every cell value is escaped before being placed in the markup. Ampersands become &amp;, less-than signs become &lt; and greater-than signs become &gt;. This ensures your data never breaks the surrounding HTML.

Can I convert TSV data instead of CSV?

Yes. Select Tab (TSV) from the delimiter dropdown. The tool will split each line on tab characters instead of commas, which is useful for data copied directly from spreadsheets.

Is my data sent to a server?

No. The conversion happens entirely in your browser using JavaScript. Nothing you paste into the textarea is uploaded or stored anywhere.

What does the CSS classes field do?

If you enter one or more class names in that field, they are added as a class attribute on the opening table tag. For example, entering 'striped bordered' produces the markup with class="striped bordered".

Why use this instead of writing the HTML by hand?

Writing table markup manually is tedious and prone to errors, especially with many rows. This tool lets you create html table structures instantly from existing data while handling indentation and escaping automatically.