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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 class="container">
  <p>Experimenting styling radio buttons, SVG, animation and meaningful colors. <br /> (We can change the color of label as well.) </p>
 
  <h2>Do you Agree?</h2>
  <div class="choice-option-yes">
    <input type="radio" name="choice" value="yes" id="yes">
    <label for="yes">
    <svg  xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">
  <g id="choice-radio-yes">
    <path d="M328.73,220.35c17.41-2.07,14.34,0,14.34,0L331.29,224c15.36-.52,26.12,2.07,15.88,3.11s-9.22,4.4,0,3.37" transform="translate(-320 -205)" fill="none" stroke="currentColor" stroke-width="2" stroke-miterlimit="10"/>
    <circle cx="20" cy="20" r="15" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="3"/>
  </g>
</svg>

        Yes
      </label>
  </div>
  <div class="choice-option-no">
    <input type="radio" name="choice" value="no" id="no" >
    <label for="no">
     <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">
  <g id="choice-radio-no">
    <path d="M328.73,220.35c17.41-2.07,14.34,0,14.34,0L331.29,224c15.36-.52,26.12,2.07,15.88,3.11s-9.22,4.4,0,3.37" transform="translate(-320 -205)" fill="none" stroke="currentColor" stroke-width="2" stroke-miterlimit="10"/>
    <circle cx="20" cy="20" r="15" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="3"/>
  </g>
</svg>

        No
      </label>
  </div> 
</div>
              
            
!

CSS

              
                
body {
  font-family: 'Montserrat', sans-serif;
  font-weight: 400;
  line-height: 1.5;
  background-color: black;
  color: #d6d4d4;
}
h2 {
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 10px 0;
}
.container {
  display: grid;
  grid-template-rows: 70px 50px 70px 70px;
  align-items: center;
  justify-content: center;
  width: calc(100vw - 40px);
  height: calc(100vh - 40px);
  padding: 20px;
}
svg {
  width: 40px;
  padding-right: 8px;
}
input[type="radio"] {
  opacity: 0;
  width: 0;
  height: 0;
}
.choice-option-yes,
.choice-option-no {
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

label {
  font-size: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  opacity: 0.5;
}

/* Demo setup end */

#choice-radio-yes path, #choice-radio-no path {
  opacity: 0;
}

input[type="radio"]:checked ~ label {
  opacity: 1
}
              
            
!

JS

              
                const select = function(s) {
  return document.querySelector(s);
}

const pathYes = select('#choice-radio-yes path');
const pathCircleYes = select('#choice-radio-yes circle');
const pathNo = select('#choice-radio-no path');
const pathCircleNo = select('#choice-radio-no circle');

function radioButtonChecked (path, color) {
  TweenLite.fromTo(path, 1, {opacity: 1, stroke: color, drawSVG: "0%"}, { opacity: 1, drawSVG: "100%", stroke: color} );
}

function radioButtonUnchecked (path, color) {
   TweenLite.fromTo(path, 1, {opacity: 1, stroke: color, drawSVG: "100%"}, { opacity: 0, drawSVG: "0%", stroke: color} );
}

function radioButtonInitial(path, color) {
  TweenLite.fromTo(path, 1, {stroke: color, draw: "0%" }, {stroke: color, draw: "100%"})
}

select('.choice-option-yes').onclick =  function(e) {
   radioButtonChecked(pathYes, '#00AD0C')
   radioButtonChecked(pathCircleYes, 
'#007a08');
   radioButtonUnchecked(pathNo, '#d6d4d4');
   radioButtonInitial(pathCircleNo, '#d6d4d4')
}
                                   
select('.choice-option-no').onclick = function(e) {
   radioButtonChecked(pathNo, '#c32828')
   radioButtonChecked(pathCircleNo, '#8e0d0d');
  radioButtonUnchecked(pathYes, '#d6d4d4');
   radioButtonInitial(pathCircleYes, '#d6d4d4')
}






              
            
!
999px

Console