shadcn.io is an independent project built on shadcn/ui
On this page9 sections
Float pins a small element to a corner or edge of its parent, centered on that spot so half of it hangs outside: the unread count on a bell button, a status dot on an avatar, a remove button on a photo. It is a positioned div and nothing more, with no state and nothing to open.
For the count itself, put a Badge inside the Float. For a hint that appears on hover, use a Tooltip.
Installation
Anatomy

Usage
<script setup lang="ts">
import { BellIcon } from "lucide-vue-next";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Float } from "@/components/ui/float";
</script>
Float is placed against the nearest positioned ancestor, so the wrapper needs relative, and inline-flex keeps the wrapper as small as the button so the count lands on the button's corner.
<template>
<div class="relative inline-flex">
<Button aria-label="Notifications, 9+ unread" size="icon-lg" variant="outline">
<BellIcon />
</Button>
<Float aria-hidden="true">
<Badge pill size="sm" variant="default">
9+
</Badge>
</Float>
</div>
</template>
Accessibility
Float is a plain div with no role, so a screen reader reads its content where it sits in the page, after the control it decorates and with nothing tying the two together. Put what the marker says into the control's own name, such as an aria-label of Notifications, 9+ unread on the bell button, and set aria-hidden="true" on the Float so the count isn't read twice. A Float that holds a control, such as a remove button on a photo, is the exception: that button needs a label of its own and stays in the tab order.
Demos
Placement
Nine boxes, each labeled with the placement it shows, from top-start to bottom-end, with a badge reading 3 on that spot. Every placement centers the marker on its corner or edge, so half of it hangs outside the box. Pick top-end, the default, for a count, and bottom-end for a status dot on an avatar.
Remove button
Three assignees' avatars, each with a small round button on its top-end corner that takes that person off the list. Here the Float holds a real control, so it keeps no aria-hidden and each button has its own aria-label, such as Remove @shadcn. Use it for selected people, upload previews or attached files.
FAQ
How do I choose where a Float sits in Vue?
Set placement to one of nine values, top, middle or bottom joined to start, center or end, such as bottom-start. Without it a Float sits at top-end, the usual spot for a count.
Start and end are the edges where a line of text starts and ends, so in a left-to-right page end is the right. The element repeats its value in data-placement, which a class can key on, and the Placement demo shows all nine.
Why is my Float in the wrong place?
Float is absolute, so it is placed against the nearest ancestor that has a position of its own. Without relative on the wrapper, it lands on the corner of a card, a dialog or the page instead.
The wrapper also has to be the size of the thing the marker belongs to. A plain div stretches across the row, which puts a top-end count at the far end of the row rather than on the button, so make the wrapper inline-flex or w-fit, as the usage does.
Why is half of my Float cut off?
The parent has overflow-hidden. A Float hangs half outside its parent, and an element that clips its overflow, such as an image wrapper with rounded corners or a scrolling list, cuts that half away.
Move the Float to a wrapper around the clipping element, with relative on the wrapper, so the marker hangs over the corner from outside. If the marker should sit fully inside the box instead, add translate-0 to the Float, which removes the half-outside offset, and rtl:translate-0 as well when the page can run right to left.
Can a Float hold a button, such as a remove button on a photo?
It can. The Float sets pointer-events-auto, so its child stays clickable even inside a parent that turns pointer events off, and z-10 lifts it above the parent's content.
Give the button its own name, such as an aria-label of Remove photo, because an icon alone has none. Keep it at least 24px square, since a small target on a corner is easy to miss, and leave the Float without aria-hidden so the button stays reachable, as in the Remove button demo.
Should I use Float or a Badge?
Use both: they do different jobs. A Badge draws the pill with the count or the label, and on its own it sits in the flow, next to text such as a menu item's name. Float places whatever you put in it on a corner of something else, as the usage does with a Badge on a bell button.
For a hint that appears on hover or focus, use a Tooltip instead, which opens in a layer of its own.
Can one parent have more than one Float?
Yes. Render one Float per spot, each with its own placement, such as a count at top-end and a status dot at bottom-end. The parent is the reference for every one of them.
They don't move out of each other's way. Two Floats with the same placement sit on the same point, and since both have z-10, the one that comes later in the markup covers the other.
Does Float work in a right-to-left layout?
Yes. The start and end placements are set with logical insets, so they switch sides with the direction, and the shift that hangs the marker half outside flips with them under Tailwind's rtl: variant. In a right-to-left page a top-end count sits centered on the top left corner.
The rtl: variant reads the dir attribute, on the html element or on any parent of the Float, so set it there. The center placements look the same in both directions.
API Reference
Float
<div> data-slot="float"
placement?"bottom-center" | "bottom-end" | "bottom-start" | "middle-center" | "middle-end" | "middle-start" | "top-center" | "top-end" | "top-start"
The corner or edge it floats at, such as top-end.
- Type
"bottom-center" | "bottom-end" | "bottom-start" | "middle-center" | "middle-end" | "middle-start" | "top-center" | "top-end" | "top-start"- Default
"top-end"
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
class?string
Merged with the part's classes.
data-placement?string
Mirrors placement.











