You probably want to wrap your image in a <div>
set to display flex (I wouldn't set <body>
to flex).
Flex box will let you place the image in the middle of your <div>
very quickly! If you want your container it to take the screen full height simply set your <div>
wrapper to 100vh.
Also notice that you shouldn't put your sizes after the forward slash.
<div class="container">
<img src="img1" onmouseover="this.src='img2'" onmouseout="this.src='img1'"/>
</div>
.container {
display: flex;
justify-content: center;
align-items:center;
height: 100vh;
}
img {
height: 200px;
}
<div class="container">
<img src="https://i.stack.imgur.com/dusjG.png"
onmouseover="this.src='https://i.stack.imgur.com/0RSNI.jpg'"
onmouseout="this.src='https://i.stack.imgur.com/dusjG.png'"/>
</div>
See also my codepen.
I hope this helps!