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>Ordinary (original) checkbox hack</h1>
<label for="checkbox">Checkbox label DOM before</label>
<input type="checkbox" id="checkbox" role="button">
<label for="checkbox">Checkbox label DOM after</label>
<div>
  <label for="checkbox">Checkbox in child element DOM after</label>
</div>

<h1>Overhauled checkbox hack</h1>
<label for="checkbox-oh">Checkbox label DOM before</label>
<input type="checkbox" id="checkbox-oh" class="checkbox-hack-checkbox" aria-labelledby="checkbox-oO" aria-controls="checkbox-hack-target" aria-hidden="true">
<div>
    <label for="checkbox-oh">Checkbox label DOM after</label>
    <div>
        <label for="checkbox-oh" id="checkbox-oO" role="button" tabindex="0" aria-expanded="false"><strong>Checkbox in child element DOM after</strong></label>
  </div>
</div>
<a href="">Link tab navigation hurdle</a>
<aside id="checkbox-hack-target" class="checkbox-hack-target">
  checkbox hack target
  <a href="">target link 0</a>
  <a href="">target link 1</a>
<aside>
              
            
!

CSS

              
                .mw-checkbox-hack-checkbox {
	position: absolute;
	// Always lower the checkbox behind the foreground content.
	z-index: -1;
	// The checkbox `display` cannot be `none` since its focus state is used for other selectors.
	opacity: 0;
}

.mw-checkbox-hack-button {
	// Labels are inlined by default but are also an icon having width and height specified.
	display: inline-block;
	// Use the hand icon for the toggle button which is actually a checkbox label.
	cursor: pointer;
}

	.mw-checkbox-hack-checkbox:focus ~ .mw-checkbox-hack-button {
		// Next two rules from OOUI, frameless, icon-only button w=idget.
		border-color: #36c;
		box-shadow: inset 0 0 0 1px #36c;
	}

	// Use the MediaWiki checkbox hack class from checkboxHack.less. This class exists on the
	// checkbox input for the menu panel.
	.checkbox-hack-checkbox:not( :checked ) ~ .checkbox-hack-target {
		// Turn off presentation so that screen readers get the same effect as visually hiding.
		// Visibility and opacity can be animated. If animation is unnecessary, use `display: none`
		// instead to avoid hidden rendering.
		visibility: hidden;
		opacity: 0;
		transform: translateX( -100% );
	}


/*  Common Formatting */

body {
  font-family: sans-serif;
}

label {
  cursor: pointer;
}

.checkbox-hack-target {
  background-color: coral;
}
              
            
!

JS

              
                /*
*   This content is licensed according to the W3C Software License at
*   https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
*   JS code for the button design pattern
*
* Original: https://www.w3.org/TR/wai-aria-practices/examples/button/js/button.js
*/

function init () {
  var actionButton = document.getElementById('checkbox-oO');
  //actionButton.addEventListener('click', activateActionButton);
  actionButton.addEventListener('keydown', actionButtonKeydownHandler);
  actionButton.addEventListener('keyup', actionButtonKeyupHandler);
}

/**
 * Activates the action button with the enter key.
 *
 * @param {KeyboardEvent} event
 */
function actionButtonKeydownHandler( event)  {
  // The action button is activated by space on the keyup event, but the
  // default action for space is already triggered on keydown. It needs to be
  // prevented to stop scrolling the page before activating the button.
  if (event.keyCode === 32) {
    event.preventDefault();
  }
  // If enter is pressed, activate the button
  else if (event.keyCode === 13) {
    event.preventDefault();
    activateActionButton();
  }
}

/**
 * Activates the action button with the space key.
 *
 * @param {KeyboardEvent} event
 */
function actionButtonKeyupHandler( event ) {
  if (event.keyCode === 32) {
    event.preventDefault();
    activateActionButton();
  }
}

function activateActionButton( checked ) {
  var checkbox = document.getElementById('checkbox-oh');
  if (checked != checkbox.checked) {
    checkbox.click();
  }
}

/**
 * Toggles the toggle button’s state between *pressed* and *not pressed*.
 *
 * @param {HTMLElement} button
 */
function toggleButtonState (button) {
  var isAriaPressed = button.getAttribute('aria-pressed') === 'true';

  button.setAttribute('aria-pressed', isAriaPressed ? 'false' : 'true');
}

window.onload = init;
              
            
!
999px

Console