Center Markdown Text: Text, Headings, and Tables (2026)

September 11, 2026 · 8 min read

Center Markdown Text: How to Center Text, Headings, and Tables

To center markdown text, wrap it in an HTML tag with an alignment attribute: <p align="center">Your text</p>. Markdown has no alignment syntax of its own, so every centering method is really inline HTML. This post shows the three snippets that work, which platforms keep them, and how to center headings, whole tables, and single table columns.

Three Ways to Center Text in Markdown

Markdown describes structure, not layout. CommonMark 0.31.2 defines headings, lists, emphasis, and links, but nothing about where text sits on the page. Alignment is a presentation decision, so every markdown center text method is really the HTML escape hatch that CommonMark passes through untouched. Our Markdown vs HTML comparison covers where the two languages divide the work.

Here are the three snippets, from most compatible to least. Each one is plain HTML dropped into your .md file.

<p align="center">Centered with the align attribute on a paragraph.</p>

<div align="center">Centered with the align attribute on a div.</div>

<p style="text-align: center">Centered with an inline style.</p>

All three render as a centered line in a browser. The first two use the align attribute, which HTML 5 marks as obsolete but every browser still honours. The third uses CSS, which is the modern approach and the one MDN recommends.

We prefer <p align="center"> for anything that ships to GitHub, and the style version everywhere else. The reason is in the compatibility table below: GitHub strips style but keeps align.

There is also the <center> tag. It works in browsers, but MDN lists <center> as deprecated since HTML 4, and GitHub's sanitizer removes the tag entirely. Skip it.

Keep Bold and Links Inside the Centered Block

This is the mistake behind most "centering broke my formatting" forum threads. When you open a block-level HTML tag like <div> or <p>, CommonMark treats everything up to the next blank line as raw HTML. Markdown inside it is not parsed, so **bold** prints the asterisks.

The fix is simple. Put a blank line after the opening tag and another before the closing tag.

<div align="center">

**This is bold** and [this is a link](/editor).

</div>

With the blank lines, the renderer closes the HTML block, parses the middle as normal Markdown, then picks up the closing tag as a second HTML block. The CommonMark HTML blocks section shows this exact case in examples 188 and 189.

One limitation: this trick only works with <div>, not <p>. A paragraph tag can't legally contain the <p> that the parsed Markdown produces, so browsers close it early and the centering stops at the first line.

Try Centering in the Editor

Paste the snippets below into the editor and watch the preview. Change align to style and see that both work here, then read the platform table before copying anything into a README.

Centering demo

This paragraph is centered with the align attribute.

Bold text and a link stay formatted because of the blank lines.

This one uses an inline style instead.

Left-aligned text for comparison.

40 words311 characters13 lines
Markdown

Where Does Center Markdown Text Actually Work?

The snippets are identical everywhere. What differs is the sanitizer between your file and the browser. This is what we found in our testing, cross-checked against each platform's documentation.

Platformalign="center"style="text-align:center"<center>Notes
GitHub (README, issues, gists)KeptStrippedTag removedGitHub's sanitizer allowlists align and width but drops style and class
GitLabKeptStrippedTag removedSame sanitizer family as GitHub
VS Code previewKeptKeptKeptNo sanitizing of align or style
Obsidian (Reading view)KeptKeptKeptObsidian's help page says it sanitizes scripts but keeps style
Hugo (Goldmark)Dropped by defaultDropped by defaultDropped by defaultNeeds markup.goldmark.renderer.unsafe = true; Hugo defaults it to false
Jekyll (kramdown)KeptKeptKeptRaw HTML passes through
Slack, Discord, RedditNoNoNoChat apps don't render HTML at all

Two rows deserve a closer look. GitHub's behaviour comes from the html-pipeline sanitization filter it uses: the attribute allowlist includes align but not style, and center isn't in the element list. That's why <p align="center"> is the only reliable way to center on GitHub.

Hugo is the opposite problem. Goldmark drops raw HTML entirely unless you flip the unsafe flag in hugo.toml, so nothing centers until you change the config.

How Do I Center Text in a Markdown Table?

This PAA question hides two different questions, so here are both answers.

Centering the content of one column is native Markdown. GitHub Flavored Markdown's table extension reads colons in the delimiter row: :--- for left, ---: for right, and :---: for center.

| Left | Center | Right |
|:-----|:------:|------:|
| a    |   b    |     c |

Every cell in the middle column renders centered, headers included. This works on GitHub, GitLab, Obsidian, VS Code, and any renderer with GFM tables. Our Markdown table guide covers the rest of the table syntax.

Centering the whole table on the page is not native. Wrap the table in a div, with the blank lines from earlier so the table still parses.

<div align="center">

| Name | Score |
|------|------:|
| Ana  |    98 |

</div>

On GitHub the table sits in the middle of the README. In our testing the column alignment colons keep working inside the wrapper.

Center Headings and Images in Markdown

A heading is just a block, so the same wrapper works. Write the heading in Markdown between the blank lines rather than as an HTML <h1>. That way it keeps its anchor link on GitHub.

<div align="center">

# Project Name

A one-line tagline under the centered title.

</div>

To center a Markdown image, the pattern is <p align="center"><img src="logo.png" width="200" /></p>. Markdown center images on GitHub need that align attribute on the wrapper, since the image tag itself has no centering option. Our Markdown image guide has the full center image markdown section, including sizing and links.

Common Center Markdown Text Mistakes

Forgetting the blank lines. <div align="center">**Bold**</div> on one line prints literal asterisks on GitHub and in every CommonMark renderer. Add a blank line after the opening tag and before the closing tag.

Using style on GitHub. <p style="text-align:center"> looks right in VS Code, then renders left-aligned on GitHub because the sanitizer removes the attribute. Switch to align="center" for anything that lives in a repository.

Centering with spaces. Padding a line with leading spaces doesn't center it. Four or more spaces turn the line into a code block, and fewer spaces are ignored. Markdown center alignment always needs an HTML tag.

Center Markdown Text FAQ

Markdown can't align anything on its own, but one HTML wrapper is all it takes to center markdown text, headings, and whole tables. Reach for <p align="center"> when the file lives on GitHub, style="text-align:center" when you control the renderer, and colons in the delimiter row for table columns. Test each snippet live in the editor before you commit it, and keep the blank-line rule in mind whenever bold text or links go missing.