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.

Quick-add: + add another resource

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.

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
Loading ..................

Console