How do you make a modal fit within a mobile viewport?

Size a mobile modal within the dynamic viewport and let its content scroll inside a bounded region. Keep the title and close control reachable, and avoid a fixed pixel height. The modal must remain usable when browser controls, the keyboard or enlarged text reduce visible space.
.modal {
max-inline-size: min(40rem, calc(100% – 2rem));
max-block-size: calc(100dvh – 2rem);
display: grid;
grid-template-rows: auto minmax(0, 1fr) auto;
}
.modal__body { overflow: auto; }
Use safe-area padding for edge-to-edge dialogs and let the body row shrink with minmax(0, 1fr). The header and action row can remain visible while the body scrolls, but they should not consume most of a short landscape screen.
Manage keyboard focus as a modal dialog: move focus inside, keep background content inert, support Escape and return focus on close. When the keyboard opens, scroll the active field and its error into view. Avoid nested scrollers inside the modal body where possible.
Test small portrait and landscape phones, 200 percent zoom, long content and validation. The close control must never sit behind a notch or browser UI. A full-screen sheet may work better than a centered box for complex mobile forms, provided it keeps the same dialog semantics. Test the finished component with keyboard focus, touch input and a resized desktop window. Responsive geometry works only when controls stay reachable and the visual sequence matches the document order. Verify the behavior across the full width range, including spaces between design breakpoints. Long labels, translated copy and enlarged text can expose constraints that short sample content never reaches.