Loading...

HTML essentialsAdvanced

Modern HTML: popover, inert & new features

5 min lesson

Next
  • Modern HTML adds built-in features that used to require JavaScript, like popovers and inert sections.
  • The popover attribute makes an element open and close as a top-layer box with a built-in light dismiss.
  • The inert attribute disables a whole part of the page: clicks, focus and screen reader access are blocked.
  • Think of popover as a sticky note that floats above the page, and inert as a transparent wall that stops interaction.
  • These features reduce code, improve accessibility and work well with CSS.
  • This builds on Template, slot & custom elements: you now have built-in controls instead of writing your own widgets.
  • The example has a popover toggled by a button and an inert area; you will see the popover open and the inert area not receive focus.
  • Next, HTML security: CSP, sandbox & rel=noopener keeps these features safe.
Keep in mind
  • Use the popover attribute instead of building your own floating box.
  • Combine popover with popovertarget on the toggle button.
  • Use inert on background areas when a modal is open.
  • These attributes need a recent browser; check support before relying on them.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Modern HTML</title>
</head>
<body>
  <!-- A button that toggles the popover below -->
  <button popovertarget="tip">Show tip</button>

  <!-- The popover opens on the top layer and closes on outside click -->
  <div id="tip" popover>
    This is a popover. Click outside to close.
  </div>

  <!-- An inert area that cannot be clicked or focused -->
  <div inert>
    <p>This area is inert.</p>
    <button>You cannot click me</button>
  </div>
</body>
</html>

What happens: A page with a "Show tip" button that opens a popover saying "This is a popover. Click outside to close." and an inert area showing "This area is inert." and a disabled-looking "You cannot click me" button that cannot receive focus.

Breaking it down

popover attribute

<div popover>...</div>

Marks the element as a popover. It is hidden by default and shown on top of the page.

popovertarget

<button popovertarget="tip">

Connects a button to a popover by id. Clicking toggles it without any JavaScript.

inert

<div inert>...</div>

Blocks all interaction inside. Nothing can be focused, clicked or reached by screen readers.

Modern attributes

AttributeEffect
popoverMakes an element a top-layer popover
popovertargetToggle a popover from a button
inertBlocks all interaction in a subtree
hiddenHides an element completely
autofocusFocuses a field on load (use carefully)

A helpful analogy

A popover is like a sticky note stuck on top of your paper: it floats above and falls off when you tap elsewhere. An inert section is a display case with a glass front: you can see it but you cannot touch anything inside.

Nesting rules

  • 1.Only one popover is visible at a time by default; use popover="manual" when you need more.
  • 2.Never put a popover inside another popover; the nesting rules get confusing fast.

Common mistakes

Using inert instead of hidden

Avoid

<div inert> when you want it gone

Use instead

<div hidden>

inert keeps the element visible but non-interactive. hidden removes it from view entirely.

Expecting popover to work in very old browsers

Avoid

Relying on popover without a fallback

Use instead

Provide a script fallback or check support first

popover and inert are recent. Without a fallback, older browsers show a broken widget.

Quick tips

  • •Press Esc while a popover is open; the browser closes it automatically.
  • •Use DevTools to toggle the inert attribute and see exactly what becomes non-interactive.
Previous
Next