How to Center Text in Markdown
Markdown has no centering syntax, so you drop in a little HTML. This guide covers the one method that survives GitHub's sanitizer, the CSS method for renderers you control, and how to center headings, images, badges, and tables.
Short answer
Wrap the content in <div align="center">. It works on GitHub, GitLab, VS Code, Obsidian, and every static site generator. Inline CSS like style="text-align: center" is stripped by GitHub, and <center> is removed entirely.
Method 1: The align Attribute
The align attribute is deprecated HTML, but it is the most portable way to center content in Markdown. GitHub allows it on div, p, h1–h6, img, td, and th.
<div align="center">This text is centered.</div>
<p align="center">So is this paragraph.</p>So is this paragraph.
<h1 align="center">Project Name</h1>
<p align="center">A one-line description that sits under the title.</p>style, class, and id. The align attribute stayed on the allowlist, which makes it the only alignment tool that works there.Keeping Markdown Alive Inside the Block
Markdown is not parsed inside a raw HTML block. Add a blank line after the opening tag and before the closing tag: the blank line ends the HTML block, so headings, bold, links, and tables in between are parsed normally. This is the pattern behind almost every centered README header.
<div align="center">
## Project Name
**Everything in this block is still Markdown.**
</div>Project Name
Everything in this block is still Markdown.
**asterisks** and a line starting with a stray # instead of a heading.Method 2: Inline CSS
If you control the renderer — a static site generator, a docs platform, a Jupyter notebook, a local preview — inline CSS is the modern, non-deprecated option. It is also the only way to combine alignment with other styling in one tag.
<p style="text-align: center;">Centered with inline CSS.</p>
<div style="text-align: center;">
This block is centered too.
</div>Centered with inline CSS.
This block is centered too.
Method 3: The <center> Tag (Avoid)
The <center> tag is the method most tutorials still recommend. It is obsolete in the HTML standard, and GitHub removes it because it is not on the allowlist of permitted tags. Browsers do still render it in plain HTML, so it works in a local preview and then fails where it matters.
<center>This text is centered.</center><div align="center">. Same result, no obsolete markup, and it survives sanitization.Centering Images and Badge Rows
Markdown image syntax has nowhere to put an alignment hint, so wrap the image in an aligned paragraph. The same wrapper centers a row of shields.io badges, which is why nearly every polished README opens with one.
<p align="center">
<img src="logo.png" alt="Project logo" width="240" />
</p><p align="center">
<img src="https://img.shields.io/badge/build-passing-brightgreen" alt="Build status" />
<img src="https://img.shields.io/badge/license-MIT-blue" alt="License" />
<img src="https://img.shields.io/badge/version-1.0.0-orange" alt="Version" />
</p> to an <img> tag is the most common place alt text gets dropped. See the image syntax guide for sizing and alt-text rules.Centering a Table vs Centering a Column
These are two different things and they get mixed up constantly. Colons in the separator row set the alignment of the text inside a column. To move the whole table to the middle of the page, wrap it in an aligned block with blank lines around the Markdown.
| Left | Center | Right |
| :--- | :----: | ----: |
| a | b | c |
| dd | ee | ff || Left | Center | Right |
|---|---|---|
| a | b | c |
| dd | ee | ff |
<div align="center">
| Plan | Price | Seats |
| ----- | ----- | ----- |
| Free | $0 | 1 |
| Team | $12 | 10 |
</div>| Plan | Price | Seats |
|---|---|---|
| Free | $0 | 1 |
| Team | $12 | 10 |
Right and Left Alignment
Everything above works with align="right" and align="left" too. Right alignment is most useful for attribution lines, signatures, and last-updated notes.
<div align="right">Right-aligned block.</div>
<p align="right"><em>- Attribution line</em></p>- Attribution line
Common Mistakes
Alignment problems are almost always a sanitizer stripping your markup or a raw HTML block swallowing your Markdown.
Broken
<div style="text-align: center;">
Centered on my machine, left-aligned on GitHub.
</div>Fixed
<div align="center">
Centered everywhere, including GitHub.
</div>Broken
<center>Centered text</center>Fixed
<div align="center">Centered text</div>Broken
<div align="center">
**This stays literal asterisks**
</div>Fixed
<div align="center">
**This renders as bold**
</div>Broken
| Left | Center |
| :--- | :----: |
| a | b |Fixed
<div align="center">
| Left | Center |
| :--- | :----: |
| a | b |
</div>Quick Reference
| Syntax | Result | Works on GitHub? |
|---|---|---|
| <div align="center"> | Centered block | Yes |
| <p align="center"> | Centered paragraph | Yes |
| <h1 align="center"> | Centered heading | Yes |
| <img align="center" ...> | Centered image | Yes |
| <div align="right"> | Right-aligned block | Yes |
| <p style="text-align: center"> | Centered paragraph | No - style stripped |
| <center> | Centered block | No - tag removed |
| | :---: | | Centered column text | Yes (column only) |
Platform Support
Alignment depends entirely on how much HTML the renderer lets through. Document platforms allow some. Chat apps allow none.
| Platform | Supported? | Notes |
|---|---|---|
| GitHub | Partial | align="center" works on div, p, h1-h6, img, td, and th. All style attributes and the <center> tag are stripped. |
| GitLab | Partial | Same picture as GitHub: the align attribute is allowed, inline CSS is sanitized away. |
| VS Code preview | Yes | Renders both the align attribute and inline CSS in the built-in preview. |
| Obsidian | Yes | Reading view honors align and inline CSS. Live Preview can lag behind on raw HTML blocks. |
| Jupyter / R Markdown | Yes | Inline CSS and the align attribute both render in notebook and knitted HTML output. |
| Docusaurus / VitePress / Astro | Yes | MDX and remark-based pipelines pass HTML through, so both methods work. |
| Notion | No | Pasted HTML is converted to Notion blocks. Alignment is set from the block menu, not Markdown. |
| Discord | No | No HTML and no alignment syntax. Messages are always left-aligned. |
| Slack | No | mrkdwn has no HTML and no alignment. Even Block Kit has no text-align option. |
| No | HTML is stripped in both old and new Reddit. There is no centering workaround. | |
| CommonMark | Partial | The spec defines no alignment syntax. Raw HTML passes through if the renderer allows it. |
Frequently Asked Questions
How do you center text in Markdown?
Markdown itself has no centering syntax, so you embed a small piece of HTML. Wrap the content in <div align="center"> or <p align="center"> for the widest compatibility, including GitHub and GitLab. In renderers that allow inline CSS, <p style="text-align: center;"> also works.
Why does text-align: center not work on GitHub?
GitHub sanitizes the HTML in Markdown files and aggressively removes anything that could affect the page, including inline style attributes, class names, and IDs. Your markup renders, but the style attribute is gone, so the text stays left-aligned. Use the align attribute instead.
Does the <center> tag work in Markdown?
It depends on the renderer. <center> is obsolete in HTML, and GitHub does not include it in its allowlist of permitted tags, so it is removed entirely. Local previews and some static site generators still render it. Use <div align="center"> instead so the result is the same everywhere.
How do I center an image in a README?
Wrap the image in an aligned paragraph: <p align="center"><img src="logo.png" alt="Logo" width="240" /></p>. You can also put align="center" directly on the img tag, but wrapping is more predictable when the image sits next to other content.
How do I center a heading in Markdown?
Replace the # syntax with the HTML equivalent and add the attribute: <h1 align="center">Project Name</h1>. On GitHub this still gets an anchor link, so table-of-contents links to the heading keep working.
How do I center a table in Markdown?
Wrap the Markdown table in <div align="center"> with a blank line before and after the table so the pipe syntax is still parsed as Markdown. The colons in a table separator row (:---: ) only center the text inside a column; they do not move the table on the page.
Why is my bold text showing literal asterisks inside a centered div?
Markdown is not parsed inside a raw HTML block. Put a blank line after the opening tag and another before the closing tag. The blank line ends the HTML block, so everything between the tags is parsed as Markdown again.
How do I right-align text in Markdown?
Use the same approach with a different value: <div align="right"> or <p align="right">. This is handy for attribution lines and signature blocks. The left value works too, though left is already the default.
Can I center text in Discord, Slack, or Reddit?
No. All three strip HTML and none of them expose a text-alignment option, so messages are always left-aligned. Padding a line with spaces or non-breaking spaces is unreliable because it depends on the reader's window width and font.
Related Markdown Guides
Centering is one of a handful of things Markdown leaves to HTML. Here are the others: