CSS float Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout

What You’ll Learn

The float property positions an element to the left or right and lets text wrap around it. It is a classic CSS layout tool that remains useful for images in articles and legacy layouts.

01

float: left

Align left.

02

float: right

Align right.

03

Text wrap

Flow around.

04

Default none

Normal flow.

05

Clear floats

Avoid collapse.

06

Modern alt

Flex & Grid.

Introduction

The float property in CSS is used to position an element to the left or right within its container, allowing text and inline elements to wrap around it. This property has been widely used in web design for creating layouts, although modern techniques like Flexbox and Grid have largely replaced it for complex designs.

Definition and Usage

Apply float: left or float: right on an element such as an image, badge, or sidebar block. The floated element is taken out of normal flow, and surrounding content flows beside it on the opposite side. Use margins to add space between the float and wrapped text.

💡
Beginner Tip

Float is still a great choice when you want text to wrap around an image in a blog post. For full page layouts, prefer Flexbox or Grid instead.

📝 Syntax

The syntax for the float property is straightforward. It can be applied to any block-level element and accepts specific keyword values:

syntax.css
element {
  float: value;
}

Basic Example

float-basic.css
.float-left {
  float: left;
  margin-right: 20px;
}
float: none; float: left; float: right; float: inherit;

Default Value

The default value of the float property is none, meaning the element does not float and behaves as a normal block-level or inline element in document flow.

Syntax Rules

  • Apply on the element you want to pull left or right — commonly images, figures, or sidebars.
  • Accepts keyword values: none, left, right, and inherit.
  • Floated elements are removed from normal flow; siblings may wrap beside them.
  • Parent containers may collapse in height unless floats are cleared.
  • The property is not inherited (use inherit explicitly if needed).

⚡ Quick Reference

QuestionAnswer
Initial valuenone
Applies toAll elements
InheritedNo
Value typeKeyword (none, left, right, inherit)
Common useImages with wrapping text; legacy column layouts

💎 Property Values

ValueDescription
noneThe element does not float. This is the default value and keeps normal document flow.
leftThe element floats to the left of its container. Content wraps on the right side of the element.
rightThe element floats to the right of its container. Content wraps on the left side of the element.
inheritThe element inherits the float value from its parent element.

Float and document flow

When an element floats, it is shifted as far left or right as possible within its containing block. Block boxes below it behave as if the float were not there, while inline content wraps around the floated box.

👀 Live Preview

A thumbnail floated left with margin-right — paragraph text wraps naturally beside and below it:

The float property is useful for simple layouts where elements need to align left or right within their container. By floating the image to the left, surrounding text flows to the right, creating a visually appealing arrangement.

Examples Gallery

In this example, we’ll float an image to the left so text wraps around it — plus float right, a two-column layout, and clearing floats with a clearfix.

🖼 Text Wrapping

Start with the reference example — an image floated left with wrapping paragraph text.

Example 1 — Float an Image Left

Float an image to the left and add right margin so text does not touch the image edge.

float-left.html
<style>
  .float-left {
    float: left;
    margin-right: 20px;
  }
</style>

<img src="photo.jpg" alt="Example" class="float-left">
<p>
  This paragraph wraps around the floated image on the right side.
</p>
Try It Yourself

How It Works

The image is pulled to the left edge of its container. Inline text in the paragraph fills the space to the right and then continues beneath the image.

Example 2 — Float Right Badge

Pull a callout or badge to the right so body text wraps on the left.

float-right.css
.badge {
  float: right;
  margin-left: 16px;
}
Try It Yourself

How It Works

float: right mirrors the left behavior. Use margin-left (instead of margin-right) to separate the float from wrapped text.

🛠 Layout Patterns

Classic float-based columns and how to contain floated children.

Example 3 — Two-Column Float Layout

A simple sidebar and main content pattern using left floats and percentage widths.

