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

              
                <body>
  <main>
    <h1>A More Accessible Required Field</h1>
    
    <form class="flow">
      <fieldset class="example example__bad">
        <legend>Visible indication only</legend>
        
        <!-- A common convention is to use an asterix (*) next to a label to indicate required fields. But this doesn't programatically indicate the field is required and depending on screen reader settings, it may not announce the asterix at all -->
        <label for="name1">Name *</label>
        <input type="text" id="name1">
        <small>All fields marked with * are required</small>
      </fieldset>
      
      <fieldset class="example example__bad">
        <legend>Relying on color only</legend>
        
        <!-- Sometimes color or bolder borders are used to indicate whether a field is required. This technique doesn't programtically indicate that a field is required, and the visual cues can also be missed by users with low contrast or color visibility issues. -->
        <label for="name2" class="required">Name</label>
        <input type="text" id="name2">
      </fieldset>
      
      <fieldset class="example example__bad">
        <legend>Programtically setting required fields</legend>
        
        <!-- Using the HTML5 required attribute will announce the field as required to screen readers, but doesn't provide any visual feedback about the required state. To stop screen readers from announcing required fields as invalid by default, set the aria-invalid="false" attribute. -->
        <label for="name3">Name</label>
        <input type="text" id="name3" required aria-invalid="false">
      </fieldset>
      
      <fieldset class="example example__good">
        <legend>Putting it All Together</legend>
        
        <!-- Using the HTML5 required attribute in addition to visual cues ensure all users know if a field is required or not. -->
        <label for="name4">Name *</label>
        <input type="text" id="name4" required aria-invalid="false">
        <small>All fields marked with * are required</small>
      </fieldset>
    </form>
  </main>
</body>
    
              
            
!

CSS

              
                :root {
  --space: 1.5rem;
}

body {
  background-color: #bebebe;
  display: grid;
  place-items: center;
  align-items: center;
  padding: var(--space);
}

main {
  background-color: #fefefe;
  padding: calc(var(--space) * 2);
  max-width: 70ch;
  border-radius: 0.25rem;
}

.flow > * + * {
  margin-top: var(--space);
}

article {
  margin-top: 3rem;
}

input {
  border-radius: 0.25rem;
  padding: 0.5rem;
}

.example {
  outline: 1px solid #efefef;
  padding: 1rem;
  border-left: 4px solid;
}

.example__bad {
  border-left-color: red;
}

.example__good {
  border-left-color: green;
}

.example__goodinput[required] input[required] {
  border: 2px solid #222;
}

label + input[type="text"] {
  display: block;
}

/* Utility Classes */

.required {
  color: red;
}

.required + input {
  background-color: #efefef;
}

.d-block {
  display: block;
}

.txt-small {
  font-size: 90%;
}

.txt-light {
  color: #444444;
}
              
            
!

JS

              
                
              
            
!
999px

Console