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

              
                <p><b>Using a mouse, try to click the highlighted button.</b></p>
<p>It's hard to click the right button when you can't see where you are. This simulates what it's like for keyboard users when buttons don't have a clear focus state.</p>

<div class="container" />
              
            
!

CSS

              
                * {
  cursor: none;
}

.container {
  display: grid;
  grid-template-columns: auto auto auto auto auto;
  grid-column-gap: 10px;
  grid-row-gap: 10px;
}

.custom-button {
  font-size: 1rem;
}

.custom-button:not(.target) {
  background-color: #ffffff;
  border-color: #666666;
  color: #666666;
}
.custom-button:not(.target):active {
  background-color: #ff0000;
  color: #ffffff;
}

              
            
!

JS

              
                const container = document.querySelector('.container');

const clearContainer = () => {
  while (container.firstChild) {
    container.removeChild(container.firstChild);
  }
}

const addButton = (index, isTarget) => {
  const button = document.createElement('button');
  button.classList.add('custom-button');
  
  if (isTarget) {
    button.classList.add('target');
    button.setAttribute('onclick', 'generateButtons(' + index + ')');
  }
  
  const content = document.createTextNode(`${index}`);
  button.appendChild(content);
  
  container.appendChild(button);
}

getTargetIndex = (lastTargetIndex) => {
  var targetIndex = Math.floor(Math.random() * 20);
  if (targetIndex === lastTargetIndex) {
    return getTargetIndex(lastTargetIndex);
  }
  return targetIndex;
}

const generateButtons = (lastTargetIndex) => {
  clearContainer();
  
  const targetIndex = getTargetIndex(lastTargetIndex);
  
  for (var i = 0; i < 20; i++) {
    addButton(i, i === targetIndex);
  }
}

generateButtons();
              
            
!
999px

Console