Interactive HTML5 Elements and Global Attributes: details, summary, dialog, template, data-*, hidden, contenteditable and More

HTML5 and CSS3 50 min min read Updated: Nov 17, 2026 Intermediate
Interactive HTML5 Elements and Global Attributes: details, summary, dialog, template, data-*, hidden, contenteditable and More
Intermediate Topic 2 of 3

details and summary: An Accordion

html <details> <summary>What is your refund policy?</summary> <p>You can ask for a refund within 30 days.</p> </details> <details open> <summary>Do you ship worldwide?</summary> <p>Yes, to most countries.</p> </details>

No JavaScript. The browser opens and closes it and the keyboard works. Add open to start opened.

dialog: A Popup Window

html <button id="openBtn">Open help</button> <dialog id="helpDialog"> <h2>Help</h2> <p>Press Esc to close this window.</p> <form method="dialog"> <button>Close</button> </form> </dialog> <script> const dlg = document.getElementById("helpDialog"); document.getElementById("openBtn").addEventListener("click", () => dlg.showModal()); </script>
  • showModal() opens it above the page and traps focus inside
  • Esc closes it
  • A form with method="dialog" closes the dialog when its button is pressed
  • Style the dim background with dialog::backdrop

template: Hidden Markup to Copy

html <template id="card"> <article class="card"> <h3></h3> <p></p> </article> </template> <div id="list"></div> <script> const tpl = document.getElementById("card"); const copy = tpl.content.cloneNode(true); copy.querySelector("h3").textContent = "New card"; copy.querySelector("p").textContent = "Made from a template."; document.getElementById("list").appendChild(copy); </script>

Content inside template is not shown until JavaScript copies it into the page.

Global Attributes

Global attributes can be used on almost any element.

AttributeUse
idUnique name. Also used for bookmarks
classReusable names for CSS
data-*Your own data, such as data-price="20", read with JavaScript
hiddenHide the element
contenteditableLet the user edit the text
draggableAllow drag and drop
tabindexControl keyboard focus order. Use 0 or -1 only
titleTooltip text, not reliable for important information
langLanguage of the element
translateMark text that should not be translated
html <button class="buy" data-product-id="42" data-price="20">Buy</button> <p contenteditable="true">Click and type here.</p> <p hidden>You cannot see me.</p>
tabindex Do not use a positive tabindex such as 5. It breaks the natural order. Prefer real buttons and links.

Practice

  1. Create an FAQ with three details blocks
  2. Open a dialog from a button and close it with the form
  3. Store a price in data-price and read it in the console

Conclusion

details, dialog and template give you accordions, popups and reusable markup with little code. Global attributes work on any element.

Quick Summary: details; dialog; template; global attributes.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators