src/docs/overflow.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 = "overflow"; export const description = "Utilities for controlling how an element handles content that is too large for the container.";
<ApiTable rows={[ ["overflow-auto", "overflow: auto;"], ["overflow-hidden", "overflow: hidden;"], ["overflow-clip", "overflow: clip;"], ["overflow-visible", "overflow: visible;"], ["overflow-scroll", "overflow: scroll;"], ["overflow-x-auto", "overflow-x: auto;"], ["overflow-y-auto", "overflow-y: auto;"], ["overflow-x-hidden", "overflow-x: hidden;"], ["overflow-y-hidden", "overflow-y: hidden;"], ["overflow-x-clip", "overflow-x: clip;"], ["overflow-y-clip", "overflow-y: clip;"], ["overflow-x-visible", "overflow-x: visible;"], ["overflow-y-visible", "overflow-y: visible;"], ["overflow-x-scroll", "overflow-x: scroll;"], ["overflow-y-scroll", "overflow-y: scroll;"], ]} />
Use the overflow-visible utility to prevent content within an element from being clipped:
<div className="flex flex-col py-5 pl-24">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Andrew Alfred</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Technical advisor</span>
</div>
</div>
} </Example>
<!-- [!code classes:overflow-visible] -->
<div class="overflow-visible ...">
<!-- ... -->
</div>
Note that any content that overflows the bounds of the element will then be visible.
Use the overflow-hidden utility to clip any content within an element that overflows the bounds of that element:
<div className="flex flex-col py-5 pl-24">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Andrew Alfred</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Technical advisor</span>
</div>
</div>
} </Example>
<!-- [!code classes:overflow-hidden] -->
<div class="overflow-hidden ...">
<!-- ... -->
</div>
Use the overflow-auto utility to add scrollbars to an element in the event that its content overflows the bounds of that element:
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Andrew Alfred</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Technical advisor</span>
</div>
</div>
<div className="flex items-center gap-4 p-4">
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Debra Houston</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Analyst</span>
</div>
</div>
<div className="flex items-center gap-4 p-4">
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Jane White</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Director, Marketing</span>
</div>
</div>
<div className="flex items-center gap-4 p-4">
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Ray Flint</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Technical Advisor</span>
</div>
</div>
</div>
} </Example>
<!-- [!code classes:overflow-auto] -->
<div class="overflow-auto ...">
<!-- ... -->
</div>
Unlike overflow-scroll, which always shows scrollbars, this utility will only show them if scrolling is necessary.
Use the overflow-x-auto utility to allow horizontal scrolling if needed:
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">Andrew</strong>
</div>
</div>
<div className="flex-none px-3 py-6 first:pl-6 last:pr-6">
<div className="flex flex-col items-center justify-center gap-3">
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">Emily</strong>
</div>
</div>
<div className="flex-none px-3 py-6 first:pl-6 last:pr-6">
<div className="flex flex-col items-center justify-center gap-3">
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">Whitney</strong>
</div>
</div>
<div className="flex-none px-3 py-6 first:pl-6 last:pr-6">
<div className="flex flex-col items-center justify-center gap-3">
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">David</strong>
</div>
</div>
<div className="flex-none px-3 py-6 first:pl-6 last:pr-6">
<div className="flex flex-col items-center justify-center gap-3">
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">Kristin</strong>
</div>
</div>
<div className="flex-none px-3 py-6 first:pl-6 last:pr-6">
<div className="flex flex-col items-center justify-center gap-3">
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">Sarah</strong>
</div>
</div>
</div>
</div>
} </Example>
<!-- [!code classes:overflow-x-auto] -->
<div class="overflow-x-auto ...">
<!-- ... -->
</div>
Use the overflow-y-auto utility to allow vertical scrolling if needed:
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Andrew Alfred</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Technical advisor</span>
</div>
</div>
<div className="flex items-center gap-4 p-4">
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Debra Houston</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Analyst</span>
</div>
</div>
<div className="flex items-center gap-4 p-4">
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Jane White</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Director, Marketing</span>
</div>
</div>
<div className="flex items-center gap-4 p-4">
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Ray Flint</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Technical Advisor</span>
</div>
</div>
</div>
} </Example>
<!-- [!code classes:overflow-y-auto] -->
<div class="h-32 overflow-y-auto ...">
<!-- ... -->
</div>
Use the overflow-x-scroll utility to allow horizontal scrolling and always show scrollbars unless always-visible scrollbars are disabled by the operating system:
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">Andrew</strong>
</div>
</div>
<div className="flex-none px-3 py-6 first:pl-6 last:pr-6">
<div className="flex flex-col items-center justify-center gap-3">
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">Emily</strong>
</div>
</div>
<div className="flex-none px-3 py-6 first:pl-6 last:pr-6">
<div className="flex flex-col items-center justify-center gap-3">
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">Whitney</strong>
</div>
</div>
<div className="flex-none px-3 py-6 first:pl-6 last:pr-6">
<div className="flex flex-col items-center justify-center gap-3">
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">David</strong>
</div>
</div>
<div className="flex-none px-3 py-6 first:pl-6 last:pr-6">
<div className="flex flex-col items-center justify-center gap-3">
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">Kristin</strong>
</div>
</div>
<div className="flex-none px-3 py-6 first:pl-6 last:pr-6">
<div className="flex flex-col items-center justify-center gap-3">
<strong className="text-xs font-medium text-gray-900 dark:text-gray-200">Sarah</strong>
</div>
</div>
</div>
</div>
} </Example>
<!-- [!code classes:overflow-x-scroll] -->
<div class="overflow-x-scroll ...">
<!-- ... -->
</div>
Use the overflow-y-scroll utility to allow vertical scrolling and always show scrollbars unless always-visible scrollbars are disabled by the operating system:
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Andrew Alfred</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Technical advisor</span>
</div>
</div>
<div className="flex items-center gap-4 p-4">
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Debra Houston</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Analyst</span>
</div>
</div>
<div className="flex items-center gap-4 p-4">
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Jane White</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Director, Marketing</span>
</div>
</div>
<div className="flex items-center gap-4 p-4">
<div className="flex flex-col">
<strong className="text-sm font-medium text-gray-900 dark:text-gray-200">Ray Flint</strong>
<span className="text-sm font-medium text-gray-500 dark:text-gray-400">Technical Advisor</span>
</div>
</div>
</div>
} </Example>
<!-- [!code classes:overflow-y-scroll] -->
<div class="overflow-y-scroll ...">
<!-- ... -->
</div>
Use the overflow-scroll utility to add scrollbars to an element:
<!-- [!code classes:overflow-scroll] -->
<div class="overflow-scroll ...">
<!-- ... -->
</div>
Unlike overflow-auto, which only shows scrollbars if they are necessary, this utility always shows them. Note that some operating systems (like macOS) hide unnecessary scrollbars regardless of this setting.