Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                
<h1>Pay your bill</h1
<form aria-label="Pay your bill">
  <fieldset>
    <legend>
      Select an amount
    </legend>
    <ul>
      <li>
        <label for="alpha" class="checkbox">
          <input type="checkbox" name="options" id="alpha" value="full">
          Pay in full: $386.00
        </label>      
      </li>
      <li>
        <div  id="bravo-label" class="checkbox label">
          <input aria-label="Other amount" type="text" placeholder="Other Amount" id="other-amount" />
        </div>      
      </li>
    </ul>
  </fieldset>

  <button class="submit" disabled>
    Pay my bill
  </button>
</form>


<h2>Why mostly this works, but is quite complicated</h2>

<p>It looks like radio buttons, but there is really only one checkbox to check "Pay in Full"</p>

<p>Everything else is smoke and mirrors that you have to explain to your developers.</p>

<p>The second "radio button" is only an input. On entering an Other amount, the Pay in Full checkbox is unchecked.</p>

<p>We have to differentiate between keyboard focus and mouse clicks now.</p>

<p>Let's say that you deliver this, extensive annotations and work with the dev team to get this right. What are the chances a new developer will be able to add another "Pay minimum" option without breaking the UX?</p>
              
            
!

CSS

              
                *:focus {
  outline-offset: 4px;
}

$icon-checkbox: "data:image/svg+xml,%0A%3Csvg height='100px' width='100px' fill='white' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 20' x='0px' y='0px'%3E%3Ctitle%3Echeckmark%3C/title%3E%3Cg data-name='Layer 2'%3E%3Cg data-name='Layer 1'%3E%3Cpath d='M22.76,1.34l-2.15,2c-.68.72-1.39,1.4-2,2.13a46.43,46.43,0,0,0-3.65,4.56A36.5,36.5,0,0,0,12,15a26.45,26.45,0,0,0-1.1,2.59c-.16.44-.3.87-.43,1.31a9.59,9.59,0,0,0-.27,1.19L6.27,20v0a3.62,3.62,0,0,0-.08-.51A5.83,5.83,0,0,0,6,18.84a12.41,12.41,0,0,0-.48-1.37,18.5,18.5,0,0,0-1.43-2.66,23.55,23.55,0,0,0-1.88-2.49C1.54,11.53.78,10.78,0,10l.54-.7.54-.7.46.3c.79.54,1.56,1.1,2.3,1.71A24.7,24.7,0,0,1,6.38,13a23.63,23.63,0,0,1,1.66,2c.3-.58.63-1.15,1-1.71a40.22,40.22,0,0,1,3.67-5A47.16,47.16,0,0,1,17,3.88c.74-.7,1.54-1.34,2.31-2l.05,0L21.68,0l.54.67Z'%3E%3C/path%3E%3C/g%3E%3C/g%3E%3C/svg%3E";


html {
  background-color: #eee;
  font-family: arial;
}
body {
  max-width: 420px;
  margin: 0px auto;
}

ul, li {
  list-style-type: none;
  margin: 0;
  padding: 0;
}



fieldset {
  border: none;
  padding: 0;
}
legend {
  font-weight: bold;
  margin-bottom: .5rem;
}

input[type=text] {
  font-size: 1rem;
  line-height: 1rem;
  padding: .25rem;
  border: 1px solid #777;
  border-radius: 2px;
}

// Place the checkbox on top of the pseudo checkbox to account for dragging in VO/Talkback
input[type=checkbox] {
  width: 1.5rem;
  height: 1.5rem;
  cursor: pointer;
  opacity: 0;
  grid-column: 1;
  grid-row: 1;
}

label.checkbox,
.checkbox {
  display: grid;
  grid-template-columns: 3rem 1fr;
  padding: 1rem;
  align-items:  center;
  margin-bottom: .25rem;
  background: #fff;
  line-height: 2rem;
  border-radius: .5rem;
  cursor: pointer;
  text-align: right;
  
  &:before {
    content: '';
    display: block;
    height: 1.5rem;
    width: 1.5rem;
    border-radius: 1.5rem;
    grid-column: 1;
    border: 2px solid #2978F6;
    grid-row: 1;
  }
  
  &:has(input[type=checkbox]:checked),
  &.checked {
    &:before {
      background-color: #2978F6;
      background-position: center center;
      background-size: 80% 80%; 
      background-repeat: no-repeat;
      box-shadow: inset 0 0 0 .25rem #fff;
    }
  }
  &:has(input[type=checkbox]:focus-visible) {
    &:before {
      outline: 2px solid #2978F6;
      outline-offset: 1px;
    }
  }
}

button {
  padding: 1rem 2rem;
  font-size: 1rem;
  color: #fff;
  line-height: 2rem;
  font-weight: bold;
  margin-top: 1rem;
  background: #2978F6;
  border: none;
  border-radius: 3rem;
  transition: .2s;
  cursor: pointer;
  
  &:active {
    background: #1F5EC1;
  }
  
  &:disabled {
    background: #999;
  }
}

input {
  text-align: right;
  width: 8rem;
  display: inline-block;
  place-self: end;
}

              
            
!

JS

              
                function checkOtherAmount() {
  if ($("input#other-amount").is(":placeholder-shown")) {
    // The placeholder is displayed
    $(".submit").attr('disabled', 'disabled'); // Disable submit
  } else {
    // The placeholder is not displayed
    $(".submit").removeAttr('disabled'); // Field has value
  }
}

// If other amount field is clicked, change radio choice
$('#other-amount, #bravo-label').click(function() {
  $('#alpha').prop('checked', false);
  $('#other-amount').focus(); // Focus the input field
  checkOtherAmount() 
  if( !$('#bravo-label').hasClass('checked')) {
    $('#bravo-label').addClass('checked');  
  }
});

// On starting to type, enable the submit button
$('input#other-amount').keypress(function() {
  checkOtherAmount();
  $('#alpha').prop('checked', false);
  
  if( !$('#bravo-label').hasClass('checked')) {
    $('#bravo-label').addClass('checked');  
  }

});

$('input[id="alpha"]').on('change', function() {
  // If alpha is UNchecked, check the Other
  if ( !$("input#alpha").is(":checked")) {
    $('#bravo-label').addClass('checked');
  } else {
    $('#bravo-label').removeClass('checked');
    $('#other-amount').val(''); // Empty other amount
    $(".submit").removeAttr('disabled'); // Field has value
  }  
});


$(".submit").click(function() {
  alert("Great success");
});

              
            
!
999px

Console