Faragiri
English

Choose a language 2

Learn Modals and overlays Components

A Lille car park app where an are you sure was dismissed in a second and a half, and a fifteen second undo removed a second service fee.

6Sections
4Min read
4Depth

Recommended Before This

0 / 2

One question: can anything else happen until this is dealt with. If anything else can happen, it is not a modal, and the four things that get built as modals instead are all cheaper and all less rude.

Camille is auditing the car park app in Lille. Four dialogues interrupt the person during a normal stay, and exactly one of them survives the question.

The four things a modal usually should have been

Four alternatives: an inline panel, a side sheet, a banner and an undo. Each covers a different reason a modal gets reached for.

Four dialogues, one stay

The only question, and what each answer costs

Three of this app's four dialogues took the left branch, and each had been built as a modal because a modal needs no route.

Can anything else happen until this is dealt with?
  • No
    It is not a modalthe person can carry on, so the interruption is a choice rather than a consequence of the state.
    • an inline panel, for content belonging to the thing on screen
    • a side sheet, when that content is long
    • a banner, for something to know rather than do
    • an undo, for anything already done
  • Yes
    A modal, with all five mechanicsthe session has expired and nothing on the page works until it is renewed, which is one dialogue in four.
    • focus trapped inside it
    • focus returned to whatever opened it
    • Escape closes it
    • the background marked inert
    • the page behind does not scroll

Two branches and no third. A dialogue that is neither, because it interrupts and can also be ignored, is the shape most confirmation dialogues actually have.

Modular Type Scale & CSS Flex/Grid Motion Lab

Test harmonic typography ratios and live Flexbox/Grid layouts with 1-click CSS export.

An inline panel is for content that belongs to the thing on screen: the filter options for a list belong beside the list, expand in place, and leave the results visible while they change. A side sheet is the same idea when the content is long: it slides in, it can be left open, and the page behind is still readable.

A banner is for something the person should know and does not have to act on now. And an undo is for something already done, which is the honest replacement for almost every confirmation dialogue.

On this app three of the four dialogues on the checkout were not modals. The cookie notice became a banner, the filters became a side sheet, and the confirmation before extending a stay became an undo. The session expiry is the one that survived, because nothing else could happen.

What a real modal owes

A modal traps focus, returns it on close, and marks the background inert. Those three are not accessibility extras, they are what makes a modal a modal: something the rest of the page cannot be used underneath.

Non-negotiable contract

Five behaviours required to lock the page, and one rule never to break

Focus containment and inertness are not optional polish; they define what separates a modal from a floating card.

What a real modal owes

  1. YesTrap keyboard focus inside the dialogueTabbing cannot leak out into obscured controlsYes
  2. YesReturn focus to the trigger on closeLeaves the reader where they startedYes
  3. YesMark the background page inertRemoves underlying controls from tab order and screen readersYes
  4. YesClose when Escape is pressedStandard exit path expected across platformsYes
  5. YesLock background page scrollPrevents the page behind from drifting out of place on phonesYes
  6. NoStack a second modal on top of the firstBreaks nested focus traps, Escape routing, and double focus returnNo

Missing even the scroll lock leaves phone users stranded somewhere else on the page after closing.

Then escape closes it, and the page behind does not scroll. The scroll one is the fault everybody has seen and nobody reports: a dialogue on a phone, and the page behind sliding away under it, so closing the dialogue leaves the person somewhere else.

Never stack a modal on a modal. The second one has to trap focus inside the first one's trap, Escape becomes ambiguous, and returning focus means returning it twice in the right order. Every implementation gets one of those wrong.

Two size rules

A modal that scrolls internally is a page in a box. If the content does not fit, the answer is a page with a route, a back button and a place in the structure, not a small window with its own scrollbar inside a page that also has one.

Viewport fit

Two size rules: never scroll inside a box, and fill small screens

A dialogue that overflows its frame or shrinks into a tiny rectangle on a phone has outgrown the modal pattern.

