Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>An <code>alt</code> Decision Tree Using Only <code>:has()</code></h1>

<p>
  <a href="https://validator.w3.org/nu/?doc=https%3A%2F%2Fcdpn.io%2Faardrian%2Fdebug%2FKKrjEEX" target="_top">Nu Checker results</a>. Used in my post <a href="https://adrianroselli.com/2023/08/an-alt-decision-tree-using-only-has.html" target="_top"><cite>An alt Decision Tree Using Only :has()</cite></a>.
</p>

<!-- Q1 -->

<fieldset id="Start">
  <legend>Does the image contain text?</legend>
  <input type="radio" name="hasText" id="hasTextNo">
  <label for="hasTextNo">No</label>
  <input type="radio" name="hasText" id="hasTextYes">
  <label for="hasTextYes">Yes</label>
</fieldset>

<h2 class="hide">
  If yes, the image contains text…
</h2>
<ul id="YesText">
  <li>… and the text is also present as <em>real</em> text nearby.
    Use an empty <code>alt</code> attribute. See <a href="https://www.w3.org/WAI/tutorials/images/decorative/" target="_top">Decorative Images</a>.
  </li>
  <li>… and the text is only shown for visual effects.
    Use an empty <code>alt</code> attribute. See <a href="https://www.w3.org/WAI/tutorials/images/decorative/" target="_top">Decorative Images</a>.
  </li>
  <li>… and the text has a specific function, for example is an icon.
    Use the <code>alt</code> attribute to communicate the function of the image. See <a href="https://www.w3.org/WAI/tutorials/images/functional/" target="_top">Functional Images</a>.
  </li>
  <li>… and the text in the image is not present otherwise. Use the <code>alt</code> attribute to include the text of the image. See <a href="https://www.w3.org/WAI/tutorials/images/textual/#image-of-styled-text-with-decorative-effect" target="_top">Images of Text</a>.</li>
</ul>

<!-- / Q1 -->
<!-- Q2 -->

<h2 class="hide">
  If no, the image contains no text…
</h2>
<fieldset id="NoText">
  <legend>Is the image used in a link or a button, and would it be hard or impossible to understand what the link or the button does, if the image wasn’t there?</legend>
  <input type="radio" name="asControl" id="asControlNo">
  <label for="asControlNo">No</label>
  <input type="radio" name="asControl" id="asControlYes">
  <label for="asControlYes">Yes</label>
</fieldset>

<h2 class="hide">
  If yes, the image is contained in a control…
</h2>
<ul id="YesControl">
  <li>Use the <code>alt</code> attribute to communicate the destination of the link or action taken. See <a href="https://www.w3.org/WAI/tutorials/images/functional/" target="_top">Functional Images</a>.</li>
</ul>

<!-- / Q2 -->
<!-- Q3 -->

<h2 class="hide">
  If no, the image is not contained in a control…
</h2>
<fieldset id="NoControl">
  <legend>Does the image contribute meaning to the current page or context?</legend>
  <input type="radio" name="addsMeaning" id="addsMeaningNo">
  <label for="addsMeaningNo">No</label>
  <input type="radio" name="addsMeaning" id="addsMeaningYes">
  <label for="addsMeaningYes">Yes</label>
</fieldset>

<h2 class="hide">
  If yes, the image contributes meaning…
</h2>
<ul id="YesMeaning">
  <li>… and it’s a simple graphic or photograph.
    Use a brief description of the image in a way that conveys that meaning in the <code>alt</code> attribute. See <a href="https://www.w3.org/WAI/tutorials/images/informative/" target="_top">Informative Images</a>.
  </li>
  <li>… and it’s a graph or complex piece of information.
    Include the information contained in the image elsewhere on the page. See <a href="https://www.w3.org/WAI/tutorials/images/complex/" target="_top">Complex Images</a>.
  </li>
  <li>… and it shows content that is redundant to <em>real</em> text nearby.
    Use an empty <code>alt</code> attribute. See (redundant) <a href="https://www.w3.org/WAI/tutorials/images/functional/#logo-image-within-link-text" target="_top">Functional Images</a>.
  </li>
