How to centre an image in CSS

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:

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

Thanks to Bert Bos for this tip!

About Jay Versluis

Jay is a medical miracle known as a Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

2 thoughts on “How to centre an image in CSS

Add your voice!