How to move images in HTML?

Images can be moved using CSS positioning properties. There are various methods for positioning images, including absolute positioning, relative positioning, and floating. Here are a few common methods:

1. Using Absolute Positioning:

<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
width: 300px;
height: 200px;
border: 1px solid black;
}
img {
position: absolute;
top: 50px;
left: 50px;
}
</style>
</head>
<body>

<div class="container">
<img src="example.jpg" alt="Example Image">
</div>

</body>
</html>

2. Using Relative Positioning:

<!DOCTYPE html>
<html>
<head>
<style>
img {
position: relative;
left: 50px;
top: 20px;
}
</style>
</head>
<body>

<img src="example.jpg" alt="Example Image">

</body>
</html>

3. Using Floats:

<!DOCTYPE html>
<html>
<head>
<style>
img {
float: right;
margin-left: 10px;
}
</style>
</head>
<body>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vehicula nulla ut justo pretium, id faucibus
risus lacinia. <img src="example.jpg" alt="Example Image"> Donec tincidunt felis ut urna dictum, vel aliquam
mauris pellentesque. Vestibulum consequat quam non arcu vehicula, sit amet congue nunc bibendum. </p>

</body>
</html>
Adjust the CSS properties such as top, left, right, or margin as needed to achieve the desired positioning.

Go from files to website in seconds.

Start a free trial for 7 days — no credit card required

Get Started for Free