{"id":150,"date":"2026-03-06T15:00:57","date_gmt":"2026-03-06T15:00:57","guid":{"rendered":"https:\/\/madebymolly.uk\/journal\/?p=150"},"modified":"2026-03-06T15:21:28","modified_gmt":"2026-03-06T15:21:28","slug":"attention-to-details-how-to-use-htmls-native-dropdown-element","status":"publish","type":"post","link":"https:\/\/madebymolly.uk\/journal\/attention-to-details-how-to-use-htmls-native-dropdown-element\/","title":{"rendered":"attention to &lt;details>: how to use html&#8217;s native dropdown element"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">anatomy of the &lt;details&gt; element<\/h2>\n\n\n\n<p>The <code>&lt;details&gt;<\/code>  element has two parts: a <code>&lt;summary&gt;<\/code> and content.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>&lt;details&gt;\n       &lt;summary&gt;This is my summary!&lt;\/summary&gt;\n       &lt;p&gt;This is my secret hidden information!&lt;\/p&gt;\n&lt;\/details&gt;<\/code><\/code><\/pre>\n\n\n\n<p>The result looks like this:<\/p>\n\n\n\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<details>\n  <summary>This is my summary!<\/summary>\n  <p>This is my secret hidden information!<\/p>\n<\/details>\n<\/div>\n\n\n\n<p>This is exactly the foundation we need to create interactive dropdowns like FAQs, or organize information like on a Wikipedia page. The <code>&lt;summary&gt;<\/code> is the always-visible label that the user clicks to expand. Everything else inside <code>&lt;details&gt;<\/code> is the hidden content that appears on click. <\/p>\n\n\n\n<p>Use a <code>&lt;p&gt;<\/code> or <code>&lt;span&gt;<\/code> for content. Headings inside <code>&lt;details&gt;<\/code> should be avoided, but if you need to use one inside a <code>&lt;summary&gt;<\/code>, set it to <code>display: inline<\/code> to avoid spacing issues.<\/p>\n\n\n\n<p>Semantically, <code>&lt;details&gt;<\/code> should only be used to collapse information elegantly. It&#8217;s not a substitute for navigation menus, footnotes, or other elements that already have proper HTML equivalents.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">open vs. closed<\/h2>\n\n\n\n<p>By default, <code>&lt;details&gt;<\/code> loads as collapsed. However, we can adjust that, using the <code>open <\/code>attribute selector.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;details open&gt;\n       &lt;summary&gt;This is my summary!&lt;\/summary&gt;\n        &lt;p&gt;This information is NOT secret.&lt;\/p&gt;\n&lt;\/details&gt;<\/code><\/pre>\n\n\n\n<p>The result loads like this:<\/p>\n\n\n\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<details open>\n  <summary>This is my summary!<\/summary>\n  <p>This information is NOT secret.<\/p>\n<\/details>\n<\/div>\n\n\n\n<p>This is handy for things like instructions at the top of a form. Display them upfront, but let the user collapse them once they&#8217;ve read enough.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">exclusivity<\/h2>\n\n\n\n<p>As of 2024, you can use the <code>name<\/code> attribute to create a group of dropdowns where only one can be open at a time. When one opens, any other with the same <code>name <\/code>automatically closes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;details name=\"exclusive\" open&gt;\n       &lt;summary&gt;First item&lt;\/summary&gt;\n       &lt;p&gt;This information is NOT secret.&lt;\/p&gt;\n&lt;\/details&gt;\n\n&lt;details name=\"exclusive\"&gt;\n       &lt;summary&gt;Second item&lt;\/summary&gt;\n       &lt;p&gt;This information IS secret.&lt;\/p&gt;\n&lt;\/details&gt;<\/code><\/pre>\n\n\n\n<p>The results behave like this:<\/p>\n\n\n\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<details name=\"exclusive\" open>\n  <summary>First item<\/summary>\n  <p>This information is NOT secret.<\/p>\n<\/details> <br> <br>\n\n<details name=\"exclusive\">\n  <summary>Second item<\/summary>\n  <p>This information IS secret.<\/p>\n<\/details>\n<\/div>\n\n\n\n<p>This is particularly useful for lengthy content, keeping content tidy as users browse.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">styling with css<\/h2>\n\n\n\n<p><code>&lt;details&gt;<\/code> accepts standard CSS just like any other element \u2014 background colours, borders, max-width, and so on. <\/p>\n\n\n\n<p>To style individual parts of the element without adding classes or IDs, use these pseudo-elements:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>details summary<\/code> \u2014 the summary element itself<\/li>\n\n\n\n<li><code>summary::marker<\/code> \u2014 the little disclosure triangle<\/li>\n\n\n\n<li><code>summary::after<\/code> \u2014 useful for adding custom text or icons<\/li>\n\n\n\n<li><code>details::details-content<\/code> \u2014 the expanded content area <em>(new as of September 2025; may still have Safari issues)<\/em><\/li>\n<\/ul>\n\n\n\n<p><strong>Use <code>summary::after<\/code><\/strong> when adding toggle arrows, icons, or swappable text. <strong>Use <code>details::details-content<\/code><\/strong> when styling the expanded section,  or adding padding and backgrounds to the content container. <strong>See demos 4, 5, and 6 <a href=\"https:\/\/madebymolly.uk\/seminar\/demos.html\">here<\/a> to see it in action. <\/strong><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">animating &lt;details&gt;<\/h2>\n\n\n\n<p>Edge and Chrome-based browsers already support simply adding <code>transition <\/code>and <code>animate <\/code>line items to CSS for <code>&lt;details&gt;<\/code>, but Firefox and Safari have yet to implement. It still is worth including these in your CSS, though, because even though your content will still statically snap open and shut on Firefox and Safari right now, when the browser support is added, it will immediately start working.<\/p>\n\n\n\n<p>Alternatively, a workaround in the mean time is animating all the content that comes <em>after <\/em>the summary instead of targeting the<code> &lt;details&gt; <\/code>element directly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>details&#91;open] summary ~ * {\n  animation: open 0.3s ease-in-out;\n}\n\n@keyframes open {\n  from { opacity: 0; transform: translateY(-10px); }\n  to   { opacity: 1; transform: translateY(0); }\n}<\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">bonus: &lt;details-utils&gt;<\/h2>\n\n\n\n<p>Zach Leatherman (<a href=\"https:\/\/github.com\/zachleat\">@zachleat<\/a> on GitHub) created an open source web component called <code>&lt;details-utils&gt;<\/code> that wraps your <code>&lt;details&gt;<\/code> element and adds a suite of useful behaviours with no extra JavaScript to write yourself:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Click outside to close<\/li>\n\n\n\n<li>Bind an optional close button<\/li>\n\n\n\n<li>Close with the Escape key<\/li>\n\n\n\n<li>More elegant open\/close animation<\/li>\n\n\n\n<li>Toggle between multiple CSS classes<\/li>\n\n\n\n<li>Force open or closed based on media queries<\/li>\n<\/ul>\n\n\n\n<p>You can link it into your HTML the same way you&#8217;d include any external script or font library. Full details on his blog: <a href=\"https:\/\/zachleat.com\/web\/details-utils\/\">zachleat.com\/web\/details-utils\/<\/a><\/p>\n\n\n\n<p>This is worth exploring if you&#8217;re using <code>&lt;details&gt;<\/code> for something substantial, like a site-wide FAQ.<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">recap<\/h2>\n\n\n\n<p><code>summary<\/code> and content = <code>details<\/code><\/p>\n\n\n\n<div class=\"wp-block-group has-global-padding is-layout-constrained wp-block-group-is-layout-constrained\">\n<p>Details start <strong>closed<\/strong> by default; add <code>open<\/code> to start expanded, or <code>name=\"group\"<\/code> for mutually exclusive dropdowns <\/p>\n\n\n\n<p>Nearly every part of <code>&lt;details&gt;<\/code> is customisable with CSS <\/p>\n\n\n\n<p>Animation support is still catching up across browsers \u2014 use keyframe workarounds in the meantime <\/p>\n\n\n\n<p>Structuring this element is being actively streamlined, so it&#8217;s worth staying current and checking browser support for newer features like <code>::details-content<\/code><\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">resources<\/h2>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>documentation<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Reference\/Elements\/details\" data-type=\"link\" data-id=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Reference\/Elements\/details\">MDN &lt;details&gt; <\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Reference\/Elements\/summary\" data-type=\"link\" data-id=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Reference\/Elements\/summary\">MDN &lt;summary&gt;<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Attribute_selectors\" data-type=\"link\" data-id=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/Attribute_selectors\">MDN attribute selectors<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/::after\" data-type=\"link\" data-id=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/::after\">MDN ::after<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/::marker\" data-type=\"link\" data-id=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/::marker\">MDN ::marker<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/::details-content\" data-type=\"link\" data-id=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Reference\/Selectors\/::details-content\">MDN ::details-content<\/a><\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>articles<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.zachleat.com\/web\/details-utils\/\" data-type=\"link\" data-id=\"https:\/\/www.zachleat.com\/web\/details-utils\/\">About &lt;details-utils&gt;<\/a>, Zach L.<\/li>\n\n\n\n<li><a href=\"https:\/\/nerdy.dev\/open-and-close-transitions-for-the-details-element\" data-type=\"link\" data-id=\"https:\/\/nerdy.dev\/open-and-close-transitions-for-the-details-element\">Open and close transitions<\/a>, Adam A.<\/li>\n\n\n\n<li><a href=\"https:\/\/www.sitepoint.com\/style-html-details-element\/\" data-type=\"link\" data-id=\"https:\/\/www.sitepoint.com\/style-html-details-element\/\">More styling ideas<\/a>, Ralph M.<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\">\n<p>inspo<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/codepen.io\/diegorueda\/pen\/PoWrjbE\">An easy FAQ<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/codepen.io\/jakob-e\/full\/MWzRjNe\">Vertical accordion<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/codepen.io\/ShadowShahriar\/pen\/LYgeNLB\">Fancy reveal animation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/codepen.io\/oathanrex\/pen\/EaYKaqz\">Glowing summary and animated marker<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/codepen.io\/NielsVoogt\/pen\/PoZqzGx\">&lt;details&gt; as help text<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/codepen.io\/NielsVoogt\/pen\/eYZXppQ\" data-type=\"link\" data-id=\"https:\/\/codepen.io\/NielsVoogt\/pen\/eYZXppQ\">&lt;details&gt; as a choose your own adventure game<\/a><\/li>\n<\/ul>\n<\/div>\n<\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>anatomy of the &lt;details&gt; element The &lt;details&gt; element has two parts: a &lt;summary&gt; and content. The result looks like this: This is my summary! This is my secret hidden information! This is exactly the foundation we need to create interactive dropdowns like FAQs, or organize information like on a Wikipedia page. The &lt;summary&gt; is the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-assignments"],"_links":{"self":[{"href":"https:\/\/madebymolly.uk\/journal\/wp-json\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/madebymolly.uk\/journal\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/madebymolly.uk\/journal\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/madebymolly.uk\/journal\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/madebymolly.uk\/journal\/wp-json\/wp\/v2\/comments?post=150"}],"version-history":[{"count":9,"href":"https:\/\/madebymolly.uk\/journal\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":162,"href":"https:\/\/madebymolly.uk\/journal\/wp-json\/wp\/v2\/posts\/150\/revisions\/162"}],"wp:attachment":[{"href":"https:\/\/madebymolly.uk\/journal\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/madebymolly.uk\/journal\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/madebymolly.uk\/journal\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}