cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <h1 class="title">
  Topcoat Checkboxes
</h1>
<p>
  Iterating on a simple, portable, and accessible css only solution for styling checkboxes.
</p>

<h2>Normal</h2>

<label class="topcoat-checkbox">
  <input type="checkbox">
  <div class="topcoat-checkbox__checkmark"></div>
</label>

<br>
<br>

<label class="topcoat-checkbox">
  <input type="checkbox" disabled>
  <div class="topcoat-checkbox__checkmark"></div>
</label>  


<div class="spacer">
  <hr>
</div>

<h2>Accessibility</h2>
  
<p>
  The normal checkbox will work on modern browsers with modern screen readers. What follows is a bullet proof approach to make sure your checkbox is accessible for as many of your users as possible.
</p>
  
<label for="checkbox1" class="topcoat-checkbox">
  <input id="checkbox1" aria-label="checkbox with aria-label" type="checkbox" aria-describedby="checkbox1-description">
  <div class="topcoat-checkbox__checkmark"></div>
</label>

<br>
<br>

<label for="checkbox2" class="topcoat-checkbox">
  label
  <input id="checkbox2" type="checkbox" aria-describedby="checkbox2-description">
  <div class="topcoat-checkbox__checkmark"></div>
</label>

<br>
<br>

<label for="checkbox3" class="topcoat-checkbox">
  <input id="checkbox3" aria-labelledby="checkbox3-label" aria-describedby="checkbox3-description" type="checkbox">
  <div class="topcoat-checkbox__checkmark"></div>
  <span id="checkbox3-label">label</span> 
</label>

<br>
  
<p id="checkbox1-description">The first checkbox doesn't have a label in text, which isn't recommended, but, depending on context, could be necessary, e.g. for a checkbox in a datagrid. We use the <code class="prettyprint">aria-label</code> attribute to make sure that the checkbox is properly labelled for assistive technology like screen readers.</p>

<p id="checkbox2-description">The second checkbox uses the <code class="prettyprint">for</code> attribute to explicitly associate the <code class="prettyprint">label</code> tag with the checkbox.</p>

<p id="checkbox3-description">The third checkbox uses the <code class="prettyprint">aria-labelledby</code> attribute to explicitly associate the checkbox with a <code class="prettyprint">span</code> that provides its label and the <code class="prettyprint">aria-describedby</code> attribute to associate the checkbox with this description.</p>

<p>To ensure that assistive technology knows the location of the checkbox, we don't use <pre class="prettyprint">
  input[type=checkbox] {
    position: absolute; 
    top: -9999px; 
    left: -9999px;
  }</pre> to hide  the checkbox offscreen. Instead we use the following, inspired by <a href="https://github.com/jquery/jquery-ui/blob/master/themes/base/jquery.ui.core.css#LC17">jQuery UI's .ui-helper-hidden-accessible class</a>, to hide the checkbox but retain its dimensions and position in the document.
  <pre class="prettyprint">
    input[type=checkbox] {
      border: 0;
      clip: rect(0 0 0 0);
      height: 2rem;
      margin: 0 -2rem -2rem 0;
      overflow: hidden;
      padding: 0;
      position: absolute;
      width: 2rem;
      opacity: 0.001;
    }</pre>
</p>
  
<script src="//use.edgefonts.net/source-sans-pro:n3,n4,n6;source-code-pro:n3.js"></script>
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
            
          
!
            
              body {
  padding: 0 50px;
  background-color: #f4f4f4;
  font-family: source-sans-pro, sans-serif;
}

.title {
  letter-spacing: -.065em
}

.spacer {
  padding: 25px 0;
}

input[type=checkbox] {
  border: 0;
	clip: rect(0 0 0 0);
	height: 2rem;
	margin: 0 -2rem -2rem 0;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 2rem;
  opacity: 0.001;
}

.topcoat-checkbox {
  position: relative;
  display: inline-block;
  line-height: 2rem;
  
  -webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
}

.topcoat-checkbox__checkmark {
  display: inline-block;
  vertical-align: top;
  width: 2rem;
  height: 2rem;
  
  -webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
}

/* Background */
.topcoat-checkbox__checkmark:before {
  content: '';
  position: absolute;
  box-sizing: border-box;
	width: 2rem;
	height: 2rem;
  background: #e5e9e9;
	border: 1px solid #a5a8a8;
	border-radius: 3px;
  cursor: pointer;
  
	-webkit-box-shadow: inset 0 1px #fff;
	box-shadow: inset 0 1px #fff;
}

/* Checkmark */
.topcoat-checkbox__checkmark:after {
  opacity: 0;
	content: '';
	position: absolute;
  /* Length of check tail */
  width: 28px; 
  /* Lenght of check foot */
  height: 11px;
	background: transparent;
	border: 7px solid #666666;
	border-top: none;
	border-right: none;
	border-radius: 2px;

	-webkit-transform: rotate(-50deg);
	-moz-transform: rotate(-50deg);
	-o-transform: rotate(-50deg);
	-ms-transform: rotate(-50deg);
	transform: rotate(-50deg);
}

:checked + .topcoat-checkbox__checkmark:after {
	opacity: 1;
}

:focus + .topcoat-checkbox__checkmark:before {
  border: 1px solid #0940fd;
  -webkit-box-shadow: 0 0 0 2px #6fb5f1;
  box-shadow: 0 0 0 2px #6fb5f1;
}

:disabled + .topcoat-checkbox__checkmark:before {
  opacity: 0.3;
  cursor: default;
  pointer-events: none;
}

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console