How to Center Text in Markdown
Markdown has no syntax to center text. Here are the HTML alignment tags that work, which ones GitHub keeps and which it strips, and how to center images, headings, and README badges.
Short answer: You can't center text in markdown itself — there is no syntax for it. The workaround is HTML: wrap the content in <p align="center"> or <div align="center">. GitHub allows the align attribute, so that pair is the reliable choice on GitHub. It strips style attributes, so inline CSS won't work there, and it doesn't allow the old <center> tag at all.
Centering is the second-most-searched thing markdown can't do, after underline, and for the same reason: markdown describes structure, and alignment is presentation. The format leaves presentation to CSS. That's a defensible design, right up until you want a centered logo at the top of a README.
Why There's No Centering Syntax
Markdown's entire vocabulary maps to semantic HTML elements — headings, paragraphs, lists, emphasis, quotes, code. Nothing in that vocabulary describes where content sits on a page, because in HTML that's the stylesheet's job.
The practical upshot is that the same markdown file renders differently everywhere, by design. Your document doesn't decide it's centered; the renderer decides. Centering requires stepping outside markdown and into whatever presentation layer the platform allows — which is why the answer is entirely a question of what your specific renderer permits.
Option 1: align on a Paragraph or Div (Best for GitHub)
<p align="center">This text is centered.</p>
Or, for a block containing several things:
<div align="center">
<h1>Project Name</h1>
<p>A short tagline for the project.</p>
</div>
The align attribute is a holdover from HTML 4 — technically obsolete in HTML5, still honored by every browser, and, crucially, on GitHub's allowlist of permitted attributes. It works on p, div, h1 through h6, img, table, td, and th.
This is what essentially every centered README on GitHub uses, and it's the option to reach for unless you control the CSS yourself.
Option 2: <center> (Deprecated, and Stripped by GitHub)
<center>This text is centered.</center>
The <center> element was deprecated in HTML 4, in 1997. Browsers still render it, so it works in local previews and in renderers that pass raw HTML through untouched.
It does not work on GitHub. center isn't on GitHub's element allowlist, so the sanitizer removes the tag and leaves the text left-aligned. This is a common source of "it looked right in VS Code" confusion — your editor is more permissive than GitHub is.
There's no reason to use it. <p align="center"> is the same number of keystrokes and survives more places.
Option 3: A CSS Style Attribute
<p style="text-align: center">This text is centered.</p>
If you own the rendering pipeline — your own static site, an internal docs system, a PDF export — this is the correct modern approach, and it gives you everything CSS gives you: centering, max-width, margins, responsive behavior.
GitHub strips style attributes. The paragraph survives, the centering doesn't. The same is true of most platforms that render markdown submitted by users, for straightforward security reasons.
If you're building a site, a CSS class beats an inline style:
<div class="centered">
Content here.
</div>
...paired with a rule in your stylesheet. That keeps presentation out of your content files, which is the whole point of markdown.
The Gotcha: Markdown Inside HTML Doesn't Parse
This one costs people more time than the alignment question itself:
<div align="center">
**This will not be bold.**
[This will not be a link](https://example.com)
</div>
On GitHub and in any CommonMark-compliant renderer, the content of an HTML block is passed through as raw HTML. Markdown syntax inside it is not processed, so you get literal asterisks and literal brackets.
Two ways around it. Write the inner content as HTML:
<div align="center">
<strong>This will be bold.</strong>
<a href="https://example.com">This will be a link</a>
</div>
Or leave a blank line after the opening tag, which ends the HTML block and lets the parser return to markdown mode:
<div align="center">
**This will be bold.**
</div>
The blank-line version works on GitHub and most CommonMark parsers. It's less predictable across older or custom renderers, so for a README that has to be right, the all-HTML version is safer.
Centering Images
Images are the most common thing people want centered, and the fix is the same wrapper:
<p align="center">
<img src="assets/logo.png" alt="Project logo" width="200">
</p>
The align attribute also works directly on the image itself, but there it means something different — <img align="left"> floats the image and wraps text around it, the way it did in 1998. For centering, wrap it.
Note the width attribute rather than a CSS width. Both width and height are allowed on GitHub; style is not. So sizing an image in a README means using the HTML attributes, not CSS.
Centering README Badges
This is the single most common real use case: a row of build-status, license, and version badges centered under the project title.
<h1 align="center">Project Name</h1>
<p align="center">
<a href="https://example.com/build"><img src="https://example.com/badge.svg" alt="Build status"></a>
<a href="LICENSE"><img src="https://example.com/license.svg" alt="License"></a>
</p>
<p align="center">
One-sentence description of what this project does.
</p>
Because everything inside those blocks is HTML, the markdown-inside-HTML problem never arises — badges are <img> tags wrapped in <a> tags, so writing them as HTML is natural rather than a workaround.
A word of restraint: a centered header block reads well when it's a logo, a title, and a line of badges. Centering body paragraphs makes them harder to read, because the eye loses the left edge it uses to find the start of each line. Center the header; left-align the prose. There's more on README structure in how to write a README.md.
Centering Tables
Two different questions get confused here.
Centering the content of table cells is native markdown, using colons in the separator row:
| Left | Center | Right |
|:-----|:------:|------:|
| a | b | c |
That works everywhere GFM tables work, with no HTML involved. See the markdown tables syntax guide for the full alignment rules.
Centering the table itself on the page is a different matter. A table is a block element that sizes to its content, and centering a block requires margin: 0 auto in CSS — which GitHub strips. Wrapping a markdown table in <div align="center"> also runs into the markdown-inside-HTML problem: the table won't parse.
The honest answer for GitHub is that you can't reliably center a table. You can write the whole table as HTML with <table align="center">, which does work, at the cost of a much bulkier and harder-to-edit source file. On your own site, one CSS rule solves it properly.
Where Centering Works
| Platform | align attribute | <center> | style attribute |
|---|---|---|---|
| GitHub | Works | Stripped | Stripped |
| GitLab | Works | Works | Stripped |
| Obsidian | Works | Works | Works |
| VS Code preview | Works | Works | Works |
| Static site generators | Depends on the raw-HTML setting | Same | Same |
| MDX | Works (JSX) | Deprecated, avoid | Needs an object, not a string |
| Not allowed | Not allowed | Not allowed | |
| Discord | Not allowed | Not allowed | Not allowed |
| Slack | Not allowed | Not allowed | Not allowed |
| Package registry READMEs | Verify — sanitizers vary | Usually stripped | Usually stripped |
That last row matters if you publish a package. A README rendered on a registry page goes through that registry's own sanitizer, which is often stricter than GitHub's. Centering that looks perfect on GitHub can arrive left-aligned on the package page. Check the rendered result rather than assuming.
MDX deserves a note too: there, HTML is JSX, so tags must be closed (<br />, not <br>) and style takes a JavaScript object rather than a CSS string. The markdown extensions guide covers those differences.
Previewing Before You Push
Every option here fails silently. A stripped tag doesn't produce an error — the content just renders unstyled, and you find out after the commit lands.
OpenMark renders raw HTML inline in Document view, so a centered header block or a wrapped image shows up as it would in a permissive renderer, with the untouched source a keystroke away in Markdown view. That confirms your HTML is well-formed. Whether a given platform keeps it is the table above's job — which is the real lesson: centering in markdown is never a syntax question, it's a question about the renderer.
Related reading on the same theme: how to underline text in markdown, which has the identical "no native syntax, here's the HTML, here's what gets stripped" shape, and markdown line breaks for the other formatting behavior that surprises people.
Download OpenMark → — $9.99, one-time, native macOS. Write your README with centered headers and badges, and see exactly how the HTML renders before you push.