123

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.

            
              # New Bootstrap v5 forms

A quick look at some of the major changes coming to form controls in Bootstrap 5.

## Checks

<hr class="mt-2 mb-3">

Taking a fresh pass at custom checkboxes and radios without psuedo-elements, thus replacing our previous native form control styles. By resetting the `appearance`, we should be able to style the inputs across Edge, Chrome, Firefox, and Safari.

**Differences from v4:**

- Custom form controls are the new native.
- No more custom HTML is required for the new form controls. They're 100% styled from the `<input>` itself with `appearance: none;`.
- Form controls are 25% larger, moving from `1rem` (`16px`) to `1.25em` (`20px`).
- Form controls are now built with `em`s instead of `rem`s for easy sizing.
- Instead of `position: absolute;`, `<input>`s are aligned with `float` and `margin-top` to help align and scale with sizing options.
- No more `.custom-checkbox-inline` modifier class—instead, use utilities for way more flexibility in your layouts.

These new checks and their text are aligned the same way as v4—with `padding-left` on the outer container. This is so any and all siblings to the `<input>` (like the `<label>`, help text, or validation feedback) is easily aligned.

Flexbox styles were originally attempted, but they're unnecessary and were abandoned early in favor of a `float`ed `<input>`.

### Default styles

<div class="flex-check">
  <input class="flex-check-input" type="checkbox" id="check1" checked>
  <label class="flex-check-label" for="check1">This is the new custom checkbox</label>
  <small class="text-muted d-block">Some additional help text could appear right here.</small>
</div>

<div class="flex-check">
  <input class="flex-check-input" type="checkbox" id="checkindeterminate">
  <label class="flex-check-label" for="checkindeterminate">This is an indeterminate custom checkbox</label>
  <small class="text-muted d-block">Indeterminate checkboxes must be toggled via JavaScript—there's no HTML attribute for this.</small>
</div>

<div class="flex-check">
  <input class="flex-check-input" type="checkbox" id="longcheck">
  <label class="flex-check-label" for="longcheck">This is the new custom checkbox with text that wraps to multiple lines because of a super long label that I keep adding text to so that it does that whole wrapping thing easily enough.</label>
</div>

<div class="flex-check">
  <input class="flex-check-input" type="checkbox" id="disabledcheck" disabled>
  <label class="flex-check-label" for="disabledcheck">This is the new disabled custom checkbox</label>
</div>

<br>

<div class="flex-check">
  <input class="flex-check-input" type="radio" id="radio1" name="radios" checked>
  <label class="flex-check-label" for="radio1">Custom radio that's checked</label>
</div>

<div class="flex-check">
  <input class="flex-check-input" type="radio" id="radio2" name="radios">
  <label class="flex-check-label" for="radio2">Custom radio that isn't</label>
</div>

<div class="flex-check">
  <input class="flex-check-input" type="radio" id="radio3" name="radios" disabled>
  <label class="flex-check-label" for="radio3">Custom radio that's disabled</label>
</div>

<br>

<div class="flex-check flex-switch">
  <input class="flex-check-input" type="checkbox" id="switch1">
  <label class="flex-check-label" for="switch1">Custom switch checkbox input</label>
</div>

<div class="flex-check flex-switch">
  <input class="flex-check-input" type="checkbox" id="switch2" disabled>
  <label class="flex-check-label" for="switch2">Disabled custom switch checkbox input</label>
</div>

<br>

<div class="flex-check flex-switch">
  <input class="flex-check-input" type="radio" id="switchradio1" name="switchradio">
  <label class="flex-check-label" for="switchradio1">Custom switch radio that's checked</label>
</div>

<div class="flex-check flex-switch">
  <input class="flex-check-input" type="radio" id="switchradio2" name="switchradio">
  <label class="flex-check-label" for="switchradio2">Second custom switch radio</label>
</div>

### Without label

And without labels inside the wrapper:

<div class="form-group row">
  <label class="col-md-3" for="check-no-label">External label</label>
  <div class="col-md-9">
    <div class="flex-check">
      <input class="flex-check-input" type="checkbox" id="check-no-label" checked>
    </div>
  </div>
</div>

<div class="form-group row">
  <label class="col-md-3" for="switch-no-label">External label</label>
  <div class="col-md-9">
    <div class="flex-check flex-switch">
      <input class="flex-check-input" type="checkbox" id="switch-no-label" checked>
    </div>
  </div>
</div>

### Inline

Make any checkbox, radio, or switch appear "inline" with utility classes. We recommend `.d-inline-block` and `margin` utilities (e.g., `.mr-3`) as needed.

<div class="flex-check d-inline-block mr-3">
  <input class="flex-check-input" type="checkbox" id="checkInline1" checked>
  <label class="flex-check-label" for="checkInline1">Inline checkbox</label>
</div>
<div class="flex-check d-inline-block mr-3">
  <input class="flex-check-input" type="checkbox" id="checkInline2">
  <label class="flex-check-label" for="checkInline2">Another one</label>
</div>
<div class="flex-check flex-switch d-inline-block">
  <input class="flex-check-input" type="checkbox" id="switchInline1">
  <label class="flex-check-label" for="switchInline1">Inline switch</label>
</div>

### Sizing

Built with `em` units, custom checks, radios, and switches will scale to their own `font-size`, or their containing element's (explicit or inherited) `font-size`. Here we're using a modifier class to set `font-size: 1.5rem` on the container.

<div class="flex-check flex-check-lg">
  <input class="flex-check-input" type="checkbox" id="sizingcheck1">
  <label class="flex-check-label" for="sizingcheck1">Resized custom check</label>
</div>

<div class="flex-check flex-check-lg">
  <input class="flex-check-input" type="radio" id="sizingradio1" name="sizingradios">
  <label class="flex-check-label" for="sizingradio1">Resized custom radio</label>
</div>

<div class="flex-check flex-switch flex-check-lg mb-3">
  <input class="flex-check-input" type="checkbox" id="sizingswitch1">
  <label class="flex-check-label" for="sizingswitch1">Resized custom switch checkbox</label>
</div>

Note that you could scope the sizing to the `<input>` itself, but you'll need additional styles to change the indentation of the `<label>`'s text. Alternatively, you could set a `font-size` on the wrapper and then override the `<label>`'s `font-size`.

<div class="flex-check flex-switch" style="font-size: 1.5rem;">
  <input class="flex-check-input" type="checkbox" id="sizingSwitch2">
  <label class="flex-check-label" for="sizingSwitch2" style="font-size: 1rem;">Large switch, normal label text</label>
</div>

## Selects

<hr class="mt-2 mb-3">

Without the `.form-select`, the previous `.custom-select` is going to become the default styling, providing a unified look across all platforms.

### Default styles

Below are the default and disabled selects. Disabled styles are the same as our checks—no `pointer-events` and an `opacity` change.

<select class="flex-select mb-3">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

<select class="flex-select" disabled>
  <option selected>Disabled select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

### Inline

Similar to the new checks, make selects inline with a modifier class: `.w-auto`. Selects are `inline-block` to begin with, so no need to change their `display`.

<div class="mb-3">
  <select class="flex-select w-auto mr-3">
    <option selected>Open this select menu</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
  </select>
  <div class="flex-check d-inline-block">
    <input class="flex-check-input" type="checkbox" id="selectInlineCheck">
    <label class="flex-check-label" for="selectInlineCheck">Inline checkbox</label>
  </div>
</div>

Vertical alignment may become an issue, so consider wrapping your inline form controls in some flex and margin utilities. The example below features a wrapper with `.d-flex` and `.align-items-center`, plus `.mb-0` on the inline checkbox.

<div class="d-flex align-items-center">
  <select class="flex-select w-auto mr-3">
    <option selected>Open this select menu</option>
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
  </select>
  <div class="flex-check d-inline-block mb-0">
    <input class="flex-check-input" type="checkbox" id="selectInlineCheck2">
    <label class="flex-check-label" for="selectInlineCheck2">Inline checkbox</label>
  </div>
</div>

### Sizing

Sizing should become similar to the new checks and switches as they're now built with `em`s. Below is the same select as above, but with an increased `font-size` of `1.5rem`.

<select class="flex-select mb-3" style="font-size: 1.5rem;">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

And making it smaller with `font-size: .875rem;`.

<select class="flex-select mb-3" style="font-size: .875rem;">
  <option selected>Open this select menu</option>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
</select>

### Multiple and size attributes

Adding `multple` or `size` should render the select as expected, though with (expected) limited styling of the `<option>`s.

<select class="flex-select mb-3" multiple>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
  <option value="4">Four</option>
  <option value="5">Five</option>
</select>

<select class="flex-select mb-3" size="3">
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
  <option value="4">Four</option>
  <option value="5">Five</option>
</select>

## File

<hr class="mt-2 mb-3">

<div class="flex-file">
  <input type="file" class="flex-file-input" id="customFile">
  <label class="flex-file-label" for="customFile" data-browse="Browse">Choose file</label>
</div>
            
          
!
            
              :root {
  --background: #fff;
  --foreground: #333;

  --accent-color: #fff;
  --accent-bg: var(--blue);
  // --accent-bg: var(--purple);
  
  --check-width: 1.25em;
  --check-bg-size: calc(var(--check-width) - .5em);
  --check-gutter: calc(var(--check-width) + .5em);

  --switch-width: 2em;
  --switch-gutter: calc(var(--switch-width) + .5em);
  
  --file-height: calc((.375em * 2) + 1.5em);
  
  --focus-ring: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

body {
  max-width: 48rem;
  padding: 2rem;
  margin: 0 auto 6rem;
}

h2 { margin-top: 2rem; }
h3 { margin-top: 1.5rem; }
li + li { margin-top: .25rem; }

//
// Checks and radios
//

.flex-check {
  padding-left: var(--check-gutter);
  margin-bottom: .5rem;
  min-height: 1.5rem; // font-size * line-height
}

.flex-check-input {
  -webkit-appearance: none;
  appearance: none;
  float: left;
  width: var(--check-width);
  height: var(--check-width);
  margin-top: calc((1.5em - var(--check-width)) / 2); // line-height minus check height
  margin-left: calc(var(--check-gutter) * -1);
  background-color: #fff;
  border: 1px solid rgba(0,0,0,.25);
  
  &[type="checkbox"] {
    border-radius: .25em;    
  }

  &[type="radio"] {
    border-radius: 50%;    
  }
  
  &:active {
    filter: brightness(90%);
  }
  
  &:focus {
    outline: 0;
    border-color: var(--accent-bg);
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
  }

  &:checked {
    border-color: var(--accent-bg);
    background-color: var(--accent-bg);
    background-repeat: no-repeat;
    background-position: center center;
    background-size: var(--check-bg-size);
    
    &[type="checkbox"] {
      background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23fff' d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3e%3c/svg%3e");
    }
    
    &[type="radio"] {
      background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23fff'/%3e%3c/svg%3e");
    }
  }
  
  &[type="checkbox"]:indeterminate {
    border-color: var(--accent-bg);
    background-color: var(--accent-bg);
    background-repeat: no-repeat;
    background-position: center center;
    background-size: var(--check-bg-size);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 4'%3e%3cpath stroke='%23fff' d='M0 2h4'/%3e%3c/svg%3e");
  }

  &:disabled {
    opacity: .5;
    pointer-events: none;
    filter: none;
    
    ~ .flex-check-label {
      opacity: .5;
    }
  }
}

.flex-check-label {
  margin-bottom: 0;
}


//
// Switch
//

.flex-switch {
  padding-left: var(--switch-gutter);
  
  .flex-check-input {
    width: var(--switch-width);
    margin-left: calc(var(--switch-gutter) * -1);
    background-repeat: no-repeat;
    background-position: left center;
    background-size: calc(var(--check-width) - 2px); // Get a 1px separation
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba(0,0,0,.25)'/%3e%3c/svg%3e");
    border-radius: 2em;
    transition: .2s ease-in-out;
    transition-property: background-position, background-color;
    
    &:focus {
      background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='hsla(211, 100%, 75%, 1)'/%3e%3c/svg%3e");
    }
    
    &:checked {
      background-position: right center;
      background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='rgba(255,255,255,1)'/%3e%3c/svg%3e");
    }
  }
}

.flex-check-lg {
  font-size: 1.5rem;
}


//
// New selects
//

.flex-select {
  display: inline-block;
  width: 100%;
  padding: .375em calc(.75em * 2.5) .375em .75em;
  vertical-align: middle;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 5'%3e%3cpath fill='rgba(0,0,0,.5)' d='M2 0L0 2h4zm0 5L0 3h4z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right .75em center;
  background-size: .5em auto;
  background-color: #fff;
  border: 1px solid rgba(0,0,0,.25);
  border-radius: .25em;
  -webkit-appearance: none;
  appearance: none;

  &:focus {
    outline: 0;
    border-color: var(--accent-bg);
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);

    &::-ms-value {
      // For visual consistency with other platforms/browsers,
      // suppress the default white text on blue background highlight given to
      // the selected option text when the (still closed) <select> receives focus
      // in IE and (under certain conditions) Edge.
      // See https://github.com/twbs/bootstrap/issues/19398.
      color: inherit; // does this need to be a hex value?
      background-color: #fff;
    }
  }

  &[multiple],
  &[size]:not([size="1"]) {
    height: auto;
    // padding-right: $custom-select-padding-x;
    background-image: none;
  }

  &:disabled {
    pointer-events: none;
    opacity: .5;
    // color: $custom-select-disabled-color;
    // background-color: $custom-select-disabled-bg;
  }

  // Hides the default caret in IE11
  &::-ms-expand {
    opacity: 0;
  }
}


