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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!-- Inspired by http://nostyle.herokuapp.com/patterns/payment by Adam Silver -->
<!-- Inspired by https://design-system.service.gov.uk/patterns/payment-card-details/ -->
<div class="pageContent">
<h1>Payment</h1>
<p class="amountSummary">Text to go here tells user how much $money will be charged to their card, how frequently their card will be charged (once off / monthly / yearly), and what they will get. For example, <br><br>Membership: $79. Annual payment.<br>Donation amount: $25. A once off payment.</p>

<!-- Avoid browser spell checking inputs (whose type attributes are in the Text, Search, URL, or E-mail states) with spellcheck="false" https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/spellcheck on individual input elements or inherit via setting in the parent form element -->
  <!-- Any field that expects a proper name (such as first, last, or city name) can also be problematic with autocorrect enabled. According to https://uxcellence.com/2014/tweaking-automatic-form-input this attribute can be set on input elements or for the whole form -->
<form novalidate spellcheck="false" autocorrect="off">

<fieldset class="field" aria-invalid="true">
  <legend>
    <h2 class="field-legend">Donation amount</h2>
    <span class="field-hint">Donations of $2 or more are tax deductible.</span>
    <!-- Accessible error messaging https://codepen.io/stringyland/pen/ZWLBVK -->
    <span class="field-error"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/error.svg" alt="Error: " class="icon" />Select a donation amount</span>
  </legend>

  <div class="govuk-radios govuk-radios--conditional" data-module="govuk-radios">
  <div class="field-options">
    <!-- more than 2 radio options should be stacked vertically https://design-system.service.gov.uk/components/radios/#stacked-radios -->
      <div class="field-radioButton">
        <input type="radio" name="donateoptions" value="25" id="donate_r1" required>
        <label for="donate_r1">          
          $25
        </label>
      </div>    
      <div class="field-radioButton">
        <input type="radio" name="donateoptions" value="150" id="donate_r2">
        <label for="donate_r2">          
          $150
        </label>
      </div>    
    <div class="field-radioButton">
        <input type="radio" name="donateoptions" value="500" id="donate_r3">
        <label for="donate_r3">
          $500
        </label>
      </div>
    <!-- Because "other" is different, use a text divider to distinguish it - https://design-system.service.gov.uk/components/radios/#radio-items-with-a-text-divider -->
    <div class="radios__divider">or </div>
    
    <div class="group">
      <!-- radio instead of button -->
      <div class="field-radioButton panel-control">
        <input type="radio" name="donateoptions" value="other" id="donate_rother">
        <label for="donate_rother">
          Other
          <i class="icon-arrow-down" aria-hidden="true"></i><i class="icon-arrow-up" hidden aria-hidden="true"></i>
        </label>
      </div>  
      <div class="hidden-all" id="panel2">
        <div class="field">
          <label for="donateOtherAmount">
            <span class="field-label">Other amount</span>
            <span class="field-error"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/error.svg" alt="Error: " class="icon" />Donation amount must be 1 or more</span> 
          </label>
          <!-- When using onscreen keyboards inputmode="decimal" will make these fields easier to fill out. See https://css-tricks.com/everything-you-ever-wanted-to-know-about-inputmode/#article-header-id-3 -->
          <input id="donateOtherAmount" name="donateOtherAmount" type="number" required min="1" step="any" inputmode="decimal">
        </div>
      </div>
      </div>
  </div>    
  
  </div>
</fieldset>
<hr>
<fieldset>
  <legend><h2 class="field-legend">Enter card details</h2></legend>
  
<div class="field">
  <label for="cardnumber">
    <span class="field-label">Card number</span>
    <!--<span class="field-hint">The long number on the front of your card.</span>-->
    <span class="field-error"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/error.svg" alt="Error: " class="icon" />Enter your card number</span>
  </label>
  <!-- When using onscreen keyboards inputmode="numeric" will make these fields easier to fill out. See https://css-tricks.com/everything-you-ever-wanted-to-know-about-inputmode/#article-header-id-1 -->
  <input name="cardnumber" id="cardnumber" autocomplete="cc-number" type="text" required pattern="[0-9]*" inputmode="numeric" minlength="13" maxlength="19">
</div>

