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
Get full control of shadcn/ui components, blocks and instances, including future additions.

Explore Shadcn Blocks

Ready-made page sections built with the same components.

View all blocks

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

PartDescription
DialogThe root. Holds the open state and accepts open, defaultOpen and onOpenChange.
DialogTriggerThe element that opens the dialog. Use asChild to render your own Button.
DialogContentThe modal panel. Renders the portal and overlay for you and shows a close button in the corner, which you can hide with showCloseButton={false}.
DialogHeaderWraps the title and description and aligns them to the center on mobile and to the left on larger screens.
DialogTitleThe heading of the dialog. It is the accessible name announced when the dialog opens.
DialogDescriptionA short explanation linked to the dialog for screen readers.
DialogFooterHolds the actions. Buttons stack on mobile and sit in a row on larger screens. Pass showCloseButton to add a Close button.
DialogCloseCloses the dialog. Wrap any button with asChild to turn it into a cancel or done action.
DialogOverlay and DialogPortalThe 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/dialog1

The 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.

KeyAction
SpaceOpens the dialog when the trigger has focus.
EnterOpens the dialog when the trigger has focus.
TabMoves focus to the next focusable element inside the dialog.
ShiftTabMoves focus to the previous focusable element inside the dialog.
EscapeCloses 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

Dialog is for general content such as forms and can be closed by clicking outside, with the close button or with Escape. Alert Dialog is for confirmations that need a decision: it uses the alertdialog role, cannot be closed by clicking the overlay and focuses the Cancel button on open.

Pass showCloseButton={false} to DialogContent. Keep another way to close it, such as a Cancel button wrapped in DialogClose.

Give DialogContent a max height, such as max-h-[80vh], make it a flex column and let the body scroll with overflow-y-auto. Keep the header and footer outside the scrolling element so they stay visible.

Control the Dialog with open and onOpenChange, run your submit handler and call setOpen(false) when it succeeds.

Keep the open state in useState, pass it to Dialog with onOpenChange, and set it to true from any event, for example a keyboard shortcut or a menu item.

Yes. Claude Code, Cursor, Copilot and other assistants can add a dialog variant with the shadcn CLI or the shadcn MCP server, for example 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.

Open /components/dialog.md to get this page as Markdown, with every dialog variant, its description and install command. Paste the link or the text into your AI tool so it uses the real component code instead of guessing.

Looking for something else? Browse all shadcn/ui components or ready-made UI blocks built with them.