Since we can only use Markdown and a limited subset of HTML/CSS is it possible to center an image, or any block element for that matter, on the Stack Exchange sites?

  • 3
    If it DID support markdown, yes. It supports a subset of markdown, and not including the arrows to center text (->centeredText<-) Commented Oct 27, 2010 at 22:58
  • @CamiloMartin Markdown does not support centering text. Only Markdown variants do. Try ->center<- here. Commented Apr 3, 2012 at 17:31
  • @DanielBeck Ah, you're right, I think I was fooled by the fact other Markdown implementations support it. Commented Apr 3, 2012 at 21:58
  • 4
    I'm inclined to think that images (inside questions and answers) should better be by default centered - (wow, I can't believe it's almost 4 years since I asked for that...) meta.math.stackexchange.com/questions/2851/…
    – leonbloy
    Commented Jul 14, 2015 at 19:24

4 Answers 4


You could use the <pre></pre> tags to position things manually I guess, but that is the only way I can imagine doing so.

    <img src="..." title="CENTERED!">

TL;DR—Prepend as many &nbsp;s as you need.

After trying all the options at hand, your best bet is to "manually" center the image prepending as many &nbsp;s as you need.

The best example is when you include the graphic using Markdown synthax:

Using <pre>

        ![Dry Paint][1]

Using &nbsp;

                  Dry Paint

  • 4
    What about the mobile site, the data dumps, and whatever other ways post are used? Doesn't feel like a good advise to me...
    – Arjan
    Commented Mar 30, 2012 at 19:18
  • 1
    @Arjan, I've hit this link from my phone (Nexus S) and it looks good and centered. I guess it's my browser that just scales down the web version. How can I see the scenarios you mentioned? Commented Mar 30, 2012 at 20:18
  • 7
    Actually, the mobile CSS theme centers (and fits, if needed) all images, no hack needed at all. (And it "displays" the whitespace above the image.) I was just saying that one cannot center stuff using whitespace; it just adds noise I'd say, and it relies on some specific content width and font width.
    – Arjan
    Commented Mar 30, 2012 at 21:13
  • 2
    Note that each &nbsp; adds 4 pixels to 660 pixel max width.
    – Nae
    Commented Dec 25, 2017 at 3:46

Tables can actually center content

The relatively recent introduction of table formatting provides a way to actually center an image or other content. However, doing so results in additional table formatting around the image (a header row and borders), but it does actually center something, regardless of the width of the user's window. Unfortunately, using formatting like <pre>, &nbsp;, or other formatting/characters to push content a set distance to the right in order to "center" something can't take into account that users can choose the width of the window, making the "centering" using <pre>, &nbsp;, etc. to be substantially off from being centered.

Markdown used:

Using colons as part of the header/content separator, |:----:|, is what results in the cell being centered. With only one cell in the table, the entire content is centered within the post.

|[![Artist concept image of "the newly forming exoplanet PDS 70b"][1]][2]<br><sub>[image credit: NASA, ESA, STScI, Joseph Olmsted (STScI)](https://www.nasa.gov/feature/goddard/2021/hubble-watches-how-a-giant-planet-grows)</sub>|

Random 470×320 px image:

enter image description here

You can add artificial margins directly into the image, if you don't mind, that they will be preserver proportionally, so the graphics itself will be very small on small displays.

Modified image, canvas extended to 1600×320:

enter image description here


(This is suboptimal solution, centering feature wanted.)

  • 7
    That's modifying the image, not aligning the image.
    – Mast
    Commented Nov 8, 2019 at 7:14
  • 1
    True, but It's still a workaround to achieve plan B results OP may not be aware of.
    – Zweifler
    Commented Feb 12, 2023 at 10:46
  • 1
    Maybe, it's a workaround, but it works pretty good for my purposes.
    – kosteklvp
    Commented Apr 10, 2023 at 8:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .