Some interactive widgets are built right into HTML. <details> gives you an expandable section, <dialog> gives you a proper pop-up window, and <progress> and <meter> draw bars. All of them work with the keyboard and screen readers without any extra effort.
Developers used to build these widgets from <div> elements and a lot of JavaScript, and the results were often hard to use with a keyboard. Using the native elements means less code to write, fewer bugs and better accessibility. It's a good example of why it pays to know what HTML can already do before reaching for JavaScript.
details and summary: accordions without JavaScript
<details>
<summary>What's in the box?</summary>
<p>A charger, a cable and a sticker.</p>
</details><summary>is the heading that is always visible. Clicking it opens and closes the section.- Everything else inside
<details>is hidden until the section is opened. - Add the
openattribute to start with the section expanded. - Give several
<details>elements the samenameand only one can be open at a time, creating an exclusive accordion.
This pattern suits FAQs, "show more" sections and long lists of settings, where most visitors only need part of the content.
dialog: native pop-up windows
<dialog> creates a pop-up box. To open it as a modal, which dims the rest of the page and keeps keyboard focus inside the box, you need one line of JavaScript:
document.querySelector('dialog').showModal();A <form method="dialog"> inside the dialog closes it when submitted, and pressing Esc closes it automatically.
Use dialogs for things that need an answer before the visitor carries on, such as "Delete this file?". For information that can wait, a message on the page is less disruptive.
progress and meter bars
<progress value="70" max="100">shows how far a task has got, such as an upload or the steps of a checkout.<meter value="0.8">shows a measurement within a known range, such as disk space used or password strength. With thelow,highandoptimumattributes it can change colour to signal a good or bad value.
Both elements are understood by screen readers, which announce the value as a percentage or a number.
HTML Interactive Elements Syntax
Interactive elements
<details><summary>Question</summary> Answer </details>
<dialog id="d"> … </dialog>
<progress value="3" max="10"></progress>
<meter value="0.6" min="0" max="1"></meter>HTML Interactive Elements Summary
<details>and<summary>create expandable sections without JavaScript.- Sharing a
namebetween<details>elements makes an exclusive accordion. <dialog>creates a pop-up;showModal()opens it as a modal.<progress>shows task progress and<meter>shows a value within a range.- Native elements are more accessible than widgets built from
<div>elements.
HTML Interactive Elements Examples
Each example runs in the page. Edit the code and press Run to see what changes.
An FAQ accordion
Click the questions. The name attribute makes it exclusive: opening one closes the others.
<h3>FAQ</h3>
<details name="faq" open>
<summary>Do you deliver on weekends?</summary>
<p>Yes! Saturday and Sunday, 9am to 1pm.</p>
</details>
<details name="faq">
<summary>Can I change my order?</summary>
<p>Up to two hours before delivery.</p>
</details>
<details name="faq">
<summary>Is the packaging recyclable?</summary>
<p>100%, including the tape.</p>
</details>Line-by-line explanation
- Line 2
openmakes the first question start expanded. - Line 3The summary is the clickable label.
- Lines 6 to 9Every
<details>sharesname="faq", which groups them into an exclusive accordion.
A modal dialog
<button type="button" id="open">Delete photo</button>
<dialog id="confirm">
<h3>Delete this photo?</h3>
<p>This can't be undone.</p>
<form method="dialog">
<button value="cancel">Cancel</button>
<button value="delete">Delete</button>
</form>
</dialog>
<p id="result"></p>
<script>
const dialog = document.getElementById("confirm");
document.getElementById("open").addEventListener("click", () => dialog.showModal());
dialog.addEventListener("close", () => {
document.getElementById("result").textContent = "You chose: " + dialog.returnValue;
});
</script>Line-by-line explanation
- Lines 3 to 10The dialog is hidden until opened.
- Lines 6 to 9A
method="dialog"form closes the dialog; the clicked button'svaluebecomesreturnValue. - Line 16
showModal()opens it as a modal and dims the page behind. - Lines 17 to 19When it closes, we show which button was chosen.
Progress and meter
<p>Course progress: <progress value="7" max="12">7 of 12</progress> 7 / 12 lessons</p>
<p>Storage used: <meter value="0.92" low="0.5" high="0.8" optimum="0.2">92%</meter> 92%</p>
<p>Password strength: <meter value="0.3" low="0.4" high="0.7" optimum="1">weak</meter> weak</p>Line-by-line explanation
- Line 1
<progress>shows completion of a task. - Line 2The meter turns warning-coloured because 0.92 is above
highand far fromoptimum. - Line 3A low value when the optimum is high also shows as poor.
Common HTML Interactive Elements Mistakes
Building an accordion with divs
<div class="q" onclick="toggle()">Question</div>
<div class="a" style="display:none">Answer</div><details>
<summary>Question</summary>
<p>Answer</p>
</details>The native version works with the keyboard, is announced properly and needs no JavaScript.
Using show() when you want a modal
<script> dialog.show(); </script><script> dialog.showModal(); </script>show() opens a non-modal dialog. The rest of the page stays clickable and Esc doesn't close it.
HTML Interactive Elements in Real Projects
Native widgets are winning
For years, every site used heavy JavaScript libraries for accordions and modals. Today, <details> and <dialog> handle focus, keyboard support and accessibility for you. Many design systems now build their components on top of these native elements.
HTML Interactive Elements Exercises
Answer each one and check it instantly. If you get stuck, open the hint before the answer.
Complete the accordion.
<>
<>Shipping info</summary>
<p>Free over £30.</p>
</details>
<details> wraps the widget; <summary> is the visible label.How do you make a <details> start expanded?
open attribute expands it.Which method opens a dialog as a modal?
showModal() dims the page, traps focus and enables Esc to close.The progress bar should show 3 out of 5 steps, and the FAQ answer should be hidden behind a clickable summary. Fix both.
<progress value="3"></progress>
<details>
<p>Where are you based?</p>
<p>Glasgow, Scotland.</p>
</details>- progress max is 5
- details has a summary with the question
HTML Interactive Elements Quiz
3 questions to check what you learned.
Which element is the clickable heading of a
<details>element?<legend><caption><title><summary>
What does
<form method="dialog">do inside a dialog?- Sends data to the server
- Opens another dialog
- Nothing
- Closes the dialog and sets its returnValue
Which element is best for "disk 90% full"?
<progress><range><meter><bar>
HTML Interactive Elements Challenge
Build a two-question FAQ
Create two <details> elements that:
- Both share
name="help" - Each have a
<summary>question and a<p>answer - The first one starts open
- Two details named "help"
- Each has a summary and a paragraph
- Only the first starts open