brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: the details element gives you an accordion without JavaScript

Web-Development
~/tips/html-details

cat ~/tips/html-details.md

Makes a click-to-expand block in plain HTML, with no JavaScript.

Hiding a block of text behind a click does not need a script or a library. HTML has an element for it, and it works with the keyboard and screen readers.

<details>
  <summary>Show the full command</summary>
  <p>Hidden until someone clicks.</p>
</details>

The summary is the clickable line. Add the open attribute to start with the block expanded. In recent browsers you can give several details elements the same name attribute, and then opening one closes the others, which makes it an accordion.

Caveat: text inside a closed details is not shown, and browser support for the name grouping is newer than for the element itself. Check it if you need older browsers.

Further reading: MDN: details

More Web-Development tips ab -n 200 -c 10 https://example.com/ console.assert(items.length > 0, 'cart is empty', items) document.designMode = "on" function save(item) { Save draft All Web-Development tips (67) All topics

Link