//
// File
//

.flex-file {
  position: relative;
  display: inline-block;
  width: 100%;
  // height: var(--file-height);
}

.flex-file-input {
  position: relative;
  z-index: 2;
  width: 100%;
  // height: var(--file-height);
  margin: 0;
  opacity: 0;

  &:focus ~ .flex-file-label {
    border-color: var(--accent-bg);
    box-shadow: var(--focus-ring);
  }

  &:disabled ~ .flex-file-label {
    // background-color: $custom-file-disabled-bg;
  }

  // @each $lang, $value in $custom-file-text {
  //   &:lang(#{$lang}) ~ .custom-file-label::after {
  //     content: $value;
  //   }
  // }

  ~ .flex-file-label[data-browse]::after {
    content: attr(data-browse);
  }
}

.flex-file-label {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  z-index: 1;
  // height: var(--file-height);
  padding: .375em .75em;
  // padding: $custom-file-padding-y $custom-file-padding-x;
  background-color: #fff;
  border: 1px solid rgba(0,0,0,.25);
  border-radius: .25em;
  // @include box-shadow($custom-file-box-shadow);

  &::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    display: block;
    // height: $custom-file-height-inner;
    padding: .375em .75em;
    // padding: $custom-file-padding-y $custom-file-padding-x;
    // line-height: $custom-file-line-height;
    // color: $custom-file-button-color;
    // content: "Browse";
    background-color: rgba(0,0,0,.05);
    // @include gradient-bg($custom-file-button-bg);
    border-left: inherit;
    // @include border-radius(0 $custom-file-border-radius $custom-file-border-radius 0);
  }
}
            
          
!
            
              var checkbox = document.getElementById("checkindeterminate");
checkbox.indeterminate = 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