Last updated: 4 April 2025

Tailwind CSS Float

The tailwind float utility class allows you to control the floating behavior of elements.


Tailwind Float

The tailwind float utility class allows you to control the floating behavior of elements. With Tailwind's float class, you can easily float elements to the left or right within their containing elements.

How to apply Tailwind float

To apply a specific Tailwind float behavior to an element, you can use the float-{value} utility class, where {value} represents the desired float behavior. Here are the common values you can use:

  • float-left: Floats the element to the left side of its containing element.
  • float-right: Floats the element to the right side of its containing element.
  • float-none: Removes any floating behavior from the element.

check out example of tailwind float:

html
<div>
<img src="https://devwares.com" class="float-left" />
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime mollitia,
molestiae quas vel sint commodi repudiandae consequuntur voluptatum laborum
numquam blanditiis harum quisquam eius sed odit fugiat iusto fuga
praesentium optio, eaque rerum! Provident similique accusantium nemo autem.
Veritatis obcaecati tenetur iure eius earum ut molestias architecto
voluptate aliquam nihil, eveniet aliquid culpa officia aut! Impedit sit sunt
quaerat, odit, tenetur error, harum nesciunt ipsum debitis quas aliquid.
Reprehenderit, quia.
</p>
</div>

Preview

This paragraph wraps around the image, which uses Tailwind float left. This setup is especially useful when you want to mimic traditional newspaper-style columns or enhance visual storytelling.

In the above example, a <div> element is styled with the float-left class, which floats the element to the left side of its containing element.

🧪 Practical Example: Tailwind Float Right with an Image

Let’s start with a basic example of an image floated to the right with text wrapping around it.

html
<div class="p-4">
<img
src="https://via.placeholder.com/150"
alt="Sample"
class="float-right ml-4 mb-4 w-40 h-auto rounded-lg shadow-md"
/>
<p>
This is some sample text that wraps around the image. Notice how the image
uses <strong>Tailwind float right</strong>, and the text flows neatly
alongside it. This layout is perfect for blog posts, documentation pages, or
anywhere you want to create a visually balanced design.
</p>
</div>

Preview

Sample

This is some sample text that wraps around the image. Notice how the image uses Tailwind float right, and the text flows neatly alongside it. This layout is perfect for blog posts, documentation pages, or anywhere you want to create a visually balanced design.

✅ What’s happening here?

  • The image is floated to the right using float-right.

  • We add spacing with ml-4 and mb-4.

  • Content wraps naturally, thanks to the float.

🧰 Use Cases for float in Tailwind

While float is less common for building full layouts today, it’s still very useful for micro-layouts and content styling.

✔️ Common Use Cases

  • Wrapping text around images

  • Aligning badges, icons, or labels

  • Creating a Tailwind float button that pins to the left or right

  • Simple sidebar or callout sections

🧠 Tip: Always add spacing utilities (mr-, mb-) to give surrounding content some breathing room.

💬 Tailwind Float Button Example

Want a floating button aligned to the right of a container? Here’s how to make a Tailwind float button:

html
<div class="relative p-4 border rounded shadow">
<button
class="float-right bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700"
>
Float Button
</button>
<p>
This section has a <strong>Tailwind float button</strong> pinned to the
right using <code>float-right</code>. You might use this pattern for quick
actions, dismiss buttons, or secondary calls to action.
</p>
</div>

Preview

This section has a Tailwind float button pinned to the right using float-right. You might use this pattern for quick actions, dismiss buttons, or secondary calls to action.

Works great for toolbars, notification panels, or compact call-to-action areas.

Clearing Tailwind Floats

When you float an element, it can affect the layout and positioning of subsequent elements. To prevent this, you may need to clear the float. Tailwind provides a clear-{value} utility class that you can apply to elements following a floated element to clear the float.

Here are the common values you can use:

  • clear-left: Clears any left floats.
  • clear-right: Clears any right floats.
  • clear-both: Clears both left and right floats.
html
<div>
<img src="https://devwares.com" class="float-left" />
<p>This element floats to the left side.</p>
<div class="clear-both">
This element clears the float and appears below the floated element.
</div>
</div>

Preview

Lorem ipsum dolor sit amet consectetur adipisicing elit. Maxime mollitia, molestiae quas vel.

This element clears the float and appears below the floated element.

Tailwind CSS FLoat Class Table

ClassProperties
float-rightfloat: right;
float-left float: left;
float-nonefloat-none

Pitfalls to Avoid

  • Parent Collapse: Use overflow-hidden or apply clearfix to prevent containers from collapsing around floated children.

  • Unintended Wrapping: Clear floats where necessary to maintain flow.

  • Responsiveness Issues: Combine with responsive classes like md:float-left or lg:float-none for better control on different screens.

🚀 Want to Keep Learning?

Experiment with floats and other layout utilities like:

✨ What's Next?

Now that you’ve mastered Tailwind Background Repeat, try experimenting with:

Windframe Tailwind blocks

blog

Windframe is a drag and drop builder for rapidly building tailwind css websites and UIs

Start building stunning tailwind UIs! 

Build from scratch or select prebuilt tailwind templates