Put the neighbourhood head’s TUTUP board on parts of the page with inert: the browser answers whether Bayu’s Tab still lands, Wulan’s click still hits, and…
Why it matters
Focus straying behind a dialog, into a closed drawer or into a form that is loading leaves keyboard and screen reader users lost. inert switches off focus, clicks, text selection and the accessibility tree at once for a whole subtree, and nothing inside can leak out of it.
The key idea
One attribute switches off focus, clicks and screen readers at once
Common mistakes
Using display:none to "switch off" what should stay visibledisplay:none removes it completely. inert makes it non-interactive yet still shown (dim it yourself with CSS if needed). Just right for a modal’s background.
Forgetting to remove inert Put inert on the background when the dialog opens, then forget to remove it on close: the page stays frozen (try the Forgot to remove inert example). Always add and remove in pairs, or use showModal(), which handles it.
Thinking inert is the same as disableddisabled is for form controls only and has a built-in style; a link inside fieldset disabled stays alive. inert works on any element, takes it out of the accessibility tree, and forces no style.
Try it in this playground
Put inert on .halaman (a chip or by typing) Beranda, Simpan and Cari turn red: Tab skips them. The TUTUP board hangs over them.
Click the board, then press Tab a few times Your Tab path jumps over everything inert, straight to the dialog.
Click a button in the inert part Nothing happens: the click goes through to the element behind.
Open the aria-hidden situation, then Tab Focus still lands on elements hidden from screen readers: Mr. Sugeng hears nothing.