cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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 Radio Buttons
</h1>
<p>
  Iterating on a simple, portable, and accessible css only solution for styling radio buttons.
</p>

<form>
  
  <label class="topcoat-radio-button__label">
    <input type="radio" name="topcoat">
    <div class="topcoat-radio-button"></div>
  </label>

  <br>
  <br>
    
  <label class="topcoat-radio-button__label">
    Label on left
    <input type="radio" name="topcoat">
    <div class="topcoat-radio-button"></div>
  </label>
    
  <br>
  <br>

  <label class="topcoat-radio-button__label">
    <input type="radio" name="topcoat">
    <div class="topcoat-radio-button"></div>
    Label on right
  </label>
    
</form>
  
<p>
  <small>
    *for fun tab to focus and use spacebar to check
  </small>
</p>


<p>To ensure that assistive technology knows the location of the radio button, we don't use <pre class="prettyprint">
  input[type=radio] {
    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 radio button but retain its dimensions and position in the document.
  <pre class="prettyprint">
    input[type=radio] {
      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;
}

input[type=radio] {
  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;
}

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

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

.topcoat-radio-button {
  position: relative;
  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-radio-button:before {
  content: '';
  position: absolute;
  box-sizing: border-box;
	width: 2rem;
	height: 2rem;
  background: #e5e9e9;
	border: 1px solid #a5a8a8;
	border-radius: 100%;
  cursor: pointer;
  
	-webkit-box-shadow: inset 0 1px #fff;
	box-shadow: inset 0 1px #fff;
}

/* Checkmark */
.topcoat-radio-button:after {
  opacity: 0;
	content: '';
	position: absolute;
  width: 1rem;
  height: 1rem;
  left: 50%;
  top: 50%;
  -webkit-transform: translate(-50%,-50%);
  background: #666666;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 100%;
  cursor: pointer;
  box-shadow: 0 1px rgba(255,255,255,0.50);
}

input[type=radio]:checked + .topcoat-radio-button:after {
	opacity: 1;
}

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

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console