To make text wrap around an image in HTML, place the <img> element in the content and use CSS float: left or float: right. The float moves the image to one side of its container while allowing surrounding text to flow beside it. Add margin to create space between the image and the paragraph.
Basic Example
<img src="image.jpg" alt="A descriptive image" class="wrap-left">
<p>
This paragraph wraps around the image. Because the image is floated left,
the text occupies the available space on the right side until it reaches
the bottom of the image.
</p>
.wrap-left {
float: left;
width: 240px;
margin: 0 20px 10px 0;
}
float: left places the image on the left side of its containing block. The text flows around its right side. The margin creates 20 pixels of horizontal space and 10 pixels of space below the image.
Wrap Text Around an Image on the Right
To put the image on the right and make text flow around its left side, use float: right:
<img src="image.jpg" alt="A descriptive image" class="wrap-right">
<p>
This paragraph wraps around the right-aligned image and continues beside it
until the text passes the image's bottom edge.
</p>
.wrap-right {
float: right;
width: 240px;
margin: 0 0 10px 20px;
}
The difference is the float direction. With float: right, the image moves to the right and the text uses the remaining space on the left.
Why float Makes Text Wrap
A normal image participates in inline content, but a larger image does not automatically create the classic newspaper-style layout where several lines of a paragraph sit beside it. CSS float is designed to allow inline content to flow around an element.
When an image is floated, it is shifted to the left or right of its containing block. Following text can occupy the available horizontal space beside the float until the text reaches the float’s bottom edge.
Therefore, float is the straightforward CSS solution when text must wrap around an image.
Stop Later Content from Wrapping
Another common issue is that content after the paragraph may still flow beside the image if the image is taller than the text. Use clear on the next element when it must begin below the float.
<img src="image.jpg" alt="A descriptive image" class="wrap-left">
<p>Text wraps around the image in this paragraph.</p>
<div class="next-section">
This section starts below the floated image.
</div>
.wrap-left {
float: left;
width: 240px;
margin: 0 20px 10px 0;
}
.next-section {
clear: both;
}
clear: both prevents the element from sitting beside either a left or right float. Use clear: left or clear: right when only one direction needs to be cleared.
Make the Image Responsive
A fixed image width can work on desktop, but a large floated image can leave too little room for text on smaller screens. Use a flexible width and preserve the image’s aspect ratio:
.wrap-left {
float: left;
width: 240px;
max-width: 40%;
height: auto;
margin: 0 20px 10px 0;
}
For narrow screens, you can remove the float so the image appears above the text:
@media (max-width: 600px) {
.wrap-left,
.wrap-right {
float: none;
display: block;
width: 100%;
max-width: 100%;
height: auto;
margin: 0 0 15px;
}
}
This keeps text readable on small screens.
flex and grid Do Not Create Text Wrapping
Flexbox and CSS Grid can place an image beside a text block, but they do not make individual lines of text flow around the image. They create separate layout areas.
.container {
display: flex;
gap: 20px;
}
This is useful when you want an image column and a text column. It is not equivalent to text wrapping around the image’s edge. For paragraph wrapping, use float.
CSS also provides shape-outside for advanced cases where text needs to flow around a non-rectangular shape. It is usually unnecessary for a normal rectangular image.
Complete Example
<article>
<img src="mountain.jpg" alt="Mountain landscape" class="article-image">
<p>
The image is floated to the left, so these lines of text occupy the
available space beside it. When the paragraph extends below the image,
the text returns to the full available width.
</p>
<p class="clear">
This paragraph starts below the image because the float has been cleared.
</p>
</article>
.article-image {
float: left;
width: 240px;
max-width: 40%;
height: auto;
margin: 0 20px 10px 0;
}
.clear {
clear: both;
}
The essential pattern is float on the image, margin for spacing, and clear when later content must start below it. For responsive websites, add flexible image sizing and remove the float on narrow screens. Also provide useful alt text because the image should remain accessible even when the visual layout changes.
Explore More Blogs
How Do You Indent In Html
How Long Does It Take To Learn Html
How To Convert Html To Excel
How To Embed A Google Form In Html
How To Get Html Code From A Website
How To Hide Text In Html
What Are Tags In Websites
What Does Hr Stand For In Html
What Is The Difference Between Css And Html
How To Add An Image From A Folder In Html
How To Add Expires Headers In Html Catswhocode


