Skip to content

Markdown Tables in VS Code: Preview, Format and Edit

By MarkdownTables.com editorial teamUpdated

On this page

How do I preview a Markdown table in VS Code?

The Markdown preview is built into VS Code and uses the markdown-it parser, which supports GitHub-style pipe tables, alignment colons and inline HTML such as <br>. No extension is needed. Paste this into a .md file and open the preview:

A table to test the preview with
Markdown
| Extension           | Formats tables | Lints tables |
| :------------------ | :------------: | :----------: |
| Markdown All in One |       ✅       |      ❌      |
| Prettier            |       ✅       |      ❌      |
| markdownlint        |       ❌       |      ✅      |
Preview
ExtensionFormats tablesLints tables
Markdown All in One✅❌
Prettier✅❌
markdownlint❌✅
Preview shortcuts
ActionWindows / LinuxmacOS
Open preview in a new tabCtrl+Shift+VCmd+Shift+V
Open preview to the sideCtrl+K then VCmd+K then V
Toggle between editor and previewCtrl+Shift+V againCmd+Shift+V again
Same, from the Command PaletteMarkdown: Open Preview to the SideMarkdown: Open Preview to the Side

The side preview scrolls with the editor and updates as you type, which is the quickest way to spot a broken delimiter row. A table that renders here will usually render on GitHub too. The differences come from raw HTML: GitHub strips style attributes and some tags, so check styled tables on GitHub itself.

Table borders in the preview

The preview follows your color theme, so table lines can be faint. Add your own stylesheet with the markdown.styles setting (a list of CSS file paths or URLs). This only changes the preview, not the file.

Stronger table borders in the previewCSS
/* .vscode/table-preview.css, referenced from "markdown.styles" */
table {
  border-collapse: collapse;
}
th,
td {
  border: 1px solid #8b949e;
  padding: 4px 10px;
}

How do I format (align) a Markdown table in VS Code?

VS Code has no built-in Markdown formatter. Format Document (Shift+Alt+F on Windows, Shift+Option+F on macOS, Ctrl+Shift+I on Linux) does nothing to a .md file until an extension provides a formatter. Once one is installed, it pads every cell so the pipes line up, which makes the source readable and keeps diffs clean.

Before: valid but hard to read
Markdown
| Setting | Default | Notes |
|---|:-:|---|
| editor.formatOnSave | false | Needs a formatter |
| editor.wordWrap | off | Turn off for tables |
Preview
SettingDefaultNotes
editor.formatOnSavefalseNeeds a formatter
editor.wordWrapoffTurn off for tables
After Format Document
Markdown
| Setting             | Default | Notes               |
| ------------------- | :-----: | ------------------- |
| editor.formatOnSave |  false  | Needs a formatter   |
| editor.wordWrap     |   off   | Turn off for tables |
Preview
SettingDefaultNotes
editor.formatOnSavefalseNeeds a formatter
editor.wordWrapoffTurn off for tables

Both versions render identically. Formatting only changes the source.

Open in editor : After Format Document

To format just one table, select it and run Format Selection (Ctrl+K Ctrl+F) where the formatter supports it. No editor available? The Markdown table formatter does the same in the browser.

VS Code extensions for Markdown tables

You need one formatter, and optionally a linter. Pick the formatter your project already uses; running two on the same file just makes them fight over the defaults.

VS Code extensions that help with Markdown tables
ExtensionWhat it does for tablesHow you use it
Markdown All in One (Yu Zhang)Formats and aligns tables, plus Markdown shortcuts, lists and a table-of-contents generatorFormat Document; format on save
Markdown Table Prettifier (darkriszty)Aligns tables only and leaves the rest of the file aloneFormat Document, or the extension’s own prettify command
Prettier (esbenp.prettier-vscode)Formats the whole Markdown file, tables includedFormat Document; format on save; also from the CLI and CI
markdownlint (David Anson)Warns about missing columns, inconsistent pipes and missing blank linesSquiggles in the editor; quick fixes for some rules
Table-editor extensionsTab moves to the next cell, Enter adds a row, the table re-aligns as you typeVaries; search the Marketplace for “markdown table”
Column-coloring extensionsColor each column so wide tables are easier to readPassive highlighting