float-columns.css
.sidebar {
  float: left;
  width: 30%;
}
.main {
  float: left;
  width: 70%;
}
Try It Yourself

How It Works

Both columns float left and sit side by side when their combined width fits. This was a common pattern before Flexbox and Grid, but still appears in older codebases.

Example 4 — Clearfix Container

Prevent a parent from collapsing when it only contains floated children.

float-clearfix.css
.clearfix::after {
  content: "";
  display: table;
  clear: both;
}
Try It Yourself

How It Works

Without clearing, a parent's background may not wrap floated children. A clearfix pseudo-element forces the container to expand. See also the CSS clear property.

♿ Accessibility

  • Keep meaningful alt text on floated images so screen reader users understand the content.
  • Do not rely on float order alone for reading sequence — DOM order should match the intended narrative.
  • Ensure sufficient spacing between floated elements and text for readability and touch targets.
  • Test zoomed layouts — narrow floated columns can become hard to read on small screens.
  • Prefer semantic HTML like figure and aside when floating media or side content.

🧠 How float Works

1

Element is taken out of flow

The floated box is shifted left or right as far as possible within its containing block.

Out of flow
2

Inline content wraps beside it

Text and inline elements flow on the opposite side of the float, then continue below it.

Text wrap
3

Following blocks may overlap

Block boxes behave as if the float were not there unless you clear floats or use a clearfix.

Clear needed
=

Wrapped content layout

Images and side elements sit beside flowing text without complex grid setup.

🖥 Browser Compatibility

The float property is supported in all modern browsers and has been part of CSS since its early days. It works consistently across browsers, making it a reliable choice for simple layout tasks.

Baseline · Universal support

float everywhere

Left, right, none, and inherit all work consistently in every browser, including legacy environments.

99% Universal support
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions
Full support
Opera All modern versions
Full support
float property 99% supported

Bottom line: float is universally supported. Pair it with clear or a clearfix when containing floated children.

🎉 Conclusion

The float property is a useful tool for web developers, particularly for simple tasks like aligning images within text. While it has been largely supplanted by more advanced layout techniques such as Flexbox and Grid, understanding how to use float effectively remains valuable for maintaining and updating legacy code or for specific design needs.

Experiment with the float property to see how it can enhance your web layouts. For beginners, remember: default is none, use left or right for wrapping content, and always clear floats when a parent must contain floated children.

💡 Best Practices

✅ Do

  • Use float: left or right for images with wrapping text
  • Add margin on the wrapped-text side for breathing room
  • Clear floats or use a clearfix on parent containers
  • Prefer Flexbox or Grid for new multi-column page layouts
  • Learn the clear property alongside float

❌ Don’t

  • Build entire responsive sites with floats alone today
  • Forget to clear floats — parents may collapse visually
  • Float elements without considering mobile readability
  • Assume float changes DOM reading order for assistive tech
  • Stack many nested floats without a clear containment strategy

Key Takeaways

Knowledge Unlocked

Five things to remember about float

Use these points when wrapping content or reading legacy CSS.

5
Core concepts
none 02

Default none

Normal flow.

Default
📄 03

Text wrap

Inline flows around.

Behavior
🛠 04

Clear floats

Contain children.

Pattern
📈 05

Modern alt

Flex & Grid.

Today

❓ Frequently Asked Questions

The float property positions an element to the left or right of its container and removes it from normal document flow so inline content and text wrap around it.
The default value is none, which means the element does not float and stays in normal block or inline flow.
float: left pulls the element to the left side of its container and content wraps on the right. float: right pulls it to the right side and content wraps on the left.
Use the clear property on a following element (often clear: both), or apply a clearfix technique to the parent container so it expands to contain floated children.
For new layouts, Flexbox and Grid are usually better choices. float is still useful for wrapping text around images and for maintaining legacy float-based code.

Practice in the Live Editor

Open the HTML editor, float an image left or right, and watch how paragraph text wraps around it.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful