Markdown cheatsheet · Center & align
Centering and aligning in markdown
Markdown can't center anything on its own, except table columns. Everything else means an HTML wrapper, and the attribute that survives GitHub is not the one you'd guess.
The short answer
Markdown has no syntax for aligning or centering anything. The one exception is table columns, which have their own colon syntax. For everything else, text, images, headings, you reach for HTML, and how much of it survives depends on the renderer.
Centering text
Where HTML is allowed, wrap the text in a div or p with an alignment. The old align attribute is the one that survives the most renderers, GitHub included.
<p align="center"> Centered heading line </p>
Centered heading line
The CSS form <div style="text-align:center"> is cleaner and works on websites, but GitHub strips style, so on GitHub the deprecated align attribute is what actually works. This is the single most common reason "my centered text isn't centering" on GitHub.
Centering an image
Same idea: wrap the image. Since a markdown image is just an inline element, aligning it means aligning its container.
<p align="center"> <img src="logo.svg" alt="Logo" width="80"> </p>
If you're also resizing, alignment and size are separate attributes on the same tags; see image size. Note you can't use the plain  markdown syntax and center it; the moment you need alignment, you're in HTML.
Centering inside a table
This one markdown does have syntax for. Colons in the divider row set each column's alignment: :--- left, :---: center, ---: right.
| Left | Center | Right | | :--- | :----: | ----: | | a | b | c |
| Left | Center | Right |
|---|---|---|
| a | b | c |
That aligns the contents of columns. Centering the whole table on the page is a different problem, and needs the HTML wrapper again.
What works where
| Target | GitHub | Websites / generators |
|---|---|---|
| Text | <p align="center"> | Either align or style |
| Image | <p align="center"><img> | Either |
| Table columns | Colon syntax | Colon syntax |
| Whole table | Not reliably | <div align="center"> |
| Right-align | align="right" | Either |
Common questions
Why won't my text-align:center work on GitHub?
GitHub removes the style attribute. Use align="center" on the element instead.
Can I center text without HTML at all?
No, except table columns. Core markdown has no alignment syntax, by design.
How do I center a heading, keeping it a real heading?
Put the # inside the wrapper on some renderers, or write the heading as HTML: <h2 align="center">Title</h2>. Be aware an HTML heading may not appear in an auto-generated table of contents.
Is right-align any different?
No, everything above works with align="right" or text-align:right.