A dialog that morphs out of its card through the native View Transitions API. The dialog itself is a native <dialog> opened by an invoker button, so it opens and closes even before hydration or without JavaScript. The script (about 1.7 kB, no libraries) only adds the morph. Closes with Escape, a click outside or the close button.
Browser Support
Limited availability8 featuresDetails
Feature
Baseline
Your browser
<dialog>
Displays the modal dialog
Your browser:
View transitions
Animates the change between views
Your browser:
Invoker commands
Controls the dialog with buttons
Your browser:
@starting-style
Animates the initial appearance
Your browser:
<dialog closedby>
Controls how the dialog closes
Your browser:
:has()
Locks page scrolling while open
Your browser:
::backdrop
Styles the dialog backdrop
Your browser:
transition-behavior
Animates the dialog closing
Your browser:
Preview
Click on the card to open the dialog with a morphing animation.
Installation
Usage
import {
MorphingDialog,
MorphingDialogTrigger,
MorphingDialogContainer,
MorphingDialogContent,
MorphingDialogImage,
MorphingDialogTitle,
MorphingDialogSubtitle,
MorphingDialogDescription,
MorphingDialogClose,
} from "@/components/ui/morphing-dialog"
export default function Example() {
return (
<MorphingDialog>
<MorphingDialogTrigger>
<MorphingDialogImage src="/image.jpg" alt="..." />
<MorphingDialogTitle>Title</MorphingDialogTitle>
<MorphingDialogSubtitle>Subtitle</MorphingDialogSubtitle>
</MorphingDialogTrigger>
<MorphingDialogContainer>
<MorphingDialogContent>
<MorphingDialogClose />
<MorphingDialogImage src="/image.jpg" alt="..." />
<MorphingDialogTitle>Title</MorphingDialogTitle>
<MorphingDialogSubtitle>Subtitle</MorphingDialogSubtitle>
<MorphingDialogDescription>
Full description here...
</MorphingDialogDescription>
</MorphingDialogContent>
</MorphingDialogContainer>
</MorphingDialog>
)
}Examples
Profile Card
Use with profile cards for a smooth expansion effect
Components
| Component | Description |
|---|---|
| MorphingDialog | Root component, manages state |
| MorphingDialogTrigger | Button that opens the dialog (commandfor + command="show-modal") |
| MorphingDialogContainer | Native <dialog> with a backdrop |
| MorphingDialogContent | Dialog content wrapper |
| MorphingDialogImage | Image (<img> with object-cover) |
| MorphingDialogTitle | Title (h2) |
| MorphingDialogSubtitle | Subtitle |
| MorphingDialogDescription | Description content |
| MorphingDialogClose | Close button (X icon) |
Features
- Native View Transitions API — no external animation libraries
- Click-outside to close — click backdrop to dismiss
- Escape key support — keyboard accessible
- Focus trap — native modal, the page behind is inert
- Body scroll lock — prevents background scrolling
- Progressive enhancement — opens without JavaScript, without the morph in older browsers
- Reduced motion support — respects
prefers-reduced-motion