# Source: https://github.com/tailwindlabs/tailwindcss.com/blob/main/src/docs/float.mdx

import { ApiTable } from "@/components/api-table.tsx";
import { Example } from "@/components/example.tsx";
import { Figure } from "@/components/figure.tsx";
import { ResponsiveDesign } from "@/components/content.tsx";

export const title = "float";
export const description = "Utilities for controlling the wrapping of content around an element.";

<ApiTable
  rows={[
    ["float-right", "float: right;"],
    ["float-left", "float: left;"],
    ["float-start", "float: inline-start;"],
    ["float-end", "float: inline-end;"],
    ["float-none", "float: none;"],
  ]}
/>

## Examples

### Floating elements to the right

Use the `float-right` utility to float an element to the right of its container:

<Figure>

<Example resizable>
  {
    <>
      <img
        className="float-right ml-6 aspect-16/9 w-2/5 rounded-lg object-cover outline -outline-offset-1 outline-black/10"
        src="https://images.unsplash.com/photo-1554629947-334ff61d85dc?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1000&h=1000&q=90"
      />
      <p className="text-justify">
        Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world, but
        what about that kid, sitting down, opening a book, right now, in a branch at the local library and finding
        drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE deserve
        better? Look. If you think this is about overdue fines and missing books, you'd better think again. This is
        about that kid's right to read a book without getting his mind warped! Or: maybe that turns you on, Seinfeld;
        maybe that's how y'get your kicks. You and your good-time buddies.
      </p>
    </>
  }
</Example>

```html
<!-- [!code classes:float-right] -->
<article>
  <img class="float-right ..." src="/img/mountains.jpg" />
  <p>Maybe we can live without libraries, people like you and me. ...</p>
</article>
```

</Figure>

### Floating elements to the left

Use the `float-left` utility to float an element to the left of its container:

<Figure>

<Example resizable>
  {
    <>
      <img
        className="float-left mr-6 aspect-16/9 w-2/5 rounded-lg object-cover outline -outline-offset-1 outline-black/10"
        src="https://images.unsplash.com/photo-1554629947-334ff61d85dc?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1000&h=1000&q=90"
      />
      <p className="text-justify">
        Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world, but
        what about that kid, sitting down, opening a book, right now, in a branch at the local library and finding
        drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE deserve
        better? Look. If you think this is about overdue fines and missing books, you'd better think again. This is
        about that kid's right to read a book without getting his mind warped! Or: maybe that turns you on, Seinfeld;
        maybe that's how y'get your kicks. You and your good-time buddies.
      </p>
    </>
  }
</Example>

```html
<!-- [!code classes:float-left] -->
<article>
  <img class="float-left ..." src="/img/mountains.jpg" />
  <p>Maybe we can live without libraries, people like you and me. ...</p>
</article>
```

</Figure>

### Using logical properties

Use the `float-start` and `float-end` utilities, which use [logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties/Basic_concepts) to map to either the left or right side based on the text direction:

<Figure>

<Example resizable>
  {
    <>
      <div dir="ltr">
        <p className="mb-4 font-mono text-xs font-medium text-gray-500 dark:text-gray-400">left-to-right</p>
        <div>
          <img
            className="float-start me-6 aspect-16/9 w-2/5 rounded-lg object-cover outline -outline-offset-1 outline-black/10"
            src="https://images.unsplash.com/photo-1554629947-334ff61d85dc?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1000&h=1000&q=90"
          />
          <p className="text-justify">
            Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world,
            but what about that kid, sitting down, opening a book, right now, in a branch at the local library and
            finding drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE
            deserve better? Look. If you think this is about overdue fines and missing books, you'd better think again.
            This is about that kid's right to read a book without getting his mind warped! Or: maybe that turns you on,
            Seinfeld; maybe that's how y'get your kicks. You and your good-time buddies.
          </p>
        </div>
      </div>
      <div dir="rtl" className="mt-6">
        <p className="mb-4 font-mono text-xs font-medium text-gray-500 dark:text-gray-400">right-to-left</p>
        <div>
          <img
            className="float-start me-6 aspect-16/9 w-2/5 rounded-lg object-cover outline -outline-offset-1 outline-black/10"
            src="https://images.unsplash.com/photo-1554629947-334ff61d85dc?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1000&h=1000&q=90"
          />
          <p className="text-justify">
            ربما يمكننا العيش بدون مكتبات، أشخاص مثلي ومثلك. ربما. بالتأكيد، نحن أكبر من أن نغير العالم، ولكن ماذا عن
            ذلك الطفل الذي يجلس ويفتح كتابًا الآن في أحد فروع المكتبة المحلية ويجد رسومات للتبول والبول على القطة في
            القبعة والإخوة الصينيون الخمسة؟ ألا يستحق الأفضل؟ ينظر. إذا كنت تعتقد أن الأمر يتعلق بالغرامات المتأخرة
            والكتب المفقودة، فمن الأفضل أن تفكر مرة أخرى. يتعلق الأمر بحق ذلك الطفل في قراءة كتاب دون أن يتشوه عقله! أو:
            ربما يثيرك هذا يا سينفيلد؛ ربما هذه هي الطريقة التي تحصل بها على ركلاتك. أنت ورفاقك الطيبين.
          </p>
        </div>
      </div>
    </>
  }
</Example>

```html
<!-- [!code word:dir="rtl"] -->
<!-- [!code classes:float-start] -->
<article>
  <img class="float-start ..." src="/img/mountains.jpg" />
  <p>Maybe we can live without libraries, people like you and me. ...</p>
</article>

<article dir="rtl">
  <img class="float-start ..." src="/img/mountains.jpg" />
  <p>... ربما يمكننا العيش بدون مكتبات، أشخاص مثلي ومثلك. ربما. بالتأكيد</p>
</article>
```

</Figure>

### Disabling a float

Use the `float-none` utility to reset any floats that are applied to an element:

<Figure>

<Example resizable>
  {
    <>
      <img
        className="mb-4 aspect-16/9 w-2/5 rounded-lg object-cover outline -outline-offset-1 outline-black/10"
        src="https://images.unsplash.com/photo-1554629947-334ff61d85dc?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1000&h=1000&q=90"
      />
      <p className="text-justify">
        Maybe we can live without libraries, people like you and me. Maybe. Sure, we're too old to change the world, but
        what about that kid, sitting down, opening a book, right now, in a branch at the local library and finding
        drawings of pee-pees and wee-wees on the Cat in the Hat and the Five Chinese Brothers? Doesn't HE deserve
        better? Look. If you think this is about overdue fines and missing books, you'd better think again. This is
        about that kid's right to read a book without getting his mind warped! Or: maybe that turns you on, Seinfeld;
        maybe that's how y'get your kicks. You and your good-time buddies.
      </p>
    </>
  }
</Example>

```html
<!-- [!code classes:float-none] -->
<article>
  <img class="float-none ..." src="/img/mountains.jpg" />
  <p>Maybe we can live without libraries, people like you and me. ...</p>
</article>
```

</Figure>

### Responsive design

<ResponsiveDesign property="float">

```html
<!-- [!code classes:md:float-left] -->
<img class="float-right md:float-left" src="/img/mountains.jpg" />
```

</ResponsiveDesign>