<fieldset class="field" aria-invalid="true">
  <legend>
    <span class="field-legend">Expiry</span>
    <span class="field-hint">eg 09/21</span>
  </legend>
    <label class="field-error" for="cc_exp_month" id="cc_exp_month_error"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/error.svg" alt="Error: " class="icon" />Enter a month, like 09</label>
    <label class="field-error" for="cc_exp_year" id="cc_exp_year_error"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/error.svg" alt="Error: " class="icon" />Enter a year, like 21</label>
  <div class="field-monthWrapper">
    <label for="cc_exp_month" id="cc_exp_month_label">Month</label>
    <!-- pattern attribute derived from http://html5pattern.com/Dates and tested successfully in iOS 13.1 for optimal onscreen keyboard displays -->
    <input name="cc_exp_month" id="cc_exp_month" autocomplete="cc-exp-month" class="field-monthBox" type="text" required pattern="(0[1-9]|1[012])" inputmode="numeric" minlength="2" maxlength="2" aria-labelledby="cc_exp_month_label cc_exp_month_error">
    <!-- CAUTION: https://dequeuniversity.com/rules/axe/3.3/form-field-multiple-labels -->
  </div>
    
  <div class="visual-separatorWrapper">/</div>
  
  <div class="field-yearWrapper">
    <label for="cc_exp_year" id="cc_exp_year_label">Year</label>
    <input name="cc_exp_year" id="cc_exp_year" autocomplete="cc-exp-year" class="field-yearBox" type="text" required pattern="[0-9]*" inputmode="numeric" minlength="2" maxlength="2" aria-labelledby="cc_exp_year_label cc_exp_year_error">
    <!-- CAUTION: https://dequeuniversity.com/rules/axe/3.3/form-field-multiple-labels -->
  </div>  
</fieldset>

<!-- Old version of this form used a single input for the card expiry. -->
<!-- Note that the canonical format for cc-exp is a valid month string, for example 2014-12 https://www.w3.org/TR/html52/sec-forms.html#sec-autofill 
<div class="field">
  <label for="expiry">
    <span class="field-label">Expiry</span>
    <span class="field-hint">MMYY</span>
    <span class="field-error">Enter 2 digits for the month followed by 2 digits for the year.</span>
  </label>
  <input name="expiry" id="expiry" autocomplete="cc-exp" type="text" required pattern="[0-9]*" inputmode="numeric" minlength="4" maxlength="4">
</div>
-->

<div class="field">
  <label for="name_on_card">
    <span class="field-label">Name on card</span>
    <!--<span class="field-hint">Example: <samp>John Snow</samp></span>-->
    <span class="field-error">
      <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/error.svg" alt="Error: " class="icon" />Enter the full name as printed on the credit card
    </span>
  </label>
  <input name="name_on_card" id="name_on_card" autocomplete="cc-name" type="text" required>
  <!-- Including the autocapitalize="characters" makes a virtual keyboard automatically uppercase all letters of each word. Setting to ="words" should ease entering multi-word proper nouns on mobile but it is buggy! See https://developers.google.com/web/updates/2015/04/autocapitalize -->
</div>

<div class="field">
  <label for="cardSecurityCode">
    <span class="field-label">Card security code</span>
<!-- Progressive enhancement: a script to identify AMEX card number (starts with 34 or 37) then:
 1. swap cc-cscHint text to indicate where to find card security code on front of AMEX cards
 2. adjust minlength & maxlength values on cardSecurityCode, both to 4 for AMEX OR both to 3 for all others
 Ref https://www.regular-expressions.info/creditcard.html -->
    <span class="field-hint" id="cc-cscHint_nonAMEX">The last 3 digits on the back of the card</span>
    <span class="field-hint" id="cc-cscHint_AMEX">The last 4 digits after the card number on the front</span>
    <span class="field-error"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/error.svg" alt="Error: " class="icon" />Enter your card security code</span>
  </label>
  <input name="cardSecurityCode" id="cardSecurityCode" autocomplete="cc-csc" type="text" required pattern="[0-9]*" inputmode="numeric" minlength="3" maxlength="4">
</div>
</fieldset>

<button type="submit" class="primaryButton" name="pay">Pay now</button>
  <!-- trigger an accessible modal dialog to tell users to wait while we process payment ... -->
</form>
</div>
            
          
!
            
              :root {
  font-family: sans-serif;
  line-height: 1.5;
  --white: #fff;
  --light: #eee;
  --dark: #111;
}

html {
  font-size: 62.5%; /* https://snook.ca/archives/html_and_css/font-size-with-rem */
  /* With html set at 62.5% and body at 1.8rem overrides the Bootstrap size 14px! */
}
body {
  font-family: Roboto,helvetica,arial,sans-serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  font-size: 1.8rem;
  background-color: var(--light);
  color: var(--dark);
}
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  color: inherit;
}
/* Check for colour-only indicators with a greyscale filter. At https://youtu.be/Wq2-cZ-vZBc?t=11m24s Julie Grundy describes how she uses a grayscale filter to check for colour-only indicators. 
body {
  filter: grayscale(100%);
}*/
.pageContent {
  padding: 20px 10px;
}

/* Text fields to support WCAG 2.1 Success Criterion 1.4.12: Text Spacing https://adrianroselli.com/2019/09/under-engineered-text-boxen.html */
textarea,
input {
  font: inherit;
  letter-spacing: inherit;
  word-spacing: inherit;
  line-height: inherit;
}

