I would like to center the image at the top of the topic starter which doubles as my blog for people to comment on. Or better yet, make the photo expand to the width of the box. What would be the code for that? Thanks. ![]()
AI-generated summary
In this Support topic, users seek ways to center uploaded images in Discourse. McBlu initiates the discussion, wanting to center or expand an image in a blog-style post. gerhard provides a simple HTML solution using <div align="center">, which Johani later enhances with CSS to automatically center all non-emoji images, warning that this may break horizontal stacking. icaria36 suggests centering images by default, while dnsmichi prefers left-aligned images for readability, noting Markdown lacks native alignment controls. jomaxro clarifies that a blank line between HTML and Markdown is essential to avoid centering text instead of images — a tip papyrophilia finds invaluable. D8vid mentions the BBCode plugin as an alternative. Gustavo_Papasergio struggles with HTML syntax, prompting codinghorror to clarify that HTML must be typed manually — no “code” button exists. jomaxro helps troubleshoot alignment issues, reinforcing the blank-line rule. The thread concludes with users successfully applying the HTML method, appreciating the clear guidance and caveats.
Would it make sense to have uploaded images centered by default in Discourse? Posts look nicer this way, and probably lazy users would prefer this setting but we are… just lazy to add the HTML manually.
Users with other needs could still add the HTML.
I prefer images not being centered by default, they should adjust the way the reader prefers to read text (left to right, or vice versa). But that’s really always a personal flavor.
Markdown itself doesn’t have such capabilities, you’ll always need to use HTML for such things. Similar thing for showing a fixed scaled image size.
It might be a nice addition to add alignment icons into the editor, similar to what Wordpress allows, and just do the HTML magic there.
If the images are not wide enough they will stack horizontally like so:
If you’re fine with losing this, then you can automatically center all images in posts using CSS.
.lightbox-wrapper {
display: block;
text-align: center;
}
p>img:not(.emoji){
display: block;
margin: 0 auto;
}
The results would look like this:
I am definitely using that. Thanks III !
As discussed here:
The code needs to be modified to exclude emojis.
I edited the code in the previous post to reflect that change.
The rest of the post still applies.
It’s now a wiki, feel free to update it.
I have an image I uploaded to the site that I’d like to reuse and center but it’s not working for me.
This works:

How would I center this image using the syntax shared above?
Thanks!
If you’re willing to use the BBCode plugin (and understand its risks & benefits), it allows for anyone to center images using only the editor.
bbcode プラグインは不要で、HTML を使うだけで大丈夫です。
<div align="center">

</div>
HTML と Markdown を混在させる場合、空行が必要である点にご注意ください。空行がないと、画像ではなく中央揃えのテキストになってしまいます。
なぜこれが私の環境で機能しないのでしょうか。HTML を記述するためのエディタの「コード」ボタンはどこにありますか?
ありがとうございます。
キーボードのキーを使って入力します。「コード」ボタンはありません。
はい、試しましたが、動きません。もう一度試してみます。
ありがとうございます。
「動作しない」とおっしゃる場合、具体的にどのような結果が表示されていますか?画像の代わりに中央揃えのテキストが表示されている可能性はありませんか?
もしそうであれば、上記の例のように空白行を含めるようにしてください。その点について補足説明を追加しています。
これをありがとうございます!正しいコードは分かっていたのですが、正しい結果が得られませんでした。@jomaxro さんへのリマインダーとご説明に感謝します!



