HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
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; */
}
Also see: Tab Triggers