Markdown All in One

The usual first install for Markdown in VS Code. Its table formatter runs on Format Document and is on by default (setting markdown.extension.tableFormatter.enabled). It keeps alignment colons, pads cells and normalizes the delimiter row. It also adds shortcuts such as Ctrl+B for bold, which work inside cells.

Markdown Table Prettifier

A focused extension by Krisztian Daroczi (darkriszty.markdown-table-prettify) that only aligns tables. It is useful when you don't want a full Markdown formatter touching the rest of the file. Like most formatters, it assumes one character is one column, so tables containing CJK text or some emoji can still look ragged in the editor even though they render correctly. Check its README for the current state of wide-character support.

Prettier

Prettier formats Markdown files, and that includes aligning table columns. If your repository already runs Prettier in CI, use it in the editor too so local formatting matches. It may leave a table in a compact, unaligned form when alignment would push lines past the configured printWidth.

Table-editor and coloring extensions

Several Marketplace extensions turn the editor into a lightweight table editor in the style of Emacs org-mode: Tab jumps to the next cell, Shift+Tab goes back, Enter adds a row, and the table re-aligns as you type. Others color each column so you can follow a row across a wide table. Names and maintainers change, so check recent updates and reviews before installing.

Format tables on save

Add this to your user settings or the project's .vscode/settings.json so every save aligns the tables. Turning word wrap off for Markdown keeps wide rows on one line, so the alignment stays visible.

settings.json with Markdown All in OneJSON
{
  "[markdown]": {
    "editor.defaultFormatter": "yzhang.markdown-all-in-one",
    "editor.formatOnSave": true,
    "editor.wordWrap": "off"
  }
}
settings.json with PrettierJSON
{
  "[markdown]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "editor.formatOnSave": true
  }
}

For Markdown Table Prettifier, set editor.defaultFormatter to darkriszty.markdown-table-prettify. Committing .vscode/settings.json gives everyone on the project the same behavior.

Catch broken tables with markdownlint

The markdownlint extension underlines table problems as you type. Three rules cover tables:

markdownlint table rules
RuleNameWhat it catches
MD055table-pipe-styleRows that mix leading/trailing pipes with rows that don’t
MD056table-column-countRows with more or fewer cells than the header
MD058blanks-around-tablesNo blank line before or after a table
.markdownlint.jsonJSON
{
  "MD055": { "style": "leading_and_trailing" },
  "MD056": true,
  "MD058": true
}

MD058 matters even if you only publish on GitHub: kramdown, Python-Markdown and several editors won't start a table without the blank line. For a one-off check outside VS Code, use the Markdown table validator.

Faster table editing: multi-cursor and column selection

Built-in multi-cursor editing handles most bulk table edits without an extension.

Multi-cursor and column selection shortcuts
TaskWindows / LinuxmacOS
Select a column of text (box select)Shift+Alt + dragShift+Option + drag
Box select with the keyboardCtrl+Shift+Alt+Arrow (Windows)Cmd+Shift+Option+Arrow
Add a cursor above / belowCtrl+Alt+Up/Down (Linux: Shift+Alt+Up/Down)Cmd+Option+Up/Down
Add a cursor where you clickAlt+ClickOption+Click
Select the next matchCtrl+DCmd+D
Select all matchesCtrl+Shift+LCmd+Shift+L
Toggle word wrapAlt+ZOption+Z
  • Add a column: box-select the end of every row, type | and the new value, then format.
  • Change alignment: edit the delimiter row only; colons there align the whole column.
  • Escape pipes in bulk: select a literal | inside a cell, press Ctrl+D to pick the next ones you need, and type \|.
  • Regex find and replace (Ctrl+H, then the .* button) handles column-wide edits, such as wrapping every value in the first column in backticks.

Sorting a table

VS Code's built-in Sort Lines Ascending and Sort Lines Descending commands (Command Palette) sort whole lines as text. Select only the data rows, not the header or delimiter, and the table is sorted by its first column. For anything else (another column, numbers, dates, several keys), paste the table into the Markdown table sorter and paste the result back. Text sorting puts 10 before 9; the sorter compares numbers as numbers.

Creating tables: snippets, pasting and generators

A table snippet

Run Snippets: Configure Snippets, choose markdown, and add the snippet below. Quick suggestions are off by default in Markdown files, so type table, press Ctrl+Space and pick the snippet. Tab then moves from cell to cell.

markdown.json (user snippets)JSON
{
  "Markdown table": {
    "prefix": "table",
    "body": [
      "| ${1:Column} | ${2:Column} | ${3:Column} |",
      "| --- | --- | --- |",
      "| ${4} | ${5} | ${6} |",
      "$0"
    ],
    "description": "Three-column Markdown table"
  }
}

From a spreadsheet or CSV

Copying cells from Excel or Google Sheets pastes tab-separated text, not a table. Convert it first with Excel to Markdown or CSV to Markdown, or build the table in the table generator and paste the Markdown in. The full rules for what you paste are in the Markdown table syntax guide.

Tables in Jupyter notebooks in VS Code

Jupyter notebooks opened in VS Code render Markdown cells with the same kind of parser, so pipe tables work in Markdown cells once the cell is run (Shift+Enter). To show a pandas DataFrame as Markdown in a code cell, convert it with to_markdown(), which needs the tabulate package:

DataFrame to a rendered Markdown tablePython
import pandas as pd
from IPython.display import Markdown

df = pd.DataFrame({"model": ["A", "B"], "accuracy": [0.91, 0.87]})
Markdown(df.to_markdown(index=False))  # needs: pip install tabulate

More options, including formatting numbers and writing tables to files, are in the Python Markdown tables guide.

Common problems and fixes

  • “There is no formatter for 'markdown' files installed.” Install one of the formatters above. If several are installed, run Format Document With… and choose Configure Default Formatter.
  • Format on save does nothing. Check that editor.formatOnSave is set inside the [markdown] block or globally, and that the table itself is valid; formatters generally leave broken tables untouched.
  • Columns look ragged after formatting. Turn off word wrap (Alt+Z) and check for CJK characters or emoji, which are wider than one column.
  • It renders in VS Code but not on GitHub or your site. Inline style attributes are stripped by GitHub, and site generators often need a blank line before the table. See Markdown table not rendering.
  • Two formatters disagree. Prettier and Markdown All in One produce slightly different spacing. Pick one per project and set it as the default formatter.

Publishing the table on GitHub? The GitHub README tables guide covers badges, centering and what GitHub strips.

Frequently asked questions

How do I preview a Markdown table in VS Code?

Press Ctrl+Shift+V (Cmd+Shift+V on macOS) to open the preview in a tab, or Ctrl+K V (Cmd+K V) to open it beside the editor. The built-in preview renders GitHub-style pipe tables with no extension needed.

Does VS Code format Markdown tables automatically?

No. VS Code ships no Markdown formatter, so Format Document and format on save do nothing to tables until you install one. Markdown All in One, Markdown Table Prettifier and Prettier all align tables when you run Format Document.

What is the best VS Code extension for Markdown tables?

For most people, Markdown All in One (Yu Zhang): it formats tables on Format Document and adds other Markdown shortcuts. Use Prettier if the project already formats code with it, and Markdown Table Prettifier if you only want table alignment. Add markdownlint to catch broken tables.

Why doesn’t Format Document align my Markdown table?

Either no Markdown formatter is installed, a different formatter is set as the default (run Format Document With… and pick one), or the table isn’t valid, for example the delimiter row has the wrong number of cells. Formatters usually skip tables they can’t parse.

How do I sort a Markdown table in VS Code?

To sort by the first column, select only the data rows and run Sort Lines Ascending from the Command Palette. To sort by another column or numerically, paste the table into the Markdown table sorter and paste the result back.

Why does my formatted table still look misaligned in VS Code?

Usually word wrap is on (toggle it with Alt+Z), or the table contains CJK characters or emoji, which take up more than one column in a monospace font. Formatters that count each character as one column can’t line those up.

Can I edit Markdown tables visually in VS Code?

Not with VS Code alone. Some extensions add Tab-to-next-cell navigation or a grid editor; otherwise build the table in the Markdown table editor and paste the Markdown into your file.

No extension? Format it here

Paste a table, get aligned Markdown back, and paste it into VS Code.

Open the formatter