</ul>

<!-- / Q3 -->
<!-- Q4 -->

<h2 class="hide">
  If no, the image contributes no meaning…
</h2>
<fieldset id="NoMeaning">
  <legend>Is the image purely decorative or not intended for the user?</legend>
  <input type="radio" name="isDecorative" id="isDecorativeNo">
  <label for="isDecorativeNo">No</label>
  <input type="radio" name="isDecorative" id="isDecorativeYes">
  <label for="isDecorativeYes">Yes</label>
</fieldset>

<h2 class="hide">
  If yes, the image is purely decorative…
</h2>
<ul id="YesDecorative">
  <li>Use an empty <code>alt</code> attribute. See <a href="https://www.w3.org/WAI/tutorials/images/decorative/" target="_top">Decorative Images</a>.</li>
</ul>

<!-- Q5 -->

<h2 class="hide">
  If no, the image is not purely decorative…
</h2>
<fieldset id="NoDecorative">
  <legend>Is the image’s use not listed above or it’s unclear what <code>alt</code> text to provide?</legend>
  <input type="radio" name="isListed" id="isListedNo">
  <label for="isListedNo">No</label>
  <input type="radio" name="isListed" id="isListedYes">
  <label for="isListedYes">Yes</label>
</fieldset>

<h2 class="hide">
  If yes, the image’s use is not listed above…
</h2>
<ul id="YesUnclear">
  <li class="yes">This decision tree <strong>does not</strong> cover all cases. For detailed information on the provision of text alternatives refer to the <a href="https://www.w3.org/WAI/tutorials/images/" target="_top">Image Concepts Page</a>.</li>
</ul>

<h2 class="hide">
  If no, because the image’s use is listed above…
</h2>
<ul id="NoUnclear">
  <li class="yes">I suggest you <a href="#hasTextNo">start over</a>.</li>
</ul>
              
            
!

CSS

              
                html {
  color-scheme: dark light;
}

body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  line-height: 1.4;
  /*   line-height: 1.5; */
  /*   letter-spacing: 0.12em; */
  /*   word-spacing: 0.16em; */
}

h1, h2 {
  line-height: 1;
}

h2 {
  margin-top: 2em;
}

/* Requires :has() support or entire selector fails */
:focus, input:has(+ label:hover) {
  outline: .2em solid rgba(0,0,255,.25);   
}

/* Redundant to account for lack of :has() support */
:focus {
  outline: .2em solid rgba(0,0,255,.25); 
}

/* Requires :has() support or entire selector fails */
label:hover, input:hover, input:hover + label, input:focus + label, input:has(+ label:hover) {
  background-color: rgba(0,0,255,.05);
}

/* Redundant to account for lack of :has() support */
label:hover, input:hover, input:hover + label, input:focus + label {
  background-color: rgba(0,0,255,.05);
}

label, input {
  padding-block-start: .25em;
  padding-block-end: .25em;
  padding-inline-start: .25em;
}

fieldset {
  margin-block-start: 2em;
  margin-block-end: 2em;
  padding-block-start: 1em;
  padding-block-end: 1em;
  display: grid;
  grid-template-columns: 1.5em auto;
  border-radius: .5em;
}

fieldset:has(input:indeterminate) {
  border-color: #900;  
}

fieldset:has(input:not(:indeterminate)) {
  border-color: #090;  
}

legend {
  font-weight: bold;
/* The following are hacks I tried for dealing */
/* with a Safari bug that compresses the width. */
/*   width: max-content; */
/*   white-space: break-spaces; */
/*   text-wrap: balance; */
/*   text-wrap: pretty; */
/*   grid-column-start: 1; */
/*   grid-column-end: 2; */
/*   justify-self: stretch; */
  min-width: 50vw;
}

li {
  margin-block-end: 1em;
}

/* Convoluted, but hides only if browser */
/* supports :has(), ensuring display parity */
fieldset:has(legend) ~ h2.hide {
  display: none;
}

/* Q1 */

/* If NO not checked, hide the fields */
fieldset#Start:has(#hasTextNo:not(:checked)) ~ fieldset#NoText {
  display: none;
}
/* If YES not checked, hide the list */
fieldset#Start:has(#hasTextYes:not(:checked)) ~ ul#YesText {
  display: none;
}

/* Q2 */

/* If NO not checked, hide the fields */
fieldset#NoText:has(#asControlNo:not(:checked)) ~ fieldset#NoControl {
  display: none;
}
/* If YES not checked, hide the list */
fieldset#NoText:has(#asControlYes:not(:checked)) ~ ul#YesControl {
  display: none;
}
/* If YES checked in prior question, this cannot show */
fieldset#Start:has(#hasTextYes:checked) ~ ul#YesControl {
  display: none;
}
/* If YES checked in prior question, this cannot show */
fieldset#Start:has(#hasTextYes:checked) ~ fieldset#NoControl {
  display: none;
}

/* Q3 */

/* If NO not checked, hide the fields */
fieldset#NoControl:has(#addsMeaningNo:not(:checked)) ~ fieldset#NoMeaning {
  display: none;
}
/* If YES not checked, hide the list */
fieldset#NoControl:has(#addsMeaningYes:not(:checked)) ~ ul#YesMeaning {
  display: none;
}
/* If YES checked in prior question, this cannot show */
fieldset#NoText:has(#asControlYes:checked) ~ ul#YesMeaning {
  display: none;
}
/* If YES checked in prior question, this cannot show */
fieldset#NoText:has(#asControlYes:checked) ~ fieldset#NoMeaning {
  display: none;
}
/* If YES checked in prior prior prior question, this cannot show */
fieldset#Start:has(#hasTextYes:checked) ~ fieldset#NoMeaning {
  display: none;
}

/* Q4 */

/* If NO not checked, hide the fields */
fieldset#NoMeaning:has(#isDecorativeNo:not(:checked)) ~ fieldset#NoDecorative {
  display: none;
}
/* If YES not checked, hide the list */
fieldset#NoMeaning:has(#isDecorativeYes:not(:checked)) ~ ul#YesDecorative {
  display: none;
}
/* If YES checked in prior question, this cannot show */
fieldset#NoControl:has(#addsMeaningYes:checked) ~ ul#YesDecorative {
  display: none;
}
/* If YES checked in prior question, this cannot show */
fieldset#NoControl:has(#addsMeaningYes:checked) ~ fieldset#NoDecorative {
  display: none;
}
/* If YES checked in prior prior question, this cannot show */
fieldset#NoText:has(#asControlYes:checked) ~ fieldset#NoDecorative {
  display: none;
}
/* If YES checked in prior prior prior question, this cannot show */
fieldset#Start:has(#hasTextYes:checked) ~ fieldset#NoDecorative {
  display: none;
}

/* Q5 */

/* If NO not checked, hide the fields */
fieldset#NoDecorative:has(#isListedNo:not(:checked)) ~ ul#NoUnclear {
  display: none;
}
/* If YES not checked, hide the list */
fieldset#NoDecorative:has(#isListedYes:not(:checked)) ~ ul#YesUnclear {
  display: none;
}
/* If YES checked in prior question, this cannot show */
fieldset#NoMeaning:has(#isDecorativeYes:checked) ~ ul#YesUnclear {
  display: none;
}
/* If YES checked in prior question, this cannot show */
fieldset#NoMeaning:has(#isDecorativeYes:checked) ~ ul#NoUnclear {
  display: none;
}
/* If YES checked in prior prior question, this cannot show */
fieldset#NoControl:has(#addsMeaningYes:checked) ~ ul#NoUnclear {
  display: none;
}
/* If YES checked in prior prior prior question, this cannot show */
fieldset#NoText:has(#asControlYes:checked) ~ ul#NoUnclear {
  display: none;
}
/* If YES checked in prior prior prior prior question, this cannot show */
fieldset#Start:has(#hasTextYes:checked) ~ ul#NoUnclear {
  display: none;
}

/* Restart */

fieldset#Start:target ~ * {
/*   display: none; */
}
              
            
!

JS

              
                
              
            
!
999px

Console