rel external for accessible image modals

This commit is contained in:
2026-03-25 13:03:30 -07:00
parent 0439f0478d
commit 8adb83d8a8
282 changed files with 3253 additions and 3281 deletions

View File

@ -20,9 +20,9 @@
<p>Fair warning: This solution is likely imperfect.</p>
</blockquote>
<h2 id="the-dialog-element">the <code>dialog</code> element</h2>
<p>do you know how many tutorials want you to roll your own modals? It's a not-insignificant amount. W3Schools, top of the search results in many cases, recommends it in two places - <a href="https://www.w3schools.com/howto/howto_css_modal_images.asp" target="_blank">image modals</a> and <a href="https://www.w3schools.com/css/css3_images_modal.asp" target="_blank">responsive image modals</a>. Several search results for "image modal" pop up div solutions - <a href="https://stackoverflow.com/questions/75598914/how-to-display-an-image-clicking-on-it-using-modal-window-on-html-css-and-js" target="_blank">div modal 1</a>, <a href="https://dev.to/salehmubashar/create-an-image-modal-with-javascript-2lf3" target="_blank">div modal 2</a>, <a href="https://www.youtube.com/watch?v=Y9TNHynFjaQ" target="_blank">div modal 3</a>.</p>
<p>do you know how many tutorials want you to roll your own modals? It's a not-insignificant amount. W3Schools, top of the search results in many cases, recommends it in two places - <a href="https://www.w3schools.com/howto/howto_css_modal_images.asp" target="_blank" rel="external">image modals</a> and <a href="https://www.w3schools.com/css/css3_images_modal.asp" target="_blank" rel="external">responsive image modals</a>. Several search results for "image modal" pop up div solutions - <a href="https://stackoverflow.com/questions/75598914/how-to-display-an-image-clicking-on-it-using-modal-window-on-html-css-and-js" target="_blank" rel="external">div modal 1</a>, <a href="https://dev.to/salehmubashar/create-an-image-modal-with-javascript-2lf3" target="_blank" rel="external">div modal 2</a>, <a href="https://www.youtube.com/watch?v=Y9TNHynFjaQ" target="_blank" rel="external">div modal 3</a>.</p>
<p>If you don't know of the existence of <code><dialog></code>, a search for image modals will not get you there quickly.</p>
<p>If you search for <em>accessible</em> image modals, you'll still hear about <code><div></code>s. Hell, <a href="https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/examples/dialog/" target="_blank">W3C's ARIA Authoring Practices Guide uses a <code><div></code></a>. You kinda have to go digging to read about the <a href="https://www.scottohara.me/blog/2023/01/26/use-the-dialog-element.html" target="_blank">dialog element from Scott O'Hara</a> or find <a href="https://accessibleweb.dev/modals" target="_blank">AccessibleWeb.dev's piece on modals</a>. Or you can go <a href="https://adrianroselli.com/2025/06/where-to-put-focus-when-opening-a-modal-dialog.html" target="_blank">straight for Adrian Roselli</a> and find examples that use the native <code><dialog></code> element. Thanks Adrian!</p>
<p>If you search for <em>accessible</em> image modals, you'll still hear about <code><div></code>s. Hell, <a href="https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/examples/dialog/" target="_blank" rel="external">W3C's ARIA Authoring Practices Guide uses a <code><div></code></a>. You kinda have to go digging to read about the <a href="https://www.scottohara.me/blog/2023/01/26/use-the-dialog-element.html" target="_blank" rel="external">dialog element from Scott O'Hara</a> or find <a href="https://accessibleweb.dev/modals" target="_blank" rel="external">AccessibleWeb.dev's piece on modals</a>. Or you can go <a href="https://adrianroselli.com/2025/06/where-to-put-focus-when-opening-a-modal-dialog.html" target="_blank" rel="external">straight for Adrian Roselli</a> and find examples that use the native <code><dialog></code> element. Thanks Adrian!</p>
<p>Did I roll my own modal at first? Regretfully, yes. I'd used the <code><dialog></code> element before... several years ago... in a project I don't have access to anymore... Needless to say, I had forgotten about its existence.</p>
<p>Anyway, I got there. Eventually. So let's talk about modals and <code><dialog></code>.</p>
<h3 id="what-does-dialog-give-us">what does <code><dialog></code> give us?</h3>
@ -38,7 +38,7 @@
<li>the <code>autofocus</code> attribute for in-modal elements to set which element should receive focus on opening the modal</li>
<li>the <code>open</code> attribute which is set on the <code><dialog></code> when open and removed when closed (when you use the functions mentioned previously)</li>
</ol>
<p>and more. This is just the pieces in use for me. There's also things like <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dialog#additional_notes" target="_blank">setting forms so that submission closes the dialog</a> (point 1 in that list).</p>
<p>and more. This is just the pieces in use for me. There's also things like <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dialog#additional_notes" target="_blank" rel="external">setting forms so that submission closes the dialog</a> (point 1 in that list).</p>
<h3 id="what-doesnt-it-give-us">what doesn't it give us?</h3>
<ol>
<li>a close button - gotta roll your own and attach the requisite <code>.close()</code> call (or rely on users hitting escape or clicking the backdrop)</li>
@ -49,7 +49,7 @@
<blockquote>
<p>Do not add the <code>tabindex</code> property to the <code><dialog></code> element as it is not interactive and does not receive focus.</p>
</blockquote>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dialog#additional_notes" target="_blank"><code><dialog></code>: additional notes</a> (point 3 in that list).</p>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dialog#additional_notes" target="_blank" rel="external"><code><dialog></code>: additional notes</a> (point 3 in that list).</p>
<p>despite this, I found that in Firefox (but not Edge), the <em><code><dialog></code> itself was focusable</em>. I have no idea why, but I tested this on a totally unstyled and unmodified page and still found it to be true. As a focusable element, it made no sense. It had no interactivity and could not be activated.</p>
<p>I'm still torn: do I add <code>tabindex="-1"</code>? MDN specifically says not to, but I'm pretty sure they're warning against making it <em>focusable</em>. Why warn against making it nonfocusable when <em>it's not supposed to be focusable in the first place</em>, after all?</p>
<p>At current, I'm ambivalent, but I've added <code>tabindex="-1"</code> to handle Firefox's poor behavior. Making the dialog focusable is unhelpful and confusing.</p>
@ -69,7 +69,7 @@
<h3 id="css">css</h3>
<p>here's the most relevant parts of the CSS:</p>
<ul>
<li><code>dialog::backdrop</code> was given a <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Colors/Using_relative_colors" target="_blank">relatively calculated</a> color - <code>rgba(from var(--color-bg) r g b / .8)</code> - as well as a blur</li>
<li><code>dialog::backdrop</code> was given a <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Guides/Colors/Using_relative_colors" target="_blank" rel="external">relatively calculated</a> color - <code>rgba(from var(--color-bg) r g b / .8)</code> - as well as a blur</li>
<li><code>body:has(dialog[open])</code> has <code>overflow: hidden</code> set</li>
<li><code>dialog img</code> uses a <code>max-height</code> as well as <code>object-fit: contain</code></li>
</ul>
@ -83,7 +83,7 @@
<updated>2026-02-19T00:00:00Z</updated>
<id>https://leecat.art/eleventy-lessons/</id>
<content type="html">&lt;p&gt;recently I wrote &lt;em&gt;several&lt;/em&gt; sites using &lt;a href=&quot;https://www.11ty.dev/&quot; target=&quot;_blank&quot; rel=&quot;external&quot;&gt;Eleventy&lt;/a&gt; (4? 5?). Including, over the past few days, rewriting this one! That&#39;s right, if you&#39;re reading this, we&#39;re now running on 11ty and hosted by &lt;a href=&quot;https://heckin.technology/&quot; target=&quot;_blank&quot; rel=&quot;external&quot;&gt;heckin.technology&lt;/a&gt;. See ya, GitHub. Won&#39;t miss ya.&lt;/p&gt;
&lt;p&gt;I&#39;ve compiled some of the things I&#39;ve learned in a standalone site: &lt;a href=&quot;https://inherentlee.codeberg.page/lessons/&quot; target=&quot;_blank&quot; rel=&quot;external&quot;&gt;11ty Lessons&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Originally, I compiled some of the things I&#39;ve learned in a standalone site.&lt;/p&gt;
&lt;p&gt;however, since I don&#39;t know how much I&#39;ll focus on that specific site - it is mostly a sample - I am re-publishing the most useful information here. I&#39;ll skip the intro to Markdown content. I&#39;m also going to update them where I&#39;ve learned more or to better match what&#39;s represented on this site.&lt;/p&gt;
&lt;p&gt;this will comprise of 4 parts: &lt;a href=&quot;https://leecat.art/eleventy-lessons/#related-posts&quot;&gt;related posts&lt;/a&gt;, &lt;a href=&quot;https://leecat.art/eleventy-lessons/#featured-images&quot;&gt;featured images&lt;/a&gt;, &lt;a href=&quot;https://leecat.art/eleventy-lessons/#pagination&quot;&gt;pagination&lt;/a&gt;, and &lt;a href=&quot;https://leecat.art/eleventy-lessons/#tag-image-preview&quot;&gt;tag image preview&lt;/a&gt;. Feel free to jump ahead, as none depend on the others.&lt;/p&gt;
&lt;hr&gt;