KC Here KC Here - 2 months ago 8x
CSS Question

When my div is not getting horizontally centered?

Why is the image not centered here?

#image {
margin: 0 auto;

<div id="image">
<img src="https://placekitten.com/200/300">

But it works perfect with a

My fiddle


Or you could just use flexbox

#image {
  height: 90vh;
  width: 90vw;
  display: flex;
  justify-content: center;
  align-items: center;

You don't need the 90vh or 90vw but you do need to give the height and width some value. Whether it's in px or % is up to you.