Back to components
ElementModalFree

Modal React component

An accessible modal dialog with a blurred backdrop, focus trap, Escape and backdrop close, scroll lock, focus restore, 3 sizes and scale, slide-up and fade animations.

About the Modal component

Modal is a dialog that opens over the page, dims and blurs everything behind it and keeps the focus inside until it closes. It has a title, a description, your content and an optional footer for buttons, plus a close button in the corner, and it opens with a scale, a slide up or a fade. Page scrolling is locked while it is open.

open and onOpenChange control it, or defaultOpen lets it manage itself. title, description, children and footer fill it, size picks sm, md or lg (380, 480 or 640px wide) and animation the opening motion. closeOnBackdrop and closeOnEscape decide whether a click outside or Escape closes it, showCloseButton toggles the corner button and blur the backdrop blur. It renders into document.body, or inside its nearest positioned parent with contained.

When to use it

Use Modal when an action needs the visitor's full attention before they carry on: confirming a delete, editing a record, signing in. It traps focus inside the dialog, locks page scroll and returns focus to the trigger when it closes.

For secondary content people want to glance at while keeping their context, a Drawer usually fits better.

Installation

Add the Modal component to your project with the shadcn CLI. It lands in components/modal.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add @reactframe/modal

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Related components

Popover
Free
Stepper
Free
Drawer
Free
Pagination
Free
Bottom Sheet
Free
SEO-ready
Breadcrumb
Free