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

              
                <h2>What is this about?</h2>
<p>This snippet intends to demonstrate the issue with having identical styling for "checked" and "focused" styles, when there are no other visual cues. This is a rather common issue when checkboxes are restyled to not display the box itself.</p>
<h2>How to use this?</h2>
<p>Press the <kbd>Tab</kbd> key until the focus lands on the placeholder link. Now pay close attention, and press on <kbd>Tab</kbd> again. Unless you have user-defined styles in your browser, you should see... nothing.</p>
<p>Now press <kbd>Tab</kbd> again. "choice 2" in the first set should be green.</p>

<a href="#">This placeholder link is here only to provide a first tab stop</a>
<fieldset id="same">
  <legend>Focus and active states look the same</legend>
  <label for="1.1"><input id="1.1" type=checkbox checked /><span>choice 1</span></label>
<label for="1.2"><input id="1.2"  type=checkbox /><span>choice 2</span></label>
<label for="1.3"><input id="1.3"  type=checkbox /><span>choice 3</span></label>
</fieldset>
<p>Go on tabbing, until you reach the second set. You should see that the element that has focus appears in bold red.</p>
<fieldset id="different">
  <legend>Focus and active states look different</legend>
  <label for="2.1"><input id="2.1" type=checkbox checked /><span>choice 1</span></label>
<label for="2.2"><input id="2.2"  type=checkbox /><span>choice 2</span></label>
<label for="2.3"><input id="2.3"  type=checkbox /><span>choice 3</span></label>
</fieldset>
<h2>Explanations</h2>
<p>In the first set of checkboxes, "checked" and "focus" states are identical in style. If the checkbox is already checked ('Choice 1' is, here), then when it gets focus, there's no visible difference.</p>
<p>By contrast, in the second set, checkboxes are styled differently when they are checked and when they have focus. When the focus lands on 'Choice 1', there's a clear visual cue.</p>
<h2>Why bother?</h2>
<p>It's an accessibility issue. Users who navigate with the keyboard only (or similar switch-based input devices), and can see the screen, really need to know the current position of the focus, at any time. If "checked" and "focus" styles are identical, then it's like having no focused state at all.</p>
<h2>How to do it better?</h2>
<p>Best option is to keep a visible focus ring for every focusable element. That way, you lessen the risk that user-side styling (like high-contrast modes) jeopardizes the user's ability to know the current cursor position.</p>
<h2>Questions?</h2>
<p>Get in touch: <a href="https://twitter.com/OlivierNourry">I'm @OlivierNourry on Twitter</a></p>

              
            
!

CSS

              
                label {
  display: block;
}
input[type=checkbox] {
  position:absolute;
  left:-100000px;
}
input:checked + span {
    color: green;
  }
input:focus + span {
    color: green;
  }
#different  input:focus + span {
    color: red;
    font-weight:bold;
  }
/* debug
  input:checked + span:after {
    content: " - active";
  }
  input:focus + span:after {
    content: " - focused";
  }
}
*/
              
            
!

JS

              
                  
              
            
!
999px

Console