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>Testing <code>aria-errormessage</code>, <code>aria-invalid</code>, and <code>aria-describedby</code> Exposure with & without Live Regions</h1>
<p>
Used in the post <cite><a href="" target="_top">Exposing Field Errors</a></cite>.
</p>
<form autocomplete="off" method="get">
<div>
<label for="Field01">1. Assertive live region with <code>aria-errormessage</code></label>
<input id="Field01" name="Field01" type="text" aria-errormessage="Msg01" value="" aria-invalid="false" onblur="valerdate(this.id);" oninput="resatt(this.id);">
<span id="Msg01" class="msg" aria-live="assertive">
<span>Field 1 error using assertive live region.</span>
</span>
</div>
<div>
<label for="Field02">2. Polite live region with <code>aria-errormessage</code></label>
<input id="Field02" name="Field02" type="text" aria-errormessage="Msg02" value="" aria-invalid="false" onblur="valerdate(this.id);" oninput="resatt(this.id);">
<span id="Msg02" class="msg" aria-live="polite">
<span>Field 2 error using polite live region.</span>
</span>
</div>
<div>
<label for="Field03">3. No live region with <code>aria-errormessage</code></label>
<input id="Field03" name="Field03" type="text" aria-errormessage="Msg03" value="" aria-invalid="false" onblur="valerdate(this.id);" oninput="resatt(this.id);">
<span id="Msg03" class="msg">
<span>Field 3 error with no live region.</span>
</span>
</div>
<div>
<label for="Field04">4. No live region, uses <code>aria-describedby</code> with <code>aria-errormessage</code></label>
<input id="Field04" name="Field04" type="text" aria-errormessage="Msg04" aria-describedby="Msg04" value="" aria-invalid="false" onblur="valerdate(this.id);" oninput="resatt(this.id);">
<span id="Msg04" class="msg">
<span>Field 4 error with no live region.</span>
</span>
</div>
<div>
<label for="Field05">5. Assertive live region with <code>aria-describedby</code></label>
<input id="Field05" name="Field05" type="text" aria-describedby="Msg05" value="" aria-invalid="false" onblur="valerdate(this.id);" oninput="resatt(this.id);">
<span id="Msg05" class="msg" aria-live="assertive">
<span>Field 5 error using assertive live region.</span>
</span>
</div>
<div>
<label for="Field06">6. Polite live region with <code>aria-describedby</code></label>
<input id="Field06" name="Field06" type="text" aria-describedby="Msg06" value="" aria-invalid="false" onblur="valerdate(this.id);" oninput="resatt(this.id);">
<span id="Msg06" class="msg" aria-live="polite">
<span>Field 6 error using polite live region.</span>
</span>
</div>
<div>
<label for="Field07">7. No live region with <code>aria-describedby</code></label>
<input id="Field07" name="Field07" type="text" aria-describedby="Msg07" value="" aria-invalid="false" onblur="valerdate(this.id);" oninput="resatt(this.id);">
<span id="Msg07" class="msg">
<span>Field 7 error with no live region.</span>
</span>
</div>
<div>
<label for="Field08">8. No validation of any kind (just for parking focus)</label>
<input id="Field08" name="Field08" type="text">
</div>
<div>
<input type="submit" value="Try">
</div>
<!-- User has input an invalid value
<label for="startTime"> Please enter a start time for the meeting: </label>
<input id="startTime" type="text" aria-errormessage="msgID" aria-invalid="true" value="11:30 PM">
<span id="msgID" class="msg" aria-live="assertive"><span>Invalid time: the time must be between 9:00 AM and 5:00 PM</span></span>
-->
</form>
<!--
<h2>Results</h2>
<p>
Numbered lists correspond to numbered fields above (there is no number 8).
</p>
<ul>
<li><strong>Firefox 111 / NVDA 2023.1:</strong> Polite or assertive live regions behave the same, <code>aria-errormessage</code> text <em>not</em> exposed on focus / navigating by field, <code>aria-describedby</code> exposed on focus / navigating by field.
<ol>
<li>Announces error message onblur, before next field accName is announced; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>Announces error message onblur, before next field accName is announced; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>Does <em>not</em> announce error message onblur; error message <em>not</em> announced when otherwise putting focus on field.</li>
<li>Does <em>not</em> announce error message onblur; error message announced when otherwise focusing / navigating by field.</li>
<li>Announces error message onblur, before next field accName is announced; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>Announces error message onblur, before next field accName is announced; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>Does <em>not</em> announce error message onblur; error message announced when otherwise focusing / navigating by field.</li>
</ol>
</li>
<li><strong>Chrome 111 / JAWS 2023:</strong> Polite or assertive live regions behave polite unless <code>aria-describedby</code> is present, then they are assertive; each announces error message when focusing errored fields, those with <code>aria-errormessage</code> also announce "has error"; error message is only announced when navigating by field if it has <code>aria-describedby</code>, otherwise <code>aria-errormessage</code> only triggers it to say "Has error".
<ol>
<li>Announces error message onblur, after next field accName is announced; error message announced when focusing field, prepended with "Has error"; error message <em>not</em> announced when navigating by field (<kbd>E</kbd>), only announced "Has error".</li>
<li>Announces error message onblur, after next field accName is announced; error message announced when focusing field, prepended with "Has error"; error message <em>not</em> announced when navigating by field (<kbd>E</kbd>), only announced "Has error".</li>
<li>Does <em>not</em> announce error message onblur; error message announced when focusing field, prepended with "Has error"; error message <em>not</em> announced when navigating by field (<kbd>E</kbd>), only announced "Has error".</li>
<li>Announces error message onblur; error message announced twice when focusing field, prepended with "Has error"; error message announced when navigating by field (<kbd>E</kbd>), also announced "Has error".</li>
<li>Announces error message onblur, before next field accName is announced; error message announced when otherwise focusing / navigating by field.</li>
<li>Announces error message onblur, before next field accName is announced; error message announced when otherwise focusing / navigating by field.</li>
<li>Announces error message onblur, before next field accName is announced; error message announced when otherwise focusing / navigating by field.</li>
</ol>
</li>
<li><strong>Edge 111 / Narrator Win11:</strong> Live regions ignored; <code>aria-errormessage</code> essentially hidden to users not using virtual cursor; <code>aria-describedby</code> conveyed error message but only when already there.
<ol>
<li>Live region not honored; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>Live region not honored; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>No announcement; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>No announcement; error message announced when otherwise focusing / navigating by field.</li>
<li>Live region not honored; error message announced when otherwise focusing / navigating by field.</li>
<li>Live region not honored; error message announced when otherwise focusing / navigating by field.</li>
<li>No announcement; error message announced when otherwise focusing / navigating by field.</li>
</ol>
</li>
<li><strong>Safari 16.4 / VoiceOver macOS 12.6.4:</strong> Live regions ignored; <code>aria-errormessage</code> essentially hidden to users not using virtual cursor; <code>aria-describedby</code> conveyed error message but only when already there. Yes, tested with <kbd>Caps Lock</kbd> + <kbd>Ctrl</kbd> + <kbd>Option</kbd> + <kbd>⌘</kbd> + <kbd>J</kbd> (and have the hand cramps to prove it) even though it is the same <kbd>Tab</kbd> here.
<ol>
<li>Live region not honored; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>Live region not honored; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>No announcement; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>No announcement; error message announced when otherwise focusing / navigating by field.</li>
<li>Live region not honored; error message announced when otherwise focusing / navigating by field.</li>
<li>Live region not honored; error message announced when otherwise focusing / navigating by field.</li>
<li>No announcement; error message announced when otherwise focusing / navigating by field.</li>
</ol>
</li>
<li><strong>Chrome 111 / TalkBack 13.1 / Android 13:</strong> Live regions ignored; <code>aria-errormessage</code> essentially hidden to users not using virtual cursor; <code>aria-describedby</code> conveyed error message but only when already there.
<ol>
<li>Live region not honored; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>Live region not honored; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>No announcement; error message <em>not</em> announced when otherwise focusing / navigating by field.</li>
<li>No announcement; error message announced when otherwise focusing / navigating by field.</li>
<li>Live region not honored; error message announced when otherwise focusing / navigating by field.</li>
<li>Live region not honored; error message announced when otherwise focusing / navigating by field.</li>
<li>No announcement; error message announced when otherwise focusing / navigating by field.</li>
</ol>
</li>
<li><strong>Safari / VoiceOver iPadOS 16.4:</strong> both live regions announce onblur, the assertive region interrupting the next field name before it fully announces, the field with no live region announces as a live region the same as the field with polite as does the field using <code>aria-describedby</code> and <code>aria-errormessage</code> while the field using <code>aria-describedby</code> is not treated as a live region; each announces error message when going back through page and focusing fields.
<ol>
<li>Announces error message onblur, interrupting next field accName announcement; error message announced when otherwise focusing / navigating by field.</li>
<li>Announces error message onblur, interrupting next field accName announcement; error message announced when otherwise focusing / navigating by field.</li>
<li>Announces error message onblur, interrupting next field accName announcement; error message announced when otherwise focusing / navigating by field.</li>
<li>Announces error message onblur, interrupting next field accName announcement; error message announced when otherwise focusing / navigating by field.</li>
<li>Announces "Invalid data" (not error message) onblur, interrupting next field accName announcement; error message announced when otherwise focusing / navigating by field.</li>
<li>Announces "Invalid data" (not error message) onblur, interrupting next field accName announcement; error message announced when otherwise focusing / navigating by field.</li>
<li>Announces "Invalid data" (not error message) onblur, interrupting next field accName announcement; error message announced when otherwise focusing / navigating by field.</li>
</ol>
</li>
</ul>
-->
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;
}
form {
margin-top: 2em;
}
label, .msg {
display: block;
}
div {
margin-top: 1em;
}
input + .msg > span {
visibility: hidden;
}
input[aria-invalid="true"] + .msg > span {
visibility: visible;
font-style: italic;
color: #c00;
}
ul > li {
margin-bottom: 1em;
}
function valerdate(btnID) {
// Get the element that triggered this
var theField = document.getElementById(btnID);
theField.setAttribute("aria-invalid", "true");
}
function resatt(btnID) {
// Get the element that triggered this
var theField = document.getElementById(btnID);
theField.setAttribute("aria-invalid", "false");
}
Also see: Tab Triggers