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>Testing <code>aria-errormessage</code>, <code>aria-invalid</code>, and <code>aria-describedby</code> Exposure with &amp; 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>
-->
              
            
!

CSS

              
                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;
}
              
            
!

JS

              
                
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");
}
              
            
!
999px

Console