CSV to Markdown
Convert CSV to a Markdown table
CSV Input
Markdown Output
What Is CSV to Markdown Conversion?
Converting CSV to a Markdown table is a common developer task. CSV (Comma-Separated Values) stores tabular data as plain text, with each row on its own line and fields separated by a delimiter such as a comma or tab. It is the default export format for spreadsheets, SQL clients, and analytics tools. CSV files are compact and easy to generate, but they have no built-in way to control how the data looks when displayed. A CSV file opened in a text editor is a wall of comma-delimited strings, readable by machines but hard for humans to scan.
Markdown tables solve this readability problem. They are defined by the GitHub Flavored Markdown (GFM) spec and supported by GitHub, GitLab, Bitbucket, Notion, Obsidian, and static site generators like Hugo and Jekyll β anywhere Markdown is processed, they render as clean HTML tables. The syntax uses pipe characters to separate columns and a mandatory separator row of dashes between the header and body rows.
Converting CSV to a Markdown table means wrapping each row in pipe-delimited syntax and inserting the separator row after the header. The first row of the CSV becomes the table header, and each subsequent row becomes a body row. You need this whenever you're pasting structured data into a README, a pull request description, a wiki page, or any Markdown documentation system.
Why Use This Tool?
This converter parses your CSV in the browser, builds the Markdown table output instantly, and never transmits your data to a server.
CSV to Markdown Use Cases
Markdown Table Syntax Reference
Markdown tables follow the GitHub Flavored Markdown (GFM) specification. Every table requires a header row, a separator row, and one or more body rows. The separator row controls column alignment.
| Element | Syntax | Description |
|---|---|---|
| Column separator | | | Separates each cell within a row |
| Header row | | Name | Age | | First row of the table, defines column names |
| Separator row | | --- | --- | | Required second row; separates header from body |
| Left align | | :--- | | Default alignment β colon on the left side |
| Center align | | :---: | | Colons on both sides of the dashes |
| Right align | | ---: | | Colon on the right side only |
| Escaped pipe | \| | Use backslash to include a literal pipe in cell text |
CSV vs Markdown Table
Both formats represent tabular data as plain text. CSV is for machines and data pipelines; Markdown tables are for humans reading documentation.
Code Examples
The following examples show how to convert CSV to a Markdown table programmatically in different languages. Each produces a valid GFM table.
const csv = `name,age,city
Alice,30,Berlin
Bob,25,Tokyo`
const [headerLine, ...rows] = csv.trim().split('\n')
const headers = headerLine.split(',')
const separator = '| ' + headers.map(() => '---').join(' | ') + ' |'
const headerRow = '| ' + headers.join(' | ') + ' |'
const bodyRows = rows.map(row =>
'| ' + row.split(',').join(' | ') + ' |'
)
const markdown = [headerRow, separator, ...bodyRows].join('\n')
// β | name | age | city |
// β | --- | --- | --- |
// β | Alice | 30 | Berlin |
// β | Bob | 25 | Tokyo |import csv
import io
csv_string = """name,age,city
Alice,30,Berlin
Bob,25,Tokyo"""
reader = csv.reader(io.StringIO(csv_string))
rows = list(reader)
headers = rows[0]
lines = []
lines.append('| ' + ' | '.join(headers) + ' |')
lines.append('| ' + ' | '.join('---' for _ in headers) + ' |')
for row in rows[1:]:
lines.append('| ' + ' | '.join(row) + ' |')
print('\n'.join(lines))
# β | name | age | city |
# β | --- | --- | --- |
# β | Alice | 30 | Berlin |
# β | Bob | 25 | Tokyo |
# With pandas (one-liner)
import pandas as pd
df = pd.read_csv(io.StringIO(csv_string))
print(df.to_markdown(index=False))package main
import (
"encoding/csv"
"fmt"
"strings"
)
func main() {
input := "name,age,city\nAlice,30,Berlin\nBob,25,Tokyo"
r := csv.NewReader(strings.NewReader(input))
records, _ := r.ReadAll()
headers := records[0]
var lines []string
lines = append(lines, "| "+strings.Join(headers, " | ")+" |")
sep := make([]string, len(headers))
for i := range sep {
sep[i] = "---"
}
lines = append(lines, "| "+strings.Join(sep, " | ")+" |")
for _, row := range records[1:] {
lines = append(lines, "| "+strings.Join(row, " | ")+" |")
}
fmt.Println(strings.Join(lines, "\n"))
// β | name | age | city |
// β | --- | --- | --- |
// β | Alice | 30 | Berlin |
// β | Bob | 25 | Tokyo |
}# Using Miller (mlr) β convert CSV to Markdown table mlr --icsv --omarkdown cat data.csv # β | name | age | city | # β | --- | --- | --- | # β | Alice | 30 | Berlin | # Using csvtomd (pip install csvtomd) csvtomd data.csv # Using pandas in a one-liner python3 -c " import pandas as pd, sys print(pd.read_csv(sys.argv[1]).to_markdown(index=False)) " data.csv