Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <div style="padding: 1em">

  <div class="c-cb">
    <input type="checkbox" name="c_input" id="c_input_1">
    <label for="c_input_1">
      Option 1
    </label>
    <!-- 
      this span is for the checkbox animation alone.

      if a checkbox needs to be checked by default, the 
      current CSS will automatically animate the checkmark.
      Some JavaScript could be written to add/remove on
      checking/unchecking the input instead, to mitigate
      this possibility of extra animation.
    -->
    <span class="c-cb__animated"></span>
  </div>
  
  <div class="c-cb">
    <input type="checkbox" id="c_input_2" disabled>
    <label for="c_input_2">
      Option 2
    </label>
    <span class="c-cb__animated"></span>
  </div>

</div>
              
            
!

CSS

              
                /**
  Custom styles
*/
.c-cb {
	padding-left: 2em;
	position: relative;
}

.c-cb > input[type="checkbox"] {
	-moz-appearance: none;
	-webkit-appearance: none;
	appearance: none;
	margin-left: -2em;
	margin-top: .75em;
	opacity: .00001;
	position: relative;
	vertical-align: top;
	z-index: 2;
}

/**
 * Make sure the label is only as wide as the
 * inner text requires it to be.
 * The label should not be a block element
 * or run 100% width of its container.
 * Why would someone expect to click
 * white space on the opposite side of the
 * screen to have a checkbox checked?
 */
.c-cb > label {
	display: inline-block;
	padding: .75em .5em;
	vertical-align: top;
}


/**
 * Note, the :before pseudo-element is the new
 * "bounds" or "box" of the checkbox.
 * It must be the same height, width and
 * position of the native checkbox element.
 */
.c-cb > label:before,
.c-cb > input[type="checkbox"] {
	height: 1.125em;
	left: .125em;
	width: 1.125em;
}

/**
 * Base styles for use on both
 * pseudo elements.
 */
.c-cb > label:before,
.c-cb > label:after,
.c-cb__animated {
	border: 1px solid;
	content: " ";
	position: absolute;
	transition:
		border-color .2s ease-in-out,
		box-shadow .2s ease-in-out,
		transform .2s ease-in-out;
}

/**
 * Styles for the custom box boundary.
 */
.c-cb > label:before {
	border-color: #565656;
	border-radius: 2px;
	box-shadow: 0 0 0 1px #565656;
	height: 1.125em;
	left: .125em;
	top: .825em;
	width: 1.125em;
}

/**
 * This recreates the "check" mark.
 */
.c-cb > label:after,
.c-cb__animated {
	border: 0;
	border-bottom: 4px solid #565656;
	border-right: 4px solid #565656;
	height: .825em;
	left: .425em;
	top: .825em;
	transform-origin: center center;
	transform: rotate(45deg) scale(0);
	width: .5em;
}

.c-cb__animated {
  visibility: hidden;
}


/**
 * ** Defining States **
 */
.c-cb > input:checked ~ label:before {
	border-color: transparent;
	box-shadow: 0 0 0 2px #0d5192;
}

.c-cb > input:focus ~ label:before {
	border-color: transparent;
	box-shadow: 0 0 0 3px #228BEC;
}

.c-cb > input:checked ~ label:after,
.c-cb > input:checked ~ .c-cb__animated {
	transform: rotate(45deg) scale(1);
}

.c-cb > input:checked:focus ~ label:after,
.c-cb > input:checked ~ .c-cb__animated {
	border-color: #228BEC;
}

.c-cb > input[disabled] + label:before, // ie11
.c-cb > input[disabled] + label {
	opacity: .625;
}


.c-cb > input:checked ~ .c-cb__animated {
  animation: expand .8s;
}

@keyframes expand {
  0% {
    transform: rotate(45deg) scale(0);
    opacity: 1;
    visibility: visible;
  }
  50% {
    transform: rotate(45deg) scale(2.5);
    opacity: 1;
  }
  100% {
    opacity: 0;
    top: 0px;
    transform: rotate(45deg) scale(2.5);
    visibility: hidden;
  }
}



/**
  some normalization and base styling to slightly pretty up the demo
*/

input,
button,
textarea,
select {
	border-radius: 0; /* may change, but start consistently */
	box-sizing: border-box;
	font-family: inherit;
	font-size: inherit;
	font-weight: inherit;
	line-height: normal;
	margin: 0;
	overflow: visible; /* show overflow in Edge */
	text-transform: none; /* remove inheritance Edge, Firefox, IE */
}

html,
body {
	background: #fcfcfc;
	font-family: arial;
	font-size: 100%;
	margin: 0;
	padding: 0;
}

*,
*:before,
*:after {
	box-sizing: border-box;
}

body {
	line-height: 1.4;
}
              
            
!

JS

              
                /**

Notes:
* The native input is visually hidden, but not as a 1px by 1px block.  It is positioned and set to an almost zero opacity on top of the custom style so that it can be discovered by certain types of screen reader navigation methods.
* The checkbox UI is recreated using :before and :after pseudo elements of the sibling <label> element.
* The checkbox's :checked, :focus and :disabled states will serve as hooks to modify the pseudo elements of the label by use of sibling selectors.
* Wrapping the input within a parent container means that it can be appropriately positioned on top of the faux checkbox UI, and the wrapper being set to position relative will keep it in place.

For full documentation about this pattern
and how the particular decisions made here
promote better UX for screen readers, 
please review:
https://scottaohara.github.io/a11y_styled_form_controls/src/checkbox/

For more information on other styled native form controls,
please review:
https://scottaohara.github.io/a11y_styled_form_controls/

*/
              
            
!
999px

Console