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.

You type
<p align="center">
  Centered heading line
</p>
You get

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.

You type
<p align="center">
  <img src="logo.svg" alt="Logo" width="80">
</p>
You get

Logo

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 ![alt](img) 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.

You type
| Left | Center | Right |
| :--- | :----: | ----: |
| a    | b      | c     |
You get
LeftCenterRight
abc

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

TargetGitHubWebsites / generators
Text<p align="center">Either align or style
Image<p align="center"><img>Either
Table columnsColon syntaxColon syntax
Whole tableNot reliably<div align="center">
Right-alignalign="right"Either
Before you center a heading: centered body text is hard to read for anything longer than a line, and screen readers ignore alignment entirely, so it carries no meaning, only looks. A centered logo and title block at the top of a README is the one place it reliably earns its keep.

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.

Related syntax

· All markdown guides

Less syntax. More writing.

Download maxdown

Free · no account · macOS, Windows & Linux