[type=checkbox], [type=date], [type=email], [type=file], [type=number], [type=password], [type=radio],  .field-radioButton label[for], button.panel-control, [type=search], [type=submit], [type=tel], [type=text], select, textarea {
  background-color: var(--white);
  color: var(--dark);
  border: 2px solid #222;
  border-radius: 4px;
  max-width: 100%; /* avoid spill over on narrow viewports */
  max-width: 420px;
  padding: 0.3rem 1ch; /* Using ch as per http://revoltpuppy.com/articles/89/using-ch-an-underappreciated-css-length */
}

[maxlength], [autocomplete], [type=number], .field-radioButton label {
  font-family: Consolas, “Andale Mono”, “Lucida Console”, “Lucida Sans Typewriter”, Monaco, “Courier New”, “monospace”; /* explanation for a monospaced font stack coming later */
  padding: .3em 1ch; /* Using ch as per http://revoltpuppy.com/articles/89/using-ch-an-underappreciated-css-length */
  width: 100%; /* keep inputs with small maxlength eg 4 at their intended witdth */
  max-width: 100%; /* avoid spill over on narrow viewports */
}

input[maxlength="19"], #salutation {
  width: calc(19ch + 2ch + 1ch + 2px); /* maxlength + padding + breathing space + border */
}
input[maxlength="12"], #salutation, #donateOtherAmount {
  width: calc(12ch + 2ch + 1ch + 2px); /* maxlength + padding + breathing space + border */
}
input[maxlength="10"]{
  width: calc(10ch + 2ch + 1ch + 2px); /* maxlength + padding + breathing space + border */
}
[maxlength="4"]{
  width: calc(4ch + 2ch + 1ch + 2px); /* maxlength + padding + breathing space + border */
}
[maxlength="3"]{
  width: calc(3ch + 2ch + 1ch + 2px); /* maxlength + padding + breathing space + border */
}

/* https://css-tricks.com/snippets/css/turn-off-number-input-spinners/ */
[type=number]::-webkit-inner-spin-button, 
[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}
/* https://jwatt.org/2013/12/11/input-type-number-coming-to-mozilla/ */
[type=number] {
    -moz-appearance:textfield;
}

[type=radio][name="donateoptions"] { /* visually hides the radio */
  opacity: 0;
  position: absolute;
}
.field-radioButton, .radios__divider {
  text-align: center;
}
.radios__divider {
  padding-right: 4ch;
}
.field-radioButton label, button.panel-control {
  font-family: inherit;
  background-color: #EFEFEF; 
  /* not accessible yet - need a border for contrast and states */
  /*
  Design is needed for the following states:
static
hover
focus
invalid
checked/selected
checked/selected & focus (this is optional)
  
  Russ Weakley has an example design system with components in different states (accessible) at https://russmaxdesign.github.io/states/ including form controls.
  */
  /* adapted from https://scottaohara.github.io/a11y_styled_form_controls/ */
  transition: .2s ease-in-out;
}
.field-radioButton input:hover ~ label, .field-radioButton :hover {
  cursor: pointer;
  background-color: #ffe3ad;
}
/* basic visual styles */
fieldset, legend {
  border: none;
  padding: 0;
}
.field, p.amountSummary {
    max-width: 26em;
    margin-bottom: 1.5rem;
    padding: 0;
}
.field-legend {
    display: block;
    font-weight: 700;
}
legend, label, input, label span, button.panel-control {
  display:block;
  width: 100%;
  font-size: 2.125rem;
  line-height: 1.38889;
}
label[for], button {
  cursor: pointer; /* I adopted this from https://patterns.boilerform.design/#group-label-component-default It helps mouse users realise they can click anywhere on the label */
}
.field-label {
  font-weight: 700;
}
label span, .field-radioButton, .radios__divider {
  margin-bottom: .4rem;
}
.radios__conditional.radios__conditional--hidden {
  padding-left: calc(2px + 1ch);
    border-left: 2px solid #222;
    margin-left: 2px;  
}
.field-hint, .field-error {
  color: #595959; /* #595959 is the minimum grey on white background to pass AA and AAA for a contrast ratio of 7:1 */
  font-size: 1.9rem;
  font-weight: normal;
  display: block;
  margin-bottom: .4rem;
}
.field-monthWrapper, .field-yearWrapper {
    width: 4em;
}
.visual-separatorWrapper, .field-monthWrapper, .field-yearWrapper {
    display: inline-block;
}
.visual-separatorWrapper {
    min-width: 1em;
    text-align: center;
}

/* Inclusively Hidden https://www.scottohara.me/blog/2017/04/14/inclusively-hidden.html by @scottohara */
/* ie9+ */
.sr-only:not(:focus):not(:active) {
  clip: rect(0 0 0 0); 
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap; 
  width: 1px;
}

