LESSON 7.6
CSS Float: How to Wrap and Position Elements
Classic text-wrapping and side-by-side layout techniques
Learn how the CSS float property works to wrap text around images and create side-by-side layouts, plus how to clear floats when they affect surrounding content.
💡 The Concept
The CSS float property is one of the original layout tools in CSS, still useful today for wrapping text around images. The float property pushes an element to the left or right side of its container so that surrounding text wraps around it. It was originally designed to replicate the print layout technique of wrapping text around images, and that is still its most common use today.
The float property takes three values:
- left: the element floats to the left and text wraps on its right
- right: the element floats to the right and text wraps on its left
- none: the default, no floating
Floating an Image
The most common use case is wrapping text around an image. Float the image and add a margin so the text does not press right up against it:
img {
float: left;
}

When you float images, you usually need to adjust how they are placed on the page with some margin. A nice trick for floated images is to set the width of an image to a percentage so that the floated image works on mobile devices.
Clearing Floats
When you float an element, it is removed from the normal document flow. The parent container no longer accounts for its height, which can cause the next element to slide up alongside it unexpectedly. The clear property fixes this by forcing an element to start below any floated elements:
footer {
clear: both;
}
When to Use Floats
Floats are less common for page layout. More common is to create a layout with stacking columns. If you continue to follow these lessons you will learn how to do it with Bootstrap. But for wrapping text around an image in an article or blog post, float is still the right tool.
🎬 Video Demonstration
This video demonstrates how the float property works.
Exercise: Try It Yourself
Step 1. Open JSFiddle.
Step 2. Add this HTML to the HTML panel. Notice that the image comes before the paragraph so the text wraps around it correctly.
<div>
<img src="https://webdevstudents.com/wp-content/uploads/2025/09/corgi.png" width="200" height="200" alt="A corgi in a field with yellow flowers">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
What is placeholder text? When web designers are working on a layout but don’t have the final copy yet, they place “lorem ipsum” text where the real content will go.
Step 3. Add this CSS to the CSS panel:
img {
float: right;
margin-left: 15px;
}
Step 4. Run the fiddle. The text should wrap around the corgi on its left side.
Step 5. Change float: right to float: left and run it again. Notice that the margin now needs to move to the right side so the text doesn’t press against the image.
Run your fiddle and check your result against this screenshot:

❓ Frequently Asked Questions
When you float an element, only the HTML content that comes after it in the document can wrap around it. Content that appears before the float is already laid out and will not reflow. So if you place your image after a paragraph of text, that paragraph will sit above the image rather than wrapping around it. By placing the image first in the HTML, all the paragraphs that follow it will wrap around it as intended.
When you float an element, it is removed from the normal document flow, so the parent container no longer counts its height. If the floated image is the only content inside the container, the container collapses to zero height and its background appears to vanish. The fix is to add overflow: hidden; to the parent container, which forces it to expand around the floated content.
This is one of the most common float problems. Because a floated element is removed from the normal document flow, any element that comes after it in the HTML can slide up alongside it, including your footer. The fix is to add clear: both; to your footer’s CSS. This tells the browser that the footer must start below any floated elements, on both the left and right sides.
★ Key Takeaways
Float is a CSS property used to wrap text around images and position elements side by side. This lesson showed you how float works and how to use the clear property when you are done with it. Next, you will learn about advanced CSS selectors, which give you more precise ways to target specific elements. These are a big step up in your styling power.
Google Ads
The costs of this website are partially offset by revenue from Google Ads.Tools of the Trade
HTML/CSS Lessons
-
-
-
1.3. HTML Tag Preview
-
-
-
2.2. The HTML Framework
-
-
2.4. HTML Headings
-
-
-
-
-
-
3.01. Introduction to CSS
-
3.02. How CSS Cascades
-
-
-
-
3.05. CSS Colors
-
3.06. RGBA Colors
-
-
3.08. Font and Text Properties
-
3.09. Classes and IDs
-
-
-
-
-
4.3. HTML Embedded Images
-
-
-
-
-
-
5.1. CSS Borders
-
5.2. CSS Border Radius
-
5.3. CSS Gradients
-
5.4. CSS Box Shadows
-
5.5. CSS Text Shadows
-
7.1. The Display Property
-
-
-
7.4. The Box Model
-
-
-
-
-
-
9.1. Website Tables
-
9.2. HTML Forms
-
-
9.4. Special Form Fields
-
9.5. Embedding Multimedia
-
-
9.7. Keyboard Shortcuts
-
10.1. What Is a Framework?
-
10.2. Font Awesome Icons
-
-
10.4. Bootstrap Grid System
-
-
10.6. Bootstrap Navigation
-
-
11.2. Purchasing a Domain Name
-
11.3. Website Hosting
-
11.4. Nameservers and DNS
-
11.5. FTP
-
11.6. GitHub Pages
