Add borders to Markdown tables
Markdown has no border syntax. Compare renderer CSS, inline HTML, grid tables and box-drawing text, and see how each holds up when copied, shared or read aloud.
If you want a Markdown table with visible borders, the first thing to know is that Markdown itself has no border setting. The pipes and hyphens in a table define structure: where columns split and which row is the header. Whether lines appear around cells is decided later by whatever renders the Markdown. This review covers the four realistic approaches, what each one changes, and how well the result survives copying, sharing and assistive technology.
Short recommendation
For most people, the best way to get bordered tables is to keep a standard pipe table and add borders with CSS in the place where it is displayed. The table stays a real table that screen readers, search tools and editors understand, and the borders are purely visual. The tradeoff is control. If you publish to a hosted platform that does not let you add CSS, you get whatever borders its stylesheet provides, which may be none.
Character-drawn borders, made with box-drawing symbols or ASCII art inside a code block, are only a good fit when the destination is plain text: terminal output, commit messages, plain-text email, or chat tools that do not render Markdown tables. In almost every other case a plain pipe table, with borders left to the renderer, is the safer choice.
What "adding a border" actually changes
The word "border" covers two different operations, and it helps to separate them. One is visual presentation. The table's characters and structure are unchanged, and a stylesheet draws lines around cells. The other is character substitution. Line-drawing characters are typed into the text itself, so the border becomes part of the content. The first approach changes how the table looks. The second changes what the text contains.
Option 1: Standard pipe table, borders from the renderer
| Item | Qty |
|--------|-----|
| Apples | 3 |
| Pears | 12 |
This is the GitHub Flavored Markdown table syntax that many tools support. The leading and trailing pipes are optional in that syntax. Including them makes the source look boxed in, but it does not add borders to the rendered output. Lining up the columns with spaces also affects only readability in the source. Whether borders appear depends entirely on the stylesheet of the viewer, editor preview or site theme. Some apply cell borders by default and others show a borderless grid.
Option 2: Your own CSS
table {
border-collapse: collapse;
}
th, td {
border: 1px solid #999;
padding: 0.25em 0.5em;
}
If you control the site, for example with a static site generator, a documentation theme or an exported HTML file, a rule like this adds borders to every rendered Markdown table. The border-collapse rule merges adjacent cell borders into single lines rather than doubled ones. The Markdown source stays clean and portable. To style only some tables, you need a way to attach a class. Plain Markdown tables cannot carry one, so this depends on extensions offered by your toolchain.
Option 3: Inline HTML table
<table border="1">
<tr><th>Item</th><th>Qty</th></tr>
<tr><td>Apples</td><td>3</td></tr>
<tr><td>Pears</td><td>12</td></tr>
</table>
Many Markdown processors pass raw HTML through, so an HTML table can carry its own border instructions. The border attribute is obsolete in the current HTML standard, although browsers generally still honor it. A style attribute is the modern alternative. The decisive limitation is that hosted platforms often sanitize user HTML and may remove style or presentational attributes. The table then renders without the borders you wrote. Check the platform's documentation on allowed HTML before relying on this. You also give up the readability of Markdown source: HTML tables are harder to edit by hand and to review in diffs.
Option 4: Grid tables or box-drawing characters
+--------+-----+
| Item | Qty |
+========+=====+
| Apples | 3 |
+--------+-----+
| Pears | 12 |
+--------+-----+
This bordered-looking layout is Pandoc's grid table syntax. In Pandoc and other tools that support it, it converts into a real table, and the plus signs and hyphens are structural markers rather than visible borders. A renderer without grid table support will not treat it as a table at all, so test it in your actual destination.
┌────────┬─────┐
│ Item │ Qty │
├────────┼─────┤
│ Apples │ 3 │
│ Pears │ 12 │
└────────┴─────┘
This version uses Unicode box-drawing characters. It is not a table to any software. It is text arranged to look like one, and it should go inside a code block so the renderer uses a monospaced font and keeps the spacing. Every border character is stored in the content, so editing a cell means redrawing the lines around it by hand or regenerating the table with a tool.
How the options compare
| Approach | What changes | Is it a real table? | Main risk |
| Pipe table, default styling | Nothing; renderer decides | Yes | Borders may not appear |
| Pipe table plus your CSS | Visual presentation only | Yes | Requires control over styling |
| Inline HTML table | Markup carries border settings | Yes, where HTML is allowed | Attributes may be stripped by sanitizers |
| Grid table | Source syntax | Yes, only in supporting tools | Shows as plain text elsewhere |
| Box-drawing text in code block | Stored characters | No | Alignment and accessibility problems |
Will it stay readable after copying or sharing?
Copy and paste
Copying a rendered HTML table usually carries cell structure into destinations that accept rich content, such as many word processors and spreadsheets. CSS borders are presentation, so whether they come along depends on the receiving application. Box-drawing tables copy as ordinary characters. They keep their alignment only where the destination uses a monospaced font. Pasted into a proportional font, the columns drift apart. Characters with non-standard display widths can also break alignment even in monospaced settings. Wide East Asian characters, emoji and emoji sequences made of several code points are common examples. This happens because the number of characters no longer matches the number of columns shown on screen.
Accessibility
Real tables from Options 1 to 3 expose rows, columns and headers to assistive technology, so a screen reader can navigate cell by cell and announce header context. A box-drawing or ASCII table exposes none of that. Depending on the screen reader and its verbosity settings, the border characters may be skipped, read as punctuation, or announced by their Unicode names, and the reader has to piece together which value belongs to which column. If you use a character-drawn table, give the same information in a form that does not depend on layout as well: a real table, a list, or a sentence.
Search and editing
Search engines and site search can read cell text in real tables. In box-drawing text the words are still present, but they sit among line characters and lose their row and column meaning. For editing, pipe tables are the easiest to maintain. Grid and box-drawing tables become tedious once cell contents change length, because the borders have to be redrawn.
When to skip borders and keep it plain
- The table will be read in several places you do not control, such as a README that is also viewed in editors, package registries or terminals.
- The audience includes screen reader users and you cannot provide a real table.
- The data changes often and someone will edit it by hand.
- The content is short enough that a list or a sentence communicates it just as well.
- The destination strips HTML and styling, so any border effort will be lost.
Evidence gaps
This review relies on documented syntax and general rendering principles. It does not draw on tests of particular platforms, editors or screen readers. Default table styling, HTML sanitization rules and grid table support differ between tools and can change over time. Before committing to an approach, preview the table in the exact place it will be published. Check that destination's documentation for allowed HTML and styling. If accessibility matters, test with the screen reader your readers actually use.