MarkdownPaper Open reader

Guide

How to center text and images in Markdown

Markdown has no way to center text. Wrap the text in an HTML paragraph or div with align="center" instead. It is old HTML, but it is the way that works on GitHub, where newer CSS styles are removed.

You write

<p align="center">This line is centered.</p>

You see

This line is centered.

On this page

Center a heading

Put align="center" on a heading tag.

You write

<h2 align="center">A centered heading</h2>

You see

A centered heading

Center an image

Wrap the image in a centered paragraph. This is how many GitHub READMEs put a logo at the top.

You write

<p align="center">
  <img src="/icon-192.png" alt="MarkdownPaper logo" width="96">
</p>

You see

MarkdownPaper logo

Center several things at once

A div can hold a heading, text and images together. Leave empty lines inside it to keep using Markdown.

You write

<div align="center">

**Project name**

A short line about the project.

</div>

You see

Project name

A short line about the project.

Center a table column

Tables use colons for alignment. A colon on both sides of the dashes centers the column.

You write

| Name | Score |
| ---- | :---: |
| Ana  | 18    |
| Ben  | 21    |

You see

NameScore
Ana18
Ben21

Why not CSS?

style="text-align: center" is the modern way in HTML, but GitHub and many Markdown apps remove style attributes. align is kept, so it is the one to use in Markdown.

Where centering does not work

  • Apps that do not allow HTML show the tags as text.
  • Some apps allow HTML but ignore align.
  • A whole document cannot be centered from inside it. The app reading the file decides the page layout.

Questions

How do I center text in a GitHub README?

Use <p align="center">Your text</p>. GitHub keeps the align attribute.

How do I center an image in Markdown?

Wrap it in <p align="center"> and use an <img> tag inside, as in the example above.

Why is my centered text not centered?

The app may not allow HTML, or it may ignore align. Check that the tag is on its own lines, with an empty line before and after it.

Next