Written and tested by the MD Converter editorial team
How to Center or Right-Align Text in Markdown
Center or right-align Markdown content with HTML, CSS, and table alignment, and understand portability and PDF limitations.
Markdown has no standard text-alignment syntax
Centering and right alignment belong to HTML and CSS rather than core Markdown. In an environment that permits raw HTML, use a paragraph with text-align: center or text-align: right. A reusable class and stylesheet are easier to maintain for repeated use.
Sanitizers may remove style attributes, and some processors do not parse Markdown inside an HTML block. Always test the destination. GFM tables have their own alignment syntax: :--- for left, :---: for center, and ---: for right.
Images can be centered with an HTML wrapper or a block class using automatic inline margins. Add max-width: 100% to avoid overflow. Print CSS can override screen alignment, so inspect the saved PDF.
Use centered text for short covers or captions, not long paragraphs. Use right alignment for dates, numeric columns, and brief metadata. Never simulate alignment with repeated spaces because fonts and page widths vary.
Understand structure versus presentation
Markdown describes what content is: a heading, paragraph, list, table, code block, or image. Left, center, right, and justified alignment are presentation decisions handled by HTML, CSS, or the export tool. This separation is why a portable Markdown file has no universal center syntax.
Repeated spaces and tabs are not a substitute. HTML collapses ordinary whitespace, proportional fonts give characters different widths, and PDF page dimensions differ from an editor window. A line aligned manually on one computer will move on another. Leading whitespace causes similar problems inside lists, so see How to Fix Markdown List Indentation and Numbering when bullets or numbering drift.
Align table columns with GFM syntax
Pipe tables provide portable column alignment in GFM:
| Item | Status | Amount |
|:---|:---:|---:|
| Design | Complete | 12,500 |
The left colon aligns the first column left, colons on both sides center the second, and a right colon aligns numeric values right. This syntax applies to table cells only. It does not center headings or paragraphs.
Right-align numbers when readers compare place values, but include units in the header and keep decimals consistent. Center short statuses sparingly; long text is easier to read left-aligned.
Align images in the PDF preview
Select an embedded image and use its left, center, or right alignment control. Resize from a corner to preserve aspect ratio. Center is a safe default for diagrams and screenshots; left alignment can integrate a small image into document flow, while right alignment is best reserved for compact marks or supporting visuals.
Verify that alignment does not separate the image from its heading or caption. A page break before the image may be cleaner than forcing it into a narrow remaining area.
Use raw HTML only when the destination allows it
An HTML paragraph with style="text-align:center" may work in permissive renderers, but sanitizers can remove the style attribute. Markdown inside an HTML block may also remain unparsed. If the document must work across Git hosting, a CMS, HTML export, and PDF, minimize raw HTML and test each destination.
When you control a stylesheet, a reusable class is easier to maintain than repeated inline style. Keep print rules aligned with screen rules so text does not unexpectedly return to left alignment in PDF.
Choose alignment for readability
Long body paragraphs should normally remain left-aligned. Centered prose creates inconsistent line starts and slows reading. Justified text can introduce large gaps in narrow columns, especially with long English words or mixed Japanese and Latin text. Right alignment suits dates, signatures, short metadata, and numeric columns rather than general explanation.
Alignment troubleshooting checklist
- Confirm the target supports raw HTML before using it.
- Do not align with spaces or tabs.
- Use GFM colon syntax only for table columns.
- Keep long prose left-aligned.
- Resize and align images through preview controls.
- Check captions and page breaks after moving an image.
- Inspect the saved PDF at 100% zoom.
- Test narrow screens if HTML is also distributed.
Frequently asked questions
Can I center a Markdown heading without HTML?
Not with portable core Markdown. Use a cover template or a controlled CSS class when centered presentation is required.
Why does alignment disappear after publishing?
The destination may sanitize inline styles or apply a stronger stylesheet rule. Inspect the generated HTML and the final print CSS rather than adding more spaces.
See Markdown table layout troubleshooting when alignment is correct but columns still overflow.