Broken modal boxFights scrolling and wastes thumb space
Platform-native fitRespects routes and screen edges
Content taller than the viewportNested scrollbar inside a floating boxDedicated page with its own URL and back button
390 px phone screenSmall centred box with hard-to-reach close iconFull-screen view with a clear back affordance

Internal scrollbars and tiny centred boxes make real tasks look like pop-up advertisements.

On a phone a modal is a full screen page with a way back. A small centred box on a 390 px screen wastes the edges, puts its close button where a thumb cannot reach, and looks like an advertisement. Full screen with a clear back affordance is the same interruption expressed in the platform's own vocabulary.

What to open

The HTML dialog element is the tool, part of the language and in every current browser since 2022. Called with showModal it gives the focus trap, the Escape key, the backdrop and the top layer without a line of script, and it replaces a div with a z-index and four hand written behaviours, three of which are usually incomplete.

What to open in the browser

The HTML dialog element and the inert attribute work as a pair

Two built-in browser features since 2022 and 2023 replace custom z-index overlays and manual aria-hidden sweeps.

  • HTML dialog with showModal
  • HTML inert attribute
  • HTML dialog with showModalAvailable since 2022; supplies focus trap, Escape key, backdrop, and top layer automatically
  • HTML inert attributeAvailable since 2023; removes the background subtree from tab order and accessibility tree in one word

Using both together removes the custom focus scripts and cleanup bugs that hand-rolled div overlays accumulate.

The inert attribute covers what dialog does not, part of the language and in every current browser since 2023. It removes a subtree from the tab order and from the accessibility tree in one word, and it replaces sweeping aria-hidden and tabindex over everything behind the dialogue and remembering to undo it.

Where it stalls: a modal needs no route

A modal needs no route, no back button and no place in the structure, which is why it is where new things go. Adding a page means a URL, a title, a position in the navigation, a decision about what links to it and what it links back to. Adding a modal means adding a component.

Why teams overuse modals

Adding a page demands architecture; adding a modal takes one component

Features land inside modals not because users need an interruption, but because a modal skips routing and navigation.

  • Adding a proper pageRequires information architecture
    • Assign a URL and route
    • Write a page title
    • Place it in navigation
    • Wire inbound and back links
  • Dumping into a modalZero architectural review
    • Drop in a component
    • Skip URLs and nav placement
    • Stuff in eight-field forms
    • Accumulate tables and inner tabs

Implementation effort

Any modal holding an eight-field form, a data table, or its own tabs is an unrouted page.

So features arrive as modals, not because they interrupt but because a modal is the only place to put something without asking anybody about the information architecture. Over two years the product accumulates a set of interruptions that were each an implementation shortcut.

The tell is the content. A modal containing a form of eight fields, a modal containing a table, a modal with its own tabs: each of those is a page that was added without a conversation.

What it looks like when it goes wrong

The app asked are you sure before extending a stay, with a confirming button and a cancel. It was dismissed in a median of about a second and a half, which is a reflex rather than a reading, and people regularly confirmed an extension of one hour when they had meant two. Extending again charged the service fee a second time, and the app's support inbox recorded it as customers misunderstanding the pricing. Replacing the dialogue with an immediate extension and a fifteen second undo removed the second fee entirely, because the mistake was now visible rather than pre-empted.

Reflex beats confirmation

How a confirmation dialogue caused double fees, and how an undo fixed it

Drivers dismissed the confirmation in about a second and a half, confirming the wrong duration before noticing.

Making the result immediately visible with a fifteen-second undo stopped mistakes before the second charge happened.

Whether an action needs a dialogue at all, and when an undo is the better answer, is hierarchy, states and what a button promises. The three mechanics that make a modal a modal are all about a route through the page, which is focus order, and never trapping it. And a modal is the top of an elevation model whose other levels have to mean something too, which is elevation that means something. How an interruption is held as a component rather than as a screen is one level up, in the parts an interface is assembled from.

Alongside this

Above this