Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

CSS float Property

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The float property takes an element out of the normal inline flow in a horizontal sense so that other inline content (text, inline elements) can wrap around it. A floated element is shifted to the side of its containing block and subsequent inline-level content flows alongside it until the float ends; however, the float still participates in the block layout in that it affects the vertical placement of following block-level boxes. Because floats influence how surrounding content wraps, they are frequently used for image/text wrapping and for small, flow-sensitive layout pieces where content should flow around a visual element rather than sit above or below it.

Floats interact with the layout of their container in ways that can be surprising: a container that only contains floated children can appear to collapse because floats are taken out of the normal flow for block layout. To manage that interaction you commonly use clearing techniques - for example the clear property on subsequent elements to stop wrapping, or you create a block formatting context for the containing box (often done via properties such as overflow) so the container expands to include its floats. These interactions also influence how margins and adjacent boxes are calculated, so it’s important to think about containment and clearing whenever floats are involved.

In modern layout practice, floats are best treated as a tool for content wrapping and not as a primary mechanism for large-scale page layout. For two-dimensional or responsive layouts, consider layout systems available through the display property or explicit control with the position property, which tend to be clearer and less error-prone. When you do use floats, combine them with explicit clearing or a clearfix pattern so containers behave predictably, and keep an eye on source order and accessibility since floated elements can change how content is perceived by assistive technologies and users navigating by flow.

Definition

Initial value
none
Applies to
All except for positioned elements and generated content
Inherited
No
Computed value
As specified
Animatable
No
JavaScript syntax
object.style.cssFloat

Interactive Demo

Float me
The rusty swing set creaked a lonely lullaby in the twilight, shadows lengthening like grasping fingers across the dew-kissed grass. A lone dandelion seed, adrift on the breeze, whispered secrets of faraway fields, of dandelion suns and galaxies spun from fluff. Somewhere, beyond the veil of dusk, a coyote laughed, echoing through the stillness like a forgotten memory.

Syntax

float: [ left | right | top | bottom | start | end | none | <page-floats> ] && contour? 

Values

  • leftThe left value indicates that the element must float to the far left side of its containing block.
  • rightThe right value indicates that the element must float to the far right side of its containing block.
  • topSame as 'left'
  • bottomsame as 'right'
  • startIf the 'direction' property is 'ltr', the same as 'left'; otherwise the same as 'right'.
  • endIf the 'direction' property is 'rtl', the same as 'right'; otherwise the same as 'left'.
  • noneIndicates that the element does not contain any float at all. This is the initial value of the float property.

Example

<div class="float-demo">
<h2>Float property example</h2>
<div class="box float-right">
<strong>Floating box</strong>
<p>Floats to the right.</p>
</div>

<img src="https://placehold.co/150" alt="Placeholder image" class="float-left" />

<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere, nisl at
fermentum elementum, urna purus tristique lorem, a tincidunt risus arcu non
mauris. Vivamus luctus, odio at interdum dictum, neque sapien cursus justo,
vitae volutpat lorem nunc vitae sapien.
</p>

<p>
Curabitur non lectus ac sapien interdum cursus. This paragraph continues to show
how text wraps around floated elements. Resize the container or window to see the
float behavior adapt.
</p>

<div class="clearfix"></div>
</div>
.float-demo {
    max-width: 720px;
    border: 1px solid #e0e0e0;
    padding: 16px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    background: #ffffff;
}

.float-left {
    float: left;
    width: 150px;
    height: auto;
    margin: 0 16px 16px 0;
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.float-right {
    float: right;
    width: 140px;
    background: #f7fbff;
    padding: 10px;
    border: 1px solid #dfeef8;
    margin: 0 0 16px 16px;
    box-sizing: border-box;
    border-radius: 4px;
}

.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

/* Small responsive tweak */
@media (max-width: 480px) {
    .float-left,
    .float-right {
        float: none;
        width: 100%;
        margin: 0 0 12px 0;
    }
}

Browser Support

The following information will show you the current browser support for the CSS float property. Hover over a browser icon to see the version that first introduced support for this CSS property.

This property is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!