- Components
- Base
- Dialog
Shadcn Dialog Components
A modal window for forms and focused tasks layered over the page, with scrollable content, sticky header and footer, sign in, OTP, checkout, plan change, profile and onboarding examples. Built with shadcn/ui and compatible with Radix UI and Base UI. Browse our collection of 13 Shadcn Dialog variants.
Scrollable
Custom scrollbar
Sticky header
Sticky footer
Terms and conditions
Newsletter
Feedback
OTP code
Sign in
Checkout
Change plan
Edit profile
Onboarding
Unlock premium components
Explore Shadcn Blocks
Ready-made page sections built with the same components.
Shadcn Dialog Component
The Shadcn Dialog is a modal window that opens on top of the page for a focused task: signing in, editing a profile, entering a one time code, choosing a plan or paying. The rest of the page is dimmed and inert until the user finishes or closes the dialog.
The examples here cover long scrollable content with a native or custom scrollbar, sticky headers and footers, a terms dialog that unlocks its accept button only after scrolling, and ready forms for newsletter, feedback, sign in, OTP, checkout, plan changes, profile editing and onboarding. They are built on the Radix UI Dialog primitive, which has an equivalent in Base UI, and styled with shadcn/ui, React and Tailwind CSS.
What is the Shadcn Dialog Component?
A dialog is a window layered over the main content with role="dialog". While it is open, focus is trapped inside it, the page behind does not scroll, and the user can close it with the close button, the Escape key or a click on the overlay.
Use a dialog for tasks the user can freely abandon. When you need an explicit decision before a destructive action, use an Alert Dialog instead, which cannot be dismissed by clicking outside. For side panels use a Sheet, and on mobile a Drawer often feels more natural.
Anatomy of the Shadcn Dialog
| Part | Description |
|---|---|
| Dialog | The root. Holds the open state and accepts open, defaultOpen and onOpenChange. |
| DialogTrigger | The element that opens the dialog. Use asChild to render your own Button. |
| DialogContent | The modal panel. Renders the portal and overlay for you and shows a close button in the corner, which you can hide with showCloseButton={false}. |
| DialogHeader | Wraps the title and description and aligns them to the center on mobile and to the left on larger screens. |
| DialogTitle | The heading of the dialog. It is the accessible name announced when the dialog opens. |
| DialogDescription | A short explanation linked to the dialog for screen readers. |
| DialogFooter | Holds the actions. Buttons stack on mobile and sit in a row on larger screens. Pass showCloseButton to add a Close button. |
| DialogClose | Closes the dialog. Wrap any button with asChild to turn it into a cancel or done action. |
| DialogOverlay and DialogPortal | The dimmed backdrop and the portal container, already used inside DialogContent and exported for custom layouts. |
13 Shadcn Dialog Variants
Each dialog variant listed here is previewed live at the top of this page, together with its source code and install command.
- Scrollable content: Dialogs with long content using the native scrollbar, a custom Scroll Area, a sticky header or a sticky footer.
- Terms and conditions: A scrollable terms dialog that keeps the accept button disabled until the user has scrolled to the end.
- Newsletter and feedback: Short dialogs with an email subscription field or a feedback textarea and a single submit button.
- Sign in and OTP code: A sign in dialog with email, password, remember me and Google login, and a one time code dialog with separate digit slots.
- Plans and checkout: A change plan dialog with radio cards and feature lists, and a checkout dialog with billing options, card details and a coupon field.
- Edit profile and onboarding: A profile editor with cover image, avatar upload and form fields, and a multi step onboarding dialog with progress dots.
How to Install the Shadcn Dialog Component
Set up shadcn/ui in your project if you have not already, then add the Shadcn UI Kit registry to your components.json once:
{
"registries": {
"@shadcnuikit": "https://shadcnuikit.com/r/{name}.json"
}
}Then install a dialog variant by its name:
npx shadcn@latest add @shadcnuikit/dialog1The same command works with pnpm dlx, yarn dlx and bunx --bun. Each variant has a copy button for every package manager, and the code is added to your project as plain React and Tailwind CSS that you can edit freely.
How to Use the Shadcn Dialog Component
Wrap a trigger and the content in Dialog, give it a title and description, put the form in the body and the actions in DialogFooter. Use DialogClose for the cancel button.
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
export function EditName() {
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Edit name</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-sm">
<DialogHeader>
<DialogTitle>Edit name</DialogTitle>
<DialogDescription>
This is how your name appears to your team.
</DialogDescription>
</DialogHeader>
<div className="grid gap-2">
<Label htmlFor="name">Name</Label>
<Input id="name" defaultValue="Olivia Martin" />
</div>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
<Button type="submit">Save</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}Why Use the Shadcn Dialog Component
- Keeps users in context: Short tasks happen on top of the current page, so users do not lose their place.
- Accessible modal behavior: Focus trapping, scroll locking, Escape to close and ARIA labelling come from the primitive.
- Easy to dismiss: The close button, the overlay and the Escape key all close the dialog, which suits optional tasks.
- Works with any form: Inputs, selects, radio groups and OTP fields from the kit drop straight into the dialog body.
- Responsive layout: The header and footer adapt from stacked on mobile to aligned rows on desktop without extra code.
Common Dialog Use Cases
- Authentication: Sign in, sign up and one time code steps without leaving the page.
- Quick edits: Rename an item, edit a profile or change a setting in place.
- Billing: Choose a plan, enter card details and apply a coupon.
- Long content: Terms, release notes and policies with a scrollable body.
- Onboarding: Multi step introductions for new users and new features.
Customizing the Shadcn Dialog
Change the width with a class such as sm:max-w-lg on DialogContent. For long content, give the content a max height and let an inner element scroll, or wrap it in a Scroll Area for a styled scrollbar. Colors and radius come from your theme variables, and the free Theme Generator can create a matching palette.
To close the dialog after a form submits, control it with open and onOpenChange:
const [open, setOpen] = useState(false)
async function onSubmit(values: FormValues) {
await saveProfile(values)
setOpen(false)
}
<Dialog open={open} onOpenChange={setOpen}>
...
</Dialog>Dialog Accessibility and Keyboard Support
The dialog follows the WAI-ARIA dialog pattern. The content has role="dialog" and aria-modal, is labelled by DialogTitle and described by DialogDescription. Keep the title even when the design has no visible heading, and hide it with sr-only instead of removing it.
Focus moves into the dialog when it opens, stays inside while it is open and returns to the trigger when it closes.
| Key | Action |
|---|---|
| Space | Opens the dialog when the trigger has focus. |
| Enter | Opens the dialog when the trigger has focus. |
| Tab | Moves focus to the next focusable element inside the dialog. |
| ShiftTab | Moves focus to the previous focusable element inside the dialog. |
| Escape | Closes the dialog and returns focus to the trigger. |
Dialog Best Practices
- Keep one task per dialog; move multi page flows to their own route.
- Always include a DialogTitle, even if it is visually hidden.
- Put the primary action last in the footer and label it with the result, such as Save changes.
- Limit the height and scroll the body, not the whole page, when content is long.
- Use an Alert Dialog instead when the user must confirm a destructive action.
Shadcn Dialog for AI Agents
An agent can turn any focused task into a Dialog wired to your data: a sign in form that closes after a successful request, an edit profile dialog that pre-fills from the current user, or a scrollable terms dialog that enables Accept only after the user reaches the end. It controls open and onOpenChange from your state so the dialog closes only when the work is done.
Install it with an AI agent
Claude Code, Cursor, Codex and other agents can install these with the shadcn CLI, for example npx shadcn@latest add @shadcnuikit/dialog1. With the Shadcn UI Kit MCP server, your agent can search every variant by name and add the right one for you. To give it full context, share /components/dialog.md, the Markdown version of this page with every variant and install command.
Example prompts
- “Move the invite member form into a Dialog that closes and shows a toast after the invite is sent.”
- “Add a scrollable changelog Dialog with a sticky header and a Done button in a sticky footer.”
- “Open an edit profile Dialog from the account menu, pre-filled with the current user's name and avatar.”
Customize it with AI
Ask the agent to keep DialogTitle and DialogDescription, hiding them with sr-only if the design has no visible heading, because they give the dialog its accessible name. For confirmations of destructive actions, ask for an Alert Dialog instead, since a Dialog can be dismissed by clicking outside.
Components Related to Dialog
Shadcn Dialog FAQ
npx shadcn@latest add @shadcnuikit/dialog1. With a Pro plan, the Shadcn UI Kit MCP server can also build complete sections and pages around it.Looking for something else? Browse all shadcn/ui components or ready-made UI blocks built with them.















