shadcn.io is an independent project built on shadcn/ui
On this page9 sections
A sheet is a dialog that slides in from one edge of the screen and runs its whole length, for work that needs more room than a centered window: a filter panel, a cart, an edit form next to the list it changes.
A short task fits a Dialog in the middle of the screen. On phones, where people expect to swipe a panel away, use a Drawer: a sheet has no gesture, and a button, Escape or a click outside closes it.
Installation
Anatomy

Usage
<script lang="ts">
import { Button } from "@/components/ui/button"
import { Field, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"
import {
Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter,
SheetHeader, SheetTitle, SheetTrigger,
} from "@/components/ui/sheet"
let open = $state(false)
const setOpen = (next: typeof open | ((previous: typeof open) => typeof open)) => { open = typeof next === "function" ? next(open) : next }
const handleOpenChange = (open: boolean) => {
setOpen(open);
}
const handleSubmit = (event: Event & { currentTarget: EventTarget & HTMLFormElement }) => {
event.preventDefault();
setOpen(false);
}
</script>
<Sheet onOpenChange={handleOpenChange} open={open}><SheetTrigger>{#snippet render({ props })}<Button {...props} variant="outline">Open</Button>{/snippet}</SheetTrigger><SheetContent><SheetHeader><SheetTitle>Edit profile</SheetTitle><SheetDescription>Make changes to your profile here. Click save when you're done.</SheetDescription></SheetHeader><form class="contents" onsubmit={handleSubmit}><div class="grid flex-1 auto-rows-min gap-6 px-4"><Field class="grid gap-3"><FieldLabel>Name</FieldLabel><Input defaultValue="Pedro Duarte" type="text" /></Field><Field class="grid gap-3"><FieldLabel>Username</FieldLabel><Input defaultValue="@peduarte" type="text" /></Field></div><SheetFooter><Button type="submit">Save changes</Button><SheetClose>{#snippet render({ props })}<Button {...props} variant="outline">Close</Button>{/snippet}</SheetClose></SheetFooter></form></SheetContent></Sheet>Accessibility
The panel has role="dialog" and takes its name from SheetTitle, an h2. While it is open, focus stays inside it, the page behind is hidden from screen readers, and Escape closes it and returns focus to the trigger. Focus starts on the first focusable element inside, or on the panel itself when it was opened by touch, and SheetDescription is announced with the title. Give every sheet a title, hidden with sr-only when the design shows none.
- Enter
- When focus is on the trigger, opens the sheet.
- Space
- When focus is on the trigger, opens the sheet.
- Tab
- Moves focus to the next focusable element in the sheet, and from the last one back to the first.
- Shift+Tab
- Moves focus to the previous focusable element in the sheet, and from the first one to the last.
- EscEscape
- Closes the sheet and moves focus back to the trigger.
Demos
Side
Four buttons open the same edit profile sheet from the top, right, bottom and left, set with side on SheetContent, which defaults to right. Top and bottom sheets are capped at half the screen here, so the text scrolls between the header and the footer. Use a side for a form or an inspector beside a list, and the top or bottom for a short strip of options.
No close button
Setting showCloseButton to false on SheetContent takes the corner X away. This sheet has nothing else to press, so its description tells people to click outside, and Escape closes it too. In a real sheet, hide the X only when the footer has its own Close or Done button.
RTL
The edit profile form in Arabic, inside a Direction provider set to right to left, with side set to left on SheetContent. side names a physical edge, so it stays on the left. The sheet renders in a portal that keeps the provider's direction, so the title, labels, fields and buttons follow it, and the corner X moves to the left, where an Arabic line ends.
FAQ
When should I use a Sheet instead of a Dialog or a Drawer?
Use a Sheet when the task needs the full height of the screen and sits next to what it changes: filters beside a product grid, a cart, an edit form for a row in a table. It slides in from an edge and keeps part of the page in view.
A Dialog suits a short task in the middle of the screen. A Drawer follows a swipe and can stop at snap points, which is what phone users expect from a bottom panel.
How do I open a Sheet from the left, top or bottom?
Set side on SheetContent to left, top or bottom. The default is right. Left and right sheets run the full height of the screen, and top and bottom ones the full width, as tall as their content.
The value is a physical edge, so left stays on the left in a right-to-left page. The Side demo opens one from each edge.
How do I open and close a Sheet from code in Svelte?
Hold the open state yourself: pass open to Sheet and update it in onOpenChange, which receives the new boolean first.
Then a row's Edit button, a keyboard shortcut or a route change can open it, and your code can close it after a save.
How do I submit a form in a Sheet and close it after saving?
Put the <form> inside SheetContent, around the fields and SheetFooter. The panel renders in a portal at the end of the page, so a form wrapped around the whole sheet doesn't contain its inputs, and the submit button in the footer does nothing.
Hold the open state yourself, and set it to closed in the submit handler once the save succeeds, so a failed save leaves the form open with its error. Keep the save off SheetClose, which closes the sheet before the request finishes.
How do I make a Sheet wider?
Left and right sheets take three quarters of the screen's width and stop at max-w-sm from the sm breakpoint up. That cap is written with a data-[side=right]: or data-[side=left]: prefix, so a plain sm:max-w-lg on the sheet loses to it. Repeat the prefix instead, as in data-[side=right]:sm:max-w-lg.
To widen every sheet, change the cap in your copy of the component. Below the sm breakpoint the width stays at three quarters, which leaves a strip of the page to tap to close it. Set variant to inset on SheetContent if the panel should float with a gap from the screen's edges, which it does from the sm breakpoint up.
How do I hide the close button in the corner of a Sheet?
Set showCloseButton to false on SheetContent, as in the No close button demo. Only the button goes: Escape and a click outside still close the sheet.
Put a SheetClose in the footer, labeled Close, Cancel or Done, so touch and screen reader users have something to press.
Does a Sheet need a SheetTitle?
Yes. SheetTitle names the panel, and a screen reader announces that name when focus moves in. Without it, UI SDK falls back to the label of the button that opened it, which rarely says what the panel holds.
When the design has no visible heading, keep SheetTitle and add the sr-only class to it. SheetDescription is optional, a line on what the panel is for.
How do I make a long Sheet scroll and keep its footer in view?
Keep SheetHeader and SheetFooter outside the part that scrolls, and let the middle take the rest of the height and scroll. SheetBody does that, as in the Side demo: it fills the space between the two with a scroll area, and scrollFade fades the text at its edges.
Top and bottom sheets grow with their content, so give them a maximum height too, as the demo does with half the screen.
API Reference
Sheet
open?boolean
Whether the dialog is open. Pass it to control the dialog. Two-way with bind:open.
defaultOpen?boolean
Whether the dialog starts open, when uncontrolled. Focus moves into it once it's on the page.
- Default
false
onOpenChange?(open: boolean, details: DialogOpenChangeDetails) → void
Runs when the dialog wants to open or close. details.reason says why, details.cancel() stops it, and details.returnValue carries what closed it.
- Type
(open: boolean, details: DialogOpenChangeDetails) → void- Parameters
open– booleandetails– DialogOpenChangeDetails- Returns
void
closeOnOutsidePress?boolean
Whether pressing outside the dialog, like on its backdrop, closes it. The press counts once it's released outside too, so dragging a text selection out of a field doesn't close it.
- Default
true, or false when `modal` is false
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- Type
DocumentFragment | Element | null
controller?PopupController<any, DialogOpenChangeReason, {}, any, DialogPayloadChangeReason>
Opens, closes and inspects the dialog from anywhere, and connects triggers outside it. Create one with createDialogController().
- Type
PopupController<any, DialogOpenChangeReason, {}, any, DialogPayloadChangeReason>
debug?boolean
Logs every state change with its reason to the console, in development builds.
disablePointerDismissal?boolean
The other bases' name for closeOnOutsidePress={false}.
dismissible?boolean
Whether Escape, an outside press and Android's back gesture can close the dialog. Close parts, triggers and the controller always can. Pass false while a form has unsaved changes, and ask in onDismissAttempt.
- Default
true
modal?"trap-focus" | boolean
true: the rest of the page is inert and doesn't scroll, focus is trapped, and an outside press only closes the dialog. "trap-focus": traps focus, and leaves the page scrollable and clickable. false: a dialog beside the page, which Tab can leave and outside presses don't close.
- Type
"trap-focus" | boolean- Default
true
onDismissAttempt?(details: DialogDismissAttemptDetails) → void
Runs when a dismissal was refused, because dismissible is false, an outside press doesn't close it, or a Close part's action is running. Ask "Discard changes?" here.
- Type
(details: DialogDismissAttemptDetails) → void- Parameters
details– DialogDismissAttemptDetails- Returns
void
onOpenChangeComplete?(open: boolean) → void
Runs once the dialog has finished opening or closing, after any animation.
- Parameters
open– boolean- Returns
void
onPayloadChange?(payload: unknown, details: ChangeDetails<DialogPayloadChangeReason>) → void
Runs when the payload the content shows changes: a trigger with another payload opens the dialog, or takes a non-modal dialog over while it's open, which fires no onOpenChange, and so does a controller's open({ payload }) on the open dialog. details.cancel() keeps the previous payload.
- Type
(payload: unknown, details: ChangeDetails<DialogPayloadChangeReason>) → void- Parameters
payload– unknowndetails– ChangeDetails<DialogPayloadChangeReason>- Returns
void
pendingAnnouncement?string
What screen readers hear once a Close part's action has been running for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
- Default
"Loading"
persistentElements?(string | Element)[] | (() → Element[])
Elements that stay usable while the dialog makes the page inert, like a chat launcher or a password manager's button. Elements, CSS selectors, or a function that returns elements, read when the dialog opens. Presses on them never close it.
- Type
(string | Element)[] | (() → Element[])- Parameters
string | Element)[] | ((- Returns
Element[])
presentation?PresentationSetting<"dialog">
How the dialog presents. "sheet" slides it up from the bottom of the screen, where it can be swiped away, and "auto" does that on small touch screens. Decided each time it opens; the server renders "dialog" for "auto".
- Type
PresentationSetting<"dialog">- Default
"dialog"
SheetTrigger
<button> data-slot="dialog-trigger"
controller?PopupController<any, DialogOpenChangeReason, {}, any, DialogPayloadChangeReason>
Connects a trigger outside the dialog, like one per table row, to the dialog with this controller.
- Type
PopupController<any, DialogOpenChangeReason, {}, any, DialogPayloadChangeReason>
disabled?boolean
Stops the trigger from opening the dialog. A native button can't be focused or pressed, unless focusableWhenDisabled is set.
- Default
false
focusableWhenDisabled?boolean
Keeps a disabled trigger in the tab order with aria-disabled instead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.
- Default
false
payload?unknown
Data for the content to render when this trigger opens the dialog, like the row it belongs to.
shortcut?string
A keyboard shortcut that presses the trigger, like "mod+k". mod is Command on Apple platforms and Control elsewhere. Sets aria-keyshortcuts, and a Shortcut part inside shows it. A modal dialog pauses the page's shortcuts while it's open.
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
data-closed?string
Present while the dialog is closed, including while it animates out.
data-disabled?string
Present when the trigger is disabled.
data-open?string
Present while the dialog is open. On a trigger, while it's open from that trigger.
SheetClose
<button> data-slot="dialog-close"
action?(event: Event, details: ActionDetails) → unknown
Runs when the part is pressed, before the dialog closes. A returned Promise keeps the dialog open while it runs: the part gets data-pending, aria-busy and aria-disabled, screen readers hear the dialog's pendingAnnouncement after a second, and nothing but the controller closes the dialog. It closes with reason "action" once the Promise resolves. A rejection keeps it open and puts the reason in the part's error state until the next press, or until the dialog opens again. details.source says how the part was pressed, for changes made after an await.
- Type
(event: Event, details: ActionDetails) → unknown- Parameters
event– Eventdetails– ActionDetails- Returns
unknown
value?string
Reported as returnValue in onOpenChange and by the controller's open(). createConfirm() resolves true for "confirm".
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
data-disabled?stringdata-pending?string
Present on a Close part while its action runs.
SheetPortal
SheetOverlay
<div> data-slot="dialog-backdrop"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-closed?string
Present while the dialog is closed, including while it animates out.
data-ending-style?string
Present while the dialog animates out. Style the state you animate to.
data-open?string
Present while the dialog is open. On a trigger, while it's open from that trigger.
data-starting-style?string
Present for the first frame. Style the state you animate from.
SheetContent
<div> data-slot="dialog-content"
container?DocumentFragment | Element | null
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- Type
DocumentFragment | Element | null
finalFocus?PopupFocusTarget
Where focus goes when the dialog closes while focus is inside it.
- Default
"trigger"
initialFocus?DialogInitialFocus
Where focus goes when the dialog opens. Opening with touch focuses the dialog itself, so no on-screen keyboard appears, unless this is set to something other than "auto".
- Default
"auto"
inline?boolean
Renders the dialog and its backdrop where they are in the page instead of above it, so it can stay inside a frame, like an app preview. Pair it with modal="trap-focus" to keep the rest of the page usable. A container on the dialog still moves its backdrop, so leave it off.
- Default
false
keepMounted?boolean
Whether the dialog stays in the page, hidden, while closed. Its content keeps its state between opens.
- Default
false
showCloseButton?boolean
Show close button at the top right corner.
- Default
true
side?"top" | "right" | "bottom" | "left"
Edge of the screen where the sheet appears.
- Type
"top" | "right" | "bottom" | "left"- Default
"right"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
data-closed?string
Present while the dialog is closed, including while it animates out.
data-ending-style?string
Present while the dialog animates out. Style the state you animate to.
data-keyboard?string
Present while the on-screen keyboard covers part of the page.
data-open?string
Present while the dialog is open. On a trigger, while it's open from that trigger.
data-presentation"dialog" | "sheet"
How the dialog presents this time it's open.
- Type
"dialog" | "sheet"
data-side?string
Mirrors side.
data-starting-style?string
Present for the first frame. Style the state you animate from.
--dialog-stackstring
How many dialogs are open above this one, nested inside it. 0 for the topmost.
--drawer-dimstring
While it presents as a sheet: how dim the page behind is, from 0 to 1. The backdrop's opacity follows it.
--drawer-expandstring
While it presents as a sheet: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.
--drawer-progressstring
While it presents as a sheet: how far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.
--drawer-stackstring
While it presents as a sheet: how many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.
--keyboard-insetstring
Unless it presents as a sheet: how many pixels of the page the on-screen keyboard covers, 0 without one.
--sheet-backdropstring
Set it yourself: the color the page dims to while it presents as a sheet. Black at 0.2 by default.
--visual-viewport-heightstring
Unless it presents as a sheet: the height of the part of the page you can see, above the keyboard.
--visual-viewport-topstring
Unless it presents as a sheet: how far the part of the page you can see is scrolled from the top of the layout, as when the keyboard pushes it up.
--visual-viewport-widthstring
Unless it presents as a sheet: the width of the part of the page you can see.
SheetHeader
<div> data-slot="sheet-header"
description?string
The description of the sheet.
title?string
The title of the sheet.
class?string
Merged with the part's classes.
SheetFooter
<div> data-slot="sheet-footer"
class?string
Merged with the part's classes.
SheetTitle
<h2> data-slot="dialog-title"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.
SheetDescription
<p> data-slot="dialog-description"
render?Snippet<[{ props, state, children }]>
Renders your own element: a snippet that gets the part's props to spread on it, its state, and children, its content.
- Type
Snippet<[{ props, state, children }]>
class?string
Merged with the part's classes.












