<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>html &amp;mdash; Roundup Issue Tracker</title>
    <link>https://blog.rouilj.dynamic-dns.net/rouilj/tag:html</link>
    <description>A blog about developing and using the Roundup Issue Tracker. Covers web design/front end development, Python, security, user interface, customization, documentation, and community development.</description>
    <pubDate>Tue, 05 May 2026 11:44:56 -0400</pubDate>
    <item>
      <title>Can a Details Element be Used as an Accessible Popup (Without JavaScript)? </title>
      <link>https://blog.rouilj.dynamic-dns.net/rouilj/can-a-details-element-be-used-as-an-accessible-popup-without-javascript</link>
      <description>&lt;![CDATA[&#xA;&#xA;I tried a little experiment to make a popup using a details element. The goal was to see if I could make a clickable popup without using JavaScript. It should be accessible for both sighted users and users using a screen reader like NVDA.&#xA;&#xA;The HTML test case is a form with an info icon (the letter I in a circular blue field) after an input element. It is straightforward semantic HTML. The details element has a summary as its first element and a div enclosing paragraphs as the details&#39; body. The summary element is the letter I styled using CSS to put the I (for info) on a circular lightblue field. The form looks like:&#xA;&#xA;Image showing detail popup closed. The circular icon with an I in it used to open the popup has a light blue background color indicating it is closed. The rest of the screen displays labels, input fields, and one button at the bottom as you would see in a typical form.&#xA;&#xA;!--more--&#xA;&#xA;The HTML is:&#xA;  body&#xA;    form&#xA;      div&#xA;&#x9;spanlabel for=&#34;a&#34;A label:/label input id=&#34;a&#34;&#xA;&#x9;  details class=&#34;inline&#34; aria-live=&#34;polite&#34;&#xA;&#x9;    summary aria-label=&#34;Activate for info on A label.&#34;I!--&lt;img src=&#34;logo.png&#34;--  /summary&#xA;&#x9;    div&#xA;&#x9;      p&#xA;&#x9;&#x9;Here is a popup/popover with some interesting information&#xA;&#x9;&#x9;about the bA label/b input field. It might also be very&#xA;&#x9;&#x9;boring. The choice is up to you. But I would make it&#xA;&#x9;&#x9;interesting if I were you.&#xA;&#x9;      /p&#xA;&#x9;      pemUse space to close./em/p&#xA;&#x9;    /div&#xA;&#x9;  /details&#xA;&#x9;/span&#xA;&#x9;spanlabel for=&#34;b&#34;B label:/label input id=&#34;b&#34;&#xA;      /div&#xA;      div&#xA;      &#x9;spanlabel for=&#34;c&#34;C label:/label input id=&#34;c&#34;/span&#xA;...&#xA;  /form&#xA;/body&#xA; &#xA;There is a small sprinkling of ARIA. The summary field&#39;s aria-label announces what happens when you open the details element. Originally I added aria-live=&#34;polite&#34; on the div after the summary. But the detailed text was not announced when the details element opened. Moving aria-live to the details element, announced the text automatically when opened.&#xA;&#xA;The summary icon trigger is opened by:&#xA;&#xA;  clicking on the icon with the mouse,&#xA;  focusing on the icon (using tab) and&#xA;    hitting space or&#xA;    hitting return&#xA;&#xA;Unlike other popups, this is triggered by a focusing user action rather than hover so it works on mobile as well.&#xA;&#xA;The CSS was also rather straightforward. Changing the detail element&#39;s display to inline-block (default block) keeps it on the same line as the input. Changing the summary item&#39;s display to inline-block (default list-item) removes the open/close arrow associated with the details summary.&#xA;&#xA;The icon was formed by using border-radius and background-color. To get things to align, I set the custom property --icon-size to the line height of the page. This property then gets used to square up (circle up 8-)) the shape of the summary text icon. You can use an image as well if you want. The background of the icon changes when opened, and can be seen through transparent parts of an image.&#xA;&#xA;The details element (with the inline class) has its position set to relative. This makes positioning the div containing the detailed text easier. The div itself uses position: absolute. With these settings, the attributes left, top, right, and bottom can be used to shift the div relative to its default location.&#xA;&#xA;This is the complete CSS:&#xA;/ styles for details popup /&#xA;:root { --icon-size: calc(1.5em); / line height / }&#xA;details.inline {&#xA;  display: inline-block;&#xA;  position: relative; / anchor popup position /&#xA;}&#xA;details.inline summary {&#xA;  background-color: lightblue;&#xA;  border: 1px black solid;&#xA;  border-radius: 50%;&#xA;  cursor: default;&#xA;  display: inline-block;  / remove marker /&#xA;  font-weight: bold;&#xA;  height: var(--icon-size); / make icon round /&#xA;  text-align: center;&#xA;  width:var(--icon-size); / make icon round /&#xA;}&#xA;details.inline summary img {&#xA;  / if you want to use an image /&#xA;  height: var(--icon-size);&#xA;  width: var(--icon-size);&#xA;}&#xA;details.inline   div   {&#xA;  margin-block: 0.25em;&#xA;  padding-inline: 0.25em;&#xA;}&#xA;details.inline[open] summary { background-color: yellow; }&#xA;details.inline[open]   div {&#xA;  background-color: white;&#xA;  border: 2px inset black;&#xA;  border-radius: 1em;&#xA;  left: -10ch; / shift box to left /&#xA;  / Move the popup box after the icon with&#xA;     a 5px gap /&#xA;  / left: calc(var(--icon-size) + 5px); /&#xA;  position: absolute;&#xA;  / To align first line of popup with the baseline of the icon:&#xA;   shift up by 1/3 of the line height (--icon-size  -0.3333)&#xA;   then shift down by the margin-block on the div (+ 0.25em).&#xA;   This turns out to be 0.25em. /&#xA;  /top: calc((var(--icon-size)  -0.333) + 0.25em);*/&#xA;  width: 40ch;&#xA;}&#xA;&#xA;The open popup looks like this:&#xA;Image showing detail popup open. The circular icon with an I in it used to open/close the popup has a yellow background color indicating it is open. The popup sits on top of other text on the page. It is shifted to the left under the opening icon.&#xA;&#xA;Prettier styling is an exercise for the reader 8-).&#xA;&#xA;It can be enhanced with JavaScript to:&#xA;&#xA;  close with a keypress (using the escape key for example)&#xA;  close with a mouse click outside of the popup&#xA;&#xA;Even without JavaScript, it is usable in Firefox and Chrome (which includes browsers like Edge, Brave, Vivaldi...).  The details element should be accessible out of the box since it is a native HTML control. Although I only tested with NVDA and Windows Narrator, I expect it will work with other screen readers as well. (Note that Narrator would sometimes refuse to read the popup when opened. I have not discovered what causes it to refuse to read the popup on open. Moving the cursor with the right arrow key causes it to read the popup, and pressing the space key still closes the popup so....)&#xA;&#xA;This seems to be a successful experiment. Custom variables, details element, and calc are all well supported. This technique should work on the majority of browsers out there today.&#xA;&#xA;This technique will probably make it into some of the trackers I design for the Roundup Issue Tracker.&#xA;&#xA;#HTML #DevDotTo #WebDev #a11y]]&gt;</description>
      <content:encoded><![CDATA[<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqykbxskdtfy142vxml3.png" alt="" title="Banner image"></p>

<p>I tried a little experiment to make a popup using a details element. The goal was to see if I could make a clickable popup without using JavaScript. It should be accessible for both sighted users and users using a screen reader like <a href="https://www.nvaccess.org/" rel="nofollow">NVDA</a>.</p>

<p>The HTML test case is a form with an info icon (the letter I in a circular blue field) after an input element. It is straightforward semantic HTML. The details element has a summary as its first element and a div enclosing paragraphs as the details&#39; body. The summary element is the letter <code>I</code> styled using CSS to put the <code>I</code> (for info) on a circular lightblue field. The form looks like:</p>

<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8da255vyr93gkoivp3ak.png" alt="Image showing detail popup closed. The circular icon with an I in it used to open the popup has a light blue background color indicating it is closed. The rest of the screen displays labels, input fields, and one button at the bottom as you would see in a typical form."></p>



<p>The HTML is:</p>

<pre><code class="language-html">  &lt;body&gt;
    &lt;form&gt;
      &lt;div&gt;
	&lt;span&gt;&lt;label for=&#34;a&#34;&gt;A label:&lt;/label&gt; &lt;input id=&#34;a&#34;&gt;
	  &lt;details class=&#34;inline&#34; aria-live=&#34;polite&#34;&gt;
	    &lt;summary aria-label=&#34;Activate for info on A label.&#34;&gt;I&lt;!--&lt;img src=&#34;logo.png&#34;&gt;--&gt;&lt;/summary&gt;
	    &lt;div&gt;
	      &lt;p&gt;
		Here is a popup/popover with some interesting information
		about the &lt;b&gt;A label&lt;/b&gt; input field. It might also be very
		boring. The choice is up to you. But I would make it
		interesting if I were you.
	      &lt;/p&gt;
	      &lt;p&gt;&lt;em&gt;Use space to close.&lt;/em&gt;&lt;/p&gt;
	    &lt;/div&gt;
	  &lt;/details&gt;
	&lt;/span&gt;
	&lt;span&gt;&lt;label for=&#34;b&#34;&gt;B label:&lt;/label&gt; &lt;input id=&#34;b&#34;&gt;
      &lt;/div&gt;
      &lt;div&gt;
      	&lt;span&gt;&lt;label for=&#34;c&#34;&gt;C label:&lt;/label&gt; &lt;input id=&#34;c&#34;&gt;&lt;/span&gt;
...
  &lt;/form&gt;
&lt;/body&gt;
</code></pre>

<p>There is a small sprinkling of <a href="https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA" rel="nofollow">ARIA</a>. The summary field&#39;s <code>aria-label</code> announces what happens when you open the details element. Originally I added <code>aria-live=&#34;polite&#34;</code> on the <code>div</code> after the <code>summary</code>. But the detailed text was not announced when the details element opened. Moving <code>aria-live</code> to the details element, announced the text automatically when opened.</p>

<p>The summary icon trigger is opened by:</p>
<ul><li>clicking on the icon with the mouse,</li>
<li>focusing on the icon (using tab) and
<ul><li>hitting space or</li>
<li>hitting return</li></ul></li></ul>

<p>Unlike other popups, this is triggered by a focusing user action rather than hover so it works on mobile as well.</p>

<p>The CSS was also rather straightforward. Changing the detail element&#39;s <code>display</code> to <code>inline-block</code> (default <code>block</code>) keeps it on the same line as the input. Changing the summary item&#39;s <code>display</code> to <code>inline-block</code> (default <code>list-item</code>) removes the open/close arrow associated with the details summary.</p>

<p>The icon was formed by using <code>border-radius</code> and <code>background-color</code>. To get things to align, I set the custom property <code>--icon-size</code> to the line height of the page. This property then gets used to square up (circle up 8-)) the shape of the summary text icon. You can use an image as well if you want. The background of the icon changes when opened, and can be seen through transparent parts of an image.</p>

<p>The details element (with the <code>inline</code> class) has its <code>position</code> set to <code>relative</code>. This makes positioning the div containing the detailed text easier. The div itself uses <code>position: absolute</code>. With these settings, the attributes <a href="https://css-tricks.com/almanac/properties/t/top-right-bottom-left/" rel="nofollow"><code>left</code>, <code>top</code>, <code>right</code>, and <code>bottom</code></a> can be used to shift the div relative to its default location.</p>

<p>This is the complete CSS:</p>

<pre><code class="language-css">/* styles for details popup */
:root { --icon-size: calc(1.5em); /* line height */ }
details.inline {
  display: inline-block;
  position: relative; /* anchor popup position */
}
details.inline summary {
  background-color: lightblue;
  border: 1px black solid;
  border-radius: 50%;
  cursor: default;
  display: inline-block;  /* remove marker */
  font-weight: bold;
  height: var(--icon-size); /* make icon round */
  text-align: center;
  width:var(--icon-size); /* make icon round */
}
details.inline summary img {
  /* if you want to use an image */
  height: var(--icon-size);
  width: var(--icon-size);
}
details.inline &gt; div &gt; * {
  margin-block: 0.25em;
  padding-inline: 0.25em;
}
details.inline[open] summary { background-color: yellow; }
details.inline[open] &gt; div {
  background-color: white;
  border: 2px inset black;
  border-radius: 1em;
  left: -10ch; /* shift box to left */
  /* Move the popup box after the icon with
     a 5px gap */
  /* left: calc(var(--icon-size) + 5px); */
  position: absolute;
  /* To align first line of popup with the baseline of the icon:
   * shift up by 1/3 of the line height (--icon-size * -0.3333)
   * then shift down by the margin-block on the div (+ 0.25em).
   * This turns out to be 0.25em. */
  /*top: calc((var(--icon-size) * -0.333) + 0.25em);*/
  width: 40ch;
}
</code></pre>

<p>The open popup looks like this:
<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqykbxskdtfy142vxml3.png" alt="Image showing detail popup open. The circular icon with an I in it used to open/close the popup has a yellow background color indicating it is open. The popup sits on top of other text on the page. It is shifted to the left under the opening icon."></p>

<p>Prettier styling is an exercise for the reader 8-).</p>

<p>It can be enhanced with JavaScript to:</p>
<ul><li>close with a keypress (using the escape key for example)</li>
<li>close with a mouse click outside of the popup</li></ul>

<p>Even without JavaScript, it is usable in Firefox and Chrome (which includes browsers like Edge, Brave, Vivaldi...).  The details element should be accessible out of the box since it is a native HTML control. Although I only tested with NVDA and Windows Narrator, I expect it will work with other screen readers as well. (Note that Narrator would sometimes refuse to read the popup when opened. I have not discovered what causes it to refuse to read the popup on open. Moving the cursor with the right arrow key causes it to read the popup, and pressing the space key still closes the popup so....)</p>

<p>This seems to be a successful experiment. Custom variables, details element, and calc are all well supported. This technique should work on the majority of browsers out there today.</p>

<p>This technique will probably make it into some of the trackers I design for the <a href="https://www.roundup-tracker.org/?ref=dev.to" rel="nofollow">Roundup Issue Tracker</a>.</p>

<p><a href="/rouilj/tag:HTML" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">HTML</span></a> <a href="/rouilj/tag:DevDotTo" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">DevDotTo</span></a> <a href="/rouilj/tag:WebDev" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">WebDev</span></a> <a href="/rouilj/tag:a11y" class="hashtag" rel="nofollow"><span>#</span><span class="p-category">a11y</span></a></p>
]]></content:encoded>
      <guid>https://blog.rouilj.dynamic-dns.net/rouilj/can-a-details-element-be-used-as-an-accessible-popup-without-javascript</guid>
      <pubDate>Sun, 05 Mar 2023 21:17:06 +0000</pubDate>
    </item>
  </channel>
</rss>