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

              
                <pre></pre><h1>Component size vs Visual size</h1>
<p>Some example buttons for focus appearance comparing what happens when you measure the underlying component vs visually.</p>

<p class="alert">OLD, do not reference!</p>

<p><button class="example1">Button 1</button> - default, passes both</p>

<p><button class="example2">Button 2</button> - drop shadow extends visual size, but not component size. Passes 'component'; fails 'visual'.</p>

<p><button class="example2b">Button 2b</button> - drop shadow used as focus indicator</p>
<p><button class="example2b">Button 2b</button> - drop shadow used as focus indicator</p>
<p><button class="example2b">Button 2b</button> - drop shadow used as focus indicator</p>

<p><button class="example3">Button 3</button> - outline offset (-3px) leads to fail measured both by component and visuals.</p>

<p><button class="example3 alt3">Button 3</button> - outline offset (+3px) leads to passes both by component and visuals.</p>

<p><span class="padding"><button class="example4">Button 4</button></span> - button wrapped in a span, the span is providing the background. Passes 'component'; fails 'visual'.</p>

<p><button class="example5"><span>Button 5</span></button> - background provided within the component, expanded hit area. Passes both.</p>

<p><button class="example5b"><span>Button 5b</span></button> - background provided within the component, and the outline goes around the inner span. (Grey dashed border shows the button size.) Passes visual, fails component.</p>

<p><button class="example6">Button 6</button> - large border radius.</p>

<p><button class="example7">Button 7</button> - small border radius.</p>

<p>Example grabbed from <a href="https://codepen.io/aardrian/pen/vYOGpXb">Adrian's block links article</a>. The link is the heading (which looks like a link), but the focus indicator goes around the whole card. Visually, what is the component? (Without a self-referencial "whatever the outline goes around!")</p>
<div>
<article class="block reorder">
    <h3><a href="https://example.com/re-ordered" rel="nofollow">Art Visually Above Heading</a></h3>
    <img src="https://placekitten.com/680/380" width="680" height="380" alt="Kitten resting against a scratching post.">
    <p>
      This looks perfect. Just Photoshop out the dog, add a baby, and make the curtains blue. There are more projects
      lined up; charge extra the next time. Can you make the logo bigger? Yes, bigger. Bigger still. The logo is too
      big.
    </p>

  </article>
  
  <article class="blockalt reorder">
    <h3><a href="https://example.com/re-ordered" rel="nofollow">Art Visually Above Heading</a></h3>
    <img src="https://placekitten.com/680/380" width="680" height="380" alt="Kitten resting against a scratching post.">
    <p>
      This looks perfect. Just Photoshop out the dog, add a baby, and make the curtains blue. There are more projects
      lined up; charge extra the next time. Can you make the logo bigger? Yes, bigger. Bigger still. The <a href="#">logo</a> is too
      big.
    </p>

  </article>
</div>

  <p>From a visual point of view, I find it impossible to evaluate these two 'card' examples without knowing what the interactive element is. The HTML for each is the same, but the first one uses CSS to increase the hit area and the second does not.</p>

<h2>Conclusion</h2>
<p>Most examples (in usage, not here) will match the component size and visuals. However, using the underlying component allows for the focus indicator to go around the text content, not the whole visual component (although that wouldn't be a problem to do so).</p>

<p>Also, the default focus indicator (outline) aligns with the component metric, therefore it is easier to test. You could outline everything with CSS, and then tab through to check for differences. e.g.</p>
<pre>a:not(:focus), button:not(:focus), input:not(:focus) {
    outline: 2px red solid !important;
}</pre>

<img class="screenshot" src="https://alastairc.uk/tmp/highlight-outlines.png" alt="Screenshot of this page, with red outlines of every interactive component.">
              
            
!

CSS

              
                body {
  font-family: sans-serif;
  max-width: 50rem;
  margin: 0 auto;
}
.alert {
  font-size: 2rem;
  color: #900;
  font-weight: bold;
}
button {
  border-radius: 0;
  border-style: none;
  padding: 4px;
  background: #DFDFDF;
  cursor: hand;
}

.example2 {
  box-shadow: 5px 5px 5px #bbb, -5px -5px 5px #bbb, -5px 5px 5px #bbb, 5px -5px 5px #bbb;
  margin-bottom: 5px;
  margin-right: 5px;
}
.example2:focus {
  box-shadow: none;
}
.example2b {
  margin-bottom: 5px;
  margin-right: 5px;
}
.example2b:focus {
  box-shadow: 5px 5px 5px #bbb, -5px -5px 5px #bbb, -5px 5px 5px #bbb, 5px -5px 5px #bbb;
  outline: transparent 2px solid;
}
.example3 {
  padding: 8px;
}
.example3:focus {
  outline-offset: -5px;
}
.example3.alt3:focus {
  outline-offset: 5px;
}

.padding {
  padding: 10px;
  background: #DFDFDF;
  display: inline-block;
}
.example4 {
  padding: 0px;
  background: none;
}

.example5 {
  background: none;
  
}

.example5 span {
  margin: 5px;
  padding: 3px;
  background: #DFDFDF;
  display: inline-block;
}


.example5b {
  background: none;
  padding: 5px;
  border: 1px grey dashed;
}

.example5b span {
  background: #DFDFDF;
  padding: 3px;
  margin: 3px;
  display: inline-block;
}

.example5b:focus  {
  outline: none;
  
}
.example5b:focus span {
  outline: 1px blue solid;
  
}

.example6 {
 padding: 0.5rem;
 height: 5rem;
  width: 5rem;
 border-radius: 5rem; 
  display: inline-block;
}

.example7 {
 padding: 0.5rem;
  width: 5rem;
 border-radius: 1rem; 
  display: inline-block;
}




/* Adrian's example */

div {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}

div > * {
  padding: .5em 1em;
  margin: 0 0.5em 1em 0.5em;
  flex: 0 1 20em;
  border: .2em solid rgba(0,0,0,.15);
  border-radius: 1em;
  background-color: #fff;
}

img {
  max-width: 100%;
  height: auto;
}

h3 {
  margin: .2em 0;
  line-height: 1.2;
}

div p {
  margin: .2em 0;
}

div a:focus, div a:hover, div a {

}

.default a:link {
  color: #333;
}

.default a:focus h3, .default a:hover h3 {
  color: #00f;
  text-decoration: underline;
}


/* Move the image above the heading */

.reorder {
  display: flex;
  flex-direction: column;
  padding-top: .5em;
}

.reorder img {
/*  see comment on post  */
  order: -1;
}


/* Block links */

.block {
  position: relative;
}

.block a[href]::after, .block button::after {
  content: "";
  display: block;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}


.block:hover, .block:focus-within, .default:hover, .default:focus-within {
  border-color: rgba(0,0,255,.5);
  box-shadow: 0 0 .5em rgba(0,0,0,.25);
}

.blockalt a:focus {
  outline: 3px solid blue;
}

/* Help out IE */

.block a[href]:hover, .block a[href]:focus {
  outline: .4em solid rgba(0,0,255,.25);
  outline-offset: .25em;
}

/* Undo the IE */

.block:hover a[href]:hover, .block:hover a[href]:focus, .block:hover button:focus, .block:hover button:hover, .block:focus-within a[href]:hover, .block:focus-within a[href]:focus, .block:focus-within button:focus, .block:focus-within button:hover {
  outline: none;
}

.screenshot {
  border: 2px grey solid;
}
              
            
!

JS

              
                
              
            
!
999px

Console