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.

            
              <fieldset class="radio-switch">
  <legend>
    Settings
  </legend>
  <input type="radio" name="lol" id="public">
  <label for="public">
    On
  </label>

  <input type="radio" name="lol" id="private">
  <label for="private">
    Off
  </label>
</fieldset>

<!--
  Note:
  The problem with this implementation, specifically the use of pseudo elements to make the Switch UI, is that the UI itself is split down the middle in where a user can click to toggle the current selection.

  Ideally, the text "on" or "off" could be clicked to update the selected option...but it'd be nicer if the full toggle UI could also be clicked to toggle the options back and forth.  I'm sure this could still be done with this implemetnation, but as it stands right now, it doesn't fully allow that.
-->
            
          
!
            
              /* 
	get rid of the fieldset styling and keep 
	this all on a single line 
*/
.radio-switch {
	border: none;
	padding: 0;
	white-space: nowrap;
}

/*
	radio button groups often benefit from a legend to
	provide context as to what the different
	options pertain to. Ideally this would be visible to all
	users, but you know...
*/
.radio-switch legend {
	font-size: 2px;
	opacity: 0;
	position: absolute;
}

/*
	relative labels to help position the pseudo elements
	the z-index will be handy later, when the labels that
	overlap the visual switch UI need to be adjusted
	to allow for a user to toggle the switch without
	having to move their mouse/finger to the different
	sides of the UI
*/
.radio-switch label {
	display: inline-block;
	line-height: 2;
	position: relative;
	z-index: 2;
}

/*
	inputs set to opcacity 0 are still accessible.
	Apparently there can be issues targetting inputs with
	Dragon speech recognition software if you use the typical
	'visually-hidden' class...so might as well just avoid that issue...
*/
.radio-switch input {
	opacity: 0;
	position: absolute;
}

/*
	a 2 option toggle can only have 2 options...so instead of
	adding more classes, i'm just going to use some
	structural pseudo-classes to target them...
	cause why let all that good work go to waste?!

  the large padding is used to position the labels
  on top of the visual UI, so the switch UI itself
  can be mouse clicked or finger tapped to toggle
  the current option
*/
.radio-switch label:first-of-type {
	padding-right: 5em;
}

.radio-switch label:last-child {
	margin-left: -4.25em;
	padding-left: 5em;
}

/*
	oh focus within, I can't wait for you to have even more support.
	But you'll never be in IE11, so we're going to need a
	polyfill for you for a bit...
 */
.radio-switch:focus-within label:first-of-type:after {
	box-shadow: 0 0 0 2px #fff, 0 0 0 4px #2196f3;
}

/* polyfill class*/
.radio-switch.focus-within label:first-of-type:after {
	box-shadow: 0 0 0 2px #fff, 0 0 0 4px #2196f3;
}

/* making the switch UI.  */
.radio-switch label:first-of-type:before,
.radio-switch label:first-of-type:after {
	border: 1px solid #aaa;
	content: "";
	height: 2em;
	overflow: hidden;
	pointer-events: none;
	position: absolute;
	vertical-align: middle;
}

.radio-switch label:first-of-type:before {
	background: #fff;
	border: 1px solid #aaa;
	border-radius: 100%;
	position: absolute;
	right: -.075em;
	transform: translateX(0em);
	transition: transform .2s ease-in-out;
	width: 2em;
	z-index: 2;
}

.radio-switch label:first-of-type:after {
	background: #222;
	border-radius: 1em;
	margin: 0 1em;
	transition: background .2s ease-in-out;
	width: 4em;
}

/*
	Visually change the switch UI to match the
	checked state of the first radio button
*/
.radio-switch input:first-of-type:checked ~ label:first-of-type:after {
	background: #2196f3;
}

.radio-switch input:first-of-type:checked ~ label:first-of-type:before {
	transform: translateX(-2em);
}

/* Move the 2nd label to have a lower z-index, so when that
   option is toggled, the first label will overlay on top of the
   Switch ui, and the switch can be pressed again to toggle back
   to the prevoius state. */
.radio-switch input:last-of-type:checked ~ label:last-of-type {
	z-index: 1;
}



/*
  system defaut fonts sure do load quick...
*/
body {
	padding: 3em;
	font-family: arial;
}
            
          
!
            
              /**
  Focus within pollyfill
  Credit: https://gist.github.com/aFarkas/a7e0d85450f323d5e164
*/
(function(window, document){
  'use strict';
  var slice = [].slice;
  var removeClass = function(elem){
    elem.classList.remove('focus-within');
  };
  var update = (function(){
    var running, last;
    var action = function(){
      var element = document.activeElement;
      running = false;
      if(last !== element){
        last = element;
        slice.call(document.getElementsByClassName('focus-within')).forEach(removeClass);
        while(element && element.classList){
          element.classList.add('focus-within');
          element = element.parentNode;
        }
      }
    };
    return function(){
      if(!running){
        requestAnimationFrame(action);
        running = true;
      }
    };
  })();
  document.addEventListener('focus', update, true);
  document.addEventListener('blur', update, true);
  update();
})(window, document);
            
          
!
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