Today I Learned

How to Modal

July 31, 2021

modal 1

This guide will help you build a modal properly.

This was shared in WeBuild - a popular dev community in Vietnam.

Focus trap

modal 2

The focus trap should follow the figure’s order.

Accessible dismissal

modal 3

Clicking on the modal background (which should usually cover the whole page) or pressing Escape should close the modal.

Guard against accidental dismissal

modal 4

When the form is filled, require explicit cancelation or submission to prevent users from losing progress or forgetting to submit.

Sticky header & footer

modal 5

In a long modal, make the header and the footer sticky so that users can see the control buttons without scrolling.

Filterable lists

modal 6

  • Make long lists filterable
  • Should have a button to clear the filter
  • Set min-height to prevent layout shift when filtering

© 2025 - Written by Vuong Vu. Connect with me on LinkedIn.