/* error styles */
.icon {
  /* To size and position a SVG (!) icon inline before validation error message text. https://codepen.io/stringyland/pen/ZWLBVK */
  width: 1em;
  height: 1em;
  margin-right: .4ch;
  margin-bottom: -.16em;
}
.field-error {
  color: #D4351C; /* color #D4351C from https://design-system.service.gov.uk/components/error-message/ is, IMO, better contrast with both background and nearby body text/labels than #b00f1f from http://nostyle.herokuapp.com/patterns/fix-form-errors */
  font-weight: 700;
  /* display: none; /* toggle this comment to hide validation messages */
}
[aria-invalid="true"] { /* An aria-invalid="true" should be injected onto each invalid input via a validation script. The HTML5 :invalid state is excessive as any input with a required attribute is invalid on first run. */
  border-color: #D4351C;
}

/* focus style */

/* 
@supports (box-shadow: 0 0 1px 4px #ffbf47;) {
  /* testing in Safari on iOS 13 shows that box-shadow is not supported. https://www.filamentgroup.com/lab/a11y-links.html is where I learnt that using @supports we can design with progressive enhancement for browsers that do */
  
  [type=checkbox]:focus, [type=date]:focus, [type=email]:focus, [type=file]:focus, [type=number]:focus, [type=password]:focus, [type=radio]:focus, [type=search]:focus, [type=submit]:focus, [type=tel]:focus, [type=text]:focus, button:focus, button:hover, select:focus, textarea:focus, [type=radio][name="donateoptions"]:focus + label, [type=radio][name="donateoptions"]:hover + label {
    outline: 0;
    box-shadow: 0 0 1px 4px #ffbf47;
  }

  [type=radio][name="donateoptions"]:checked + label {
    outline: 0;
    box-shadow: 0 0 1px 4px #ffbf47;
    background: #ffbf47;
  }
/*}*/

@media (min-width: 37.5em)
.primaryButton {
    font-size: 1.125em;
    line-height: 1.38889;
}
.primaryButton {
    font: inherit;
    border: none;
    appearance: none;
    -webkit-appearance: none;
    font-size: 1em;
    line-height: 1.5625;
    padding: 1rem 4ch;
    background-color: #0074d9;
    color: #fff;
    width: inherit;
}
button:active {
  background-color: #fff;
    color: #0074d9;
}

/* Julie Grundy's basic show/hide pattern to toggle the Other amount https://codepen.io/stringyland/pen/vYBXrGv */
.hidden-all {
  display: none;
}
.group [aria-expanded="true"] {
  margin: 1rem 0;
  border-left: 2px solid;
  padding-left: 1ch;
}
.panel-control i {
  float: right;
}
/* Icon font stuff from here on */
@font-face {
  font-family: 'icomoon';
  src:
    url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/icomoon.ttf') format('truetype'),
    url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/236520/icomoon_copy.svg') format('svg');
  font-weight: normal;
  font-style: normal;
}

i {
  /* use !important to prevent issues with browser extensions that change fonts */
  font-family: 'icomoon' !important;
  speak: none;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1.2;
  
  /* Better Font Rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.icon-arrow-up:before {
  content: "\ea41";
}
.icon-arrow-down:before {
  content: "\ea43";
}
            
          
!
            
              /* https://zellwk.com/blog/style-hover-focus-active-states/ */
document.addEventListener('click', event => {
  if (event.target.matches('button')) {
    event.target.focus()
  }
})

/* Julie Grundy's basic show/hide pattern to toggle the Other amount https://codepen.io/stringyland/pen/vYBXrGv */
const group = document.querySelector('.group')
// const toggle2 = group.querySelector('button');
const toggle2 = group.querySelector('label[for="donate_rother"]');
const panel2 = group.querySelector('#panel2');
var donateopt = document.getElementsByName('donateoptions') // want to use this var to see what radio is selected ...

// Must update ARIA attribute as well as panel for buttons
toggle2.addEventListener("click", function(e) {
  if (panel2.classList.contains("hidden-all")) {
    panel2.classList.remove("hidden-all");
    panel2.setAttribute('aria-expanded','true');
    updateIcon(this, 'up');    
  } else {
    panel2.classList.add("hidden-all");
    panel2.setAttribute('aria-expanded', 'false');
    updateIcon(this, 'down')
    // clear after any other radio[name="donateoptions"] selected
  }
});
// utility functions
function updateIcon(whichOne, direction) {
  if (direction === 'up') {
    whichOne.children[0].setAttribute('hidden', 'true');
    whichOne.children[1].removeAttribute('hidden');
  } else {
    whichOne.children[0].removeAttribute('hidden');
    whichOne.children[1].setAttribute('hidden', 'true');
  }
}
            
          
!
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.

Console