Modern HTML: Built-In Features for Today's Web
Ten years ago, a pop-up window, a tooltip, or a reusable widget meant a JavaScript library, a pile of extra code, and a lot of accessibility bugs. Today HTML itself can do much of this work. The browser handles focus, the Escape key, layering, and screen reader announcements, and you write a few lines of markup.
This section shows you those features: what each one does, how to use it safely, and what to do for visitors whose browsers do not have it yet.
What You Will Learnβ
- Why HTML is now a "living standard", and what that means for you
- How to tell whether a new feature is safe to use
- What
dialog,details,popover,inert,template,slot, native lazy loading, and web components are for - How to build on a solid base and add modern features on top
- How to check support in your own code
The Big Ideaβ
A rule of thumb for the modern web: if HTML or CSS can do it, let them. Built-in features are usually shorter, faster, and more accessible than a hand-written version. They are also tested by browser makers, on more devices than you will ever own.
- A Taste of It
- What Can Your Browser Do?
- Old Way or New Way?
<!-- A modal dialog, with focus handling and Escape built in -->
<button type="button" id="open">Open settings</button>
<dialog id="settings">
<h2>Settings</h2>
<form method="dialog">
<button>Close</button>
</form>
</dialog>
<!-- A show-and-hide section with no JavaScript -->
<details>
<summary>Delivery information</summary>
<p>Orders ship within two working days.</p>
</details>
<!-- A popover opened by a button, also with no JavaScript -->
<button type="button" popovertarget="tips">Tips</button>
<div id="tips" popover>Press Escape to close this.</div>
<script>
document.getElementById("open").addEventListener("click", function () {
document.getElementById("settings").showModal();
});
</script>
Checking your browser...
For each job people used to code by hand, pick the built-in feature that now helps.
HTML Is a Living Standardβ
You may have heard of HTML5. It was a big milestone, around 2014, but it was not the end of the story. Today, HTML is maintained as a living standard by an open group called the WHATWG, together with browser makers. There is no "HTML6" to wait for. Instead, the specification changes continuously, small features are added, and browsers ship them one by one.
That changes how you work:
- Features arrive at different times in different browsers. A feature can work in one browser this year and in another next year.
- "What version of HTML?" is the wrong question. The right one is "do my visitors' browsers support this feature?"
- Learning never finishes, but the base is stable. Elements you learned years ago still work.
The next lesson, The HTML Living Standard, explains how this works in practice and where to read the real specification.
Can I Use This Feature?β
Before you rely on any new feature, check support. A few reliable places are:
- MDN Web Docs. Each page has a browser compatibility table at the bottom.
- Baseline. A shared label from browser makers that tells you how widely a feature works. Newly available means it works in the latest versions of all the major browsers. Widely available means it has worked in all of them for at least about two and a half years, so it is safe for most sites.
- Can I use. A site that shows support by browser version and usage share.
Then decide what fits your visitors. A site for a tech-savvy audience on current phones can use newer features sooner. A site for people on older, shared, or low-cost devices should wait for wider support, or provide a fallback.
From Old Way to Modern Wayβ
| The job | The old way | The modern way | Lesson |
|---|---|---|---|
| A modal pop-up | A div, an overlay, a focus trap, many bugs | dialog with showModal() | Dialog |
| A show and hide section | A click handler and a class | details and summary | Details and Summary |
| A tooltip, menu, or card that opens on demand | A script, positioning code, click-outside handling | The popover attribute | Popover |
| A block of markup used many times | Strings and innerHTML | template | template |
| Content placed inside a component | Custom code to move nodes around | slot | slot |
| Blocking the background while a panel is open | Many tabindex and aria-hidden changes | The inert attribute | inert |
| Loading images and frames late | Scroll listeners and observers | loading="lazy" | Lazy Loading |
| A reusable custom tag | A framework, or copying and pasting | Custom elements and shadow DOM | Web Components in HTML |
Open the Old Way or New Way? tab and test yourself on this table.
What Is in This Sectionβ
ποΈ HTML Living Standard
Learn how HTML is specified and maintained today: the history from HTML 2.0 to the WHATWG Living Standard, how a feature becomes part of HTML, how the parser repairs broken markup, and how to read element definitions in the specification. Includes a live parser lab and a content-model quiz.
ποΈ Modern HTML Features
A guided tour of newer HTML features that deserve a place in your toolbox: the search element, inputmode and enterkeyhint, fetchpriority and decoding, hidden until-found, translate and spellcheck, and module scripts with import maps. Plus a simple method for judging whether a feature is ready for your visitors. Includes a feature-matching quiz and a readiness judge.
ποΈ Dialog
Go beyond the basics of the dialog element: the top layer, validating a form before it closes, closing rules (Escape, click outside, closedby, requestClose), focus return, scroll locking, optional animation, and how to choose between a dialog, a popover, and details. Includes a live rename dialog lab and a decision picker.
π οΈ details-summary
ποΈ inert
ποΈ lazy-loading
ποΈ popover
ποΈ slot
ποΈ template
ποΈ web-components-html
Progressive Enhancementβ
The most useful habit for modern HTML is progressive enhancement: build a page that works with plain, widely supported HTML, then add newer features on top. If a feature is missing, the visitor gets the simple version, not a broken page.
A good example is details, which works as a heading and its content even if nothing else is available. Another is a link that goes to a full page, which a script upgrades into a pop-up when dialog is supported.
<!-- Works everywhere: a normal link to a full settings page -->
<a href="/settings" id="settings-link">Settings</a>
// Enhance it only where dialog is supported
const link = document.getElementById("settings-link");
if (typeof HTMLDialogElement === "function") {
link.addEventListener("click", function (event) {
event.preventDefault();
// open a dialog with the settings form here
});
}
Detecting featuresβ
Check for the feature, not for the browser name. Browser names change, and visitors can disguise them. These are typical checks:
// Is the dialog element available?
const hasDialog = typeof HTMLDialogElement === "function";
// Is the popover attribute available?
const hasPopover = "popover" in HTMLElement.prototype;
// Does CSS understand a selector?
const hasPopoverOpen = CSS.supports("selector(:popover-open)");
The What Can Your Browser Do? tab above runs checks like these in your own browser. Compare the results with a friend's phone or an older device, if you can.
Using New Features Safelyβ
- Check support, on MDN or Baseline, and note the fallbacks.
- Start with a working base. Plain HTML first, features second.
- Test in more than one browser, and on a real phone, if you can.
- Use a polyfill only when you need it. A polyfill is a script that adds a missing feature. It adds weight, so weigh the cost.
- Check accessibility. Test with the keyboard alone, and with a screen reader if you can.
- Re-check from time to time. A feature that was not ready last year may be today.
Modern Does Not Mean Safeβ
Built-in features save work, but they do not remove the need for the habits in the HTML Security section:
templateand web components still need escaping when you put visitor text inside them. See XSS Basics.- A
dialogorpopoveris not a security boundary. It only changes what is shown. - Shadow DOM is an organising tool, not a way to hide anything from scripts or attackers.
- A new feature can have its own pitfalls, so read each lesson's security notes.
Accessibility at a Glanceβ
Built-in features come with keyboard and screen reader behaviour that you would otherwise have to rebuild:
dialogmoves focus into the dialog, keeps it there when opened withshowModal(), and closes with Escape.detailsandsummarycan be opened with the keyboard, and announce their state.popoverhandles light dismiss and the Escape key, andinertkeeps hidden areas out of reach.
Your job is to use them as intended: add a heading and a way to close, write clear labels, and test with the keyboard. The existing lessons on Dialog and Details in the Semantic HTML section introduce those elements. The lessons here go further, with a modern focus and different examples.
Global Audience Notesβ
- Browser versions vary. Many visitors use older phones, shared computers, or devices that no longer get updates. Fallbacks protect them.
- Data costs matter. A native feature usually costs fewer bytes than a library that does the same job.
- Languages and writing directions differ. Test dialogs, popovers, and components with long words and right-to-left text, and avoid fixed widths.
- Cultures differ in expectations. For example, a pop-up that blocks the page may be more irritating in some places than others. Use dialogs sparingly, and never trap people.
Common Mistakes to Avoidβ
- Using a new feature without checking support.
- Replacing a working base with a feature-only version, so older browsers see nothing.
- Detecting the browser name instead of the feature.
- Adding a polyfill by habit, and paying for code you do not need.
- Rebuilding by hand something HTML already does.
- Skipping the keyboard test.
- Treating
dialog,popover, or shadow DOM as security. - Not re-checking support as browsers improve.
- Copying code that mixes old and new patterns without understanding it.
- Using modals for everything.
Practice Timeβ
- Open the What Can Your Browser Do? tab. How many features does your browser support? Which, if any, are missing?
- Open the same page in a second browser, and compare.
- Complete the Old Way or New Way? matcher.
- Choose one feature from the table, and look it up on MDN. What does its browser compatibility table say?
- Write the feature check you would use for
inert. - Pick a page of yours, and find one thing built by hand that a modern feature could replace.
- Write one sentence about a fallback for that feature.
- Bonus: find the Baseline label for
popoveron MDN.
Quick Recapβ
Click a question to check your answer.
1. What does "living standard" mean?
HTML is no longer released in numbered versions. The specification is updated continuously, and browsers add features one by one.
2. How do you know a feature is safe to use?
Check browser support on MDN, Baseline, or Can I use, and think about which browsers your visitors really use.
3. What is progressive enhancement?
Building a page that works with plain, widely supported HTML, then adding newer features on top, so visitors without them still get a working page.
4. Why detect a feature instead of a browser?
Feature checks answer the question you care about, and they stay correct as browsers change. Browser names can be wrong or disguised.
5. Do modern features remove the need for security habits?
No. template, components, dialog, and popover still need escaping of visitor text, and none of them is a security boundary.
6. Why prefer a built-in feature to hand-written code?
It is usually shorter, faster, tested by browser makers, and brings keyboard and screen reader behaviour with it.
Key Takeawaysβ
- HTML is a living standard. Features arrive over time, and support varies by browser.
- Check support on MDN, Baseline, or Can I use, and think about your visitors.
- Let HTML do what it can: dialogs, disclosure, popovers, templates, slots, inert regions, lazy loading, and components.
- Build a working base first, then enhance it.
- Detect features, not browsers.
- Modern does not mean safe. Keep escaping, and keep testing with the keyboard.
Next up: The HTML Living Standard, where you will learn how HTML is specified, where to read it, and how a feature travels from an idea to your browser.