How to centre an image in CSS

- by

CSS-LogoCentering text in CSS is relatively easy. All you do is add the “text-aling: center” property.

If you’ve ever tried this with anything that isn’t text you’ll have noticed that this approach doesn’t work.

Instead, display your class as a block, then set the margins to auto. You also need to specify a width so the rest flows around this fixed parameter:

.yourclass {
	width: 400px;

This approach works with everything that is not text such as images.

Thanks to Bert Bos for this tip!

If you enjoy my content, please consider supporting me on Ko-fi. In return you can browse this whole site without any pesky ads! More details here.

2 thoughts on “How to centre an image in CSS”

Leave a Comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.