css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <header>
  <a href="https://fontawesome.com/" target="_blank"><h3><i class="fab fa-font-awesome"></i>Font Awesome</h3></a>
</header>
<main class="container">
  <div class="row">
    <div class="col-12 text-center">
      <h1 class="text-center mb-0">Custom Checklists</h1>
		<a id="open-modal-top" href="#" id="steps-cta"><i class="far fa-clipboard-list"></i><span class="d-none d-sm-inline">Step-by-Step </span>Guide</a>
    </div>
  </div>
  <div class="row">
    <div class="col-12 pb-0">
      <h4 class="text-center mb-0">Standard</h4>
    </div>
  </div>
  <div class="row lists">
    <div class="col-sm-6 col-md-4 offset-md-2 list-standard">
      <h2>Checklists</h2>
      <label class="checkbox">One
        <input type="checkbox" checked>
        <i class="fas fa-check-square"></i>
      </label>
      <label class="checkbox">Two
        <input type="checkbox">
        <i class="far fa-square"></i>
      </label>
      <label class="checkbox">Three
        <input type="checkbox">
        <i class="far fa-square"></i>
      </label>
      <label class="checkbox">Four
        <input type="checkbox">
        <i class="far fa-square"></i>
      </label>
    </div>
    <div class="col-sm-6 col-md-4 col-lg-3 list-standard">
      <h2>Radio Buttons</h2>
      <label class="checkbox">One
        <input type="radio" checked>
        <i class="fas fa-dot-circle"></i>
      </label>
      <label class="checkbox">Two
        <input type="radio">
        <i class="far fa-circle"></i>
      </label>
      <label class="checkbox">Three
        <input type="radio">
        <i class="far fa-circle"></i>
      </label>
      <label class="checkbox">Four
        <input type="radio">
        <i class="far fa-circle"></i>
      </label>
    </div>
  </div>
  <div class="row">
    <div class="col-12 pt-0 pb-0">
      <h4 class="text-center mb-0">Custom</h4>
    </div>
  </div>
  <div class="row lists">
    <div class="col-sm-6 col-md-4 offset-md-2 list-custom">
      <h2>Amenities</h2>
      <label class="checkbox green">Verified hosts
        <input type="checkbox">
        <i class="far fa-badge-check"></i>
      </label>
      <label class="checkbox">Bed
        <input type="checkbox" checked>
        <i class="far fa-bed"></i>
      </label>
      <label class="checkbox">Bath
        <input type="checkbox">
        <i class="far fa-bath"></i>
      </label>
      <label class="checkbox">Outlets
        <input type="checkbox">
        <i class="fas fa-plug"></i>
      </label>
    </div>
    <div class="col-sm-6 col-md-4 col-lg-3 list-custom">
      <h2>Transportation</h2>
      <label class="checkbox">Taxi
        <input type="radio" checked>
        <i class="far fa-taxi"></i>
      </label>
      <label class="checkbox">Truck
        <input type="radio">
        <i class="far fa-truck"></i>
      </label>
      <label class="checkbox">Train
        <input type="radio">
        <i class="far fa-train"></i>
      </label>
      <label class="checkbox">Plane
        <input type="radio">
        <i class="far fa-plane"></i>
      </label>
    </div>
  </div>
</main>
<footer>
  <a href="https://www.w3schools.com/howto/howto_css_custom_checkbox.asp" target="_blank" title="W3Schools How To Article"><i class="far fa-link"></i>W3Schools</a><a id="open-modal" href="#"><i class="far fa-question-circle"></i>Step-by-Step</a>
</footer>
<aside id="modal-wrapper" style="display: none;">
  <div id="modal">
    <div id="modal-inner">
      <h3>A JavaScript (jQuery) Solution to Custom Checklists</h3>
      <p>* This method assumes and requires you are using <a href="https://fontawesome.com" target="_blank" title="Font Awesome 5">Font Awesome 5</a> and have a <a href="https://fontawesome.com/pricing" target="_blank" title="Font Awesome 5 Pro">Pro license</a> for full access to all available icons and weight classes.</p>
      <hr><br>
      <ol>
        <li>
          <p>Set up an event listener for your custom lists. Make sure to target the appropriate list if you have multiple lists on the same page/form and want to use different styling for each.</p>
          <pre><code class="javascript">$('.custom-checklist').on('click', '[type="checkbox"], [type="radio"]', function() {});</code></pre>
        </li>
        <li>
          <p>Check whether the list being interacted with is a checkbox list or radio button list, and if it is a checkbox list, check whether the checkbox is being checked or unchecked.</p>
          <pre><code class="javascript">$('.custom-checklist').on('click', '[type="checkbox"], [type="radio"]', function() {
  if ($(this).attr('type') == 'checkbox') { // checkbox list
    if ($(this).is(':checked')) {} // checkbox being checked
  } else {} // checkbox being unchecked
  else if ($(this).attr('type') == 'radio') {} // radio button list
});</code></pre>
        </li>
        <li>
          <p>On click, if the checkbox/radio is being checked, apply the checked styling using the data-icon and data-prefix attributes on the dynamically generated SVG element for that icon. If you are using a radio button list, make sure to unstyle all sibling radio buttons within the adjacent labels, and if a checkbox is being unchecked, apply the unchecked styling the same way as checked.</p>
          <pre><code class="javascript">$('.custom-checklist').on('click', '[type="checkbox"], [type="radio"]', function() {
  if ($(this).attr('type') == 'checkbox') { // checkbox list
    if ($(this).is(':checked')) { // checkbox being checked, style as checked
      $(this).siblings('[data-icon]')
        .attr({
          'data-icon': 'check-square',
          'data-prefix': 'fas'
        })
        .parent().addClass('checked');
    } else { // checkbox being unchecked, style as unchecked
      $(this).siblings('[data-icon]')
        .attr({
          'data-icon': 'square',
          'data-prefix': 'far'
        })
        .parent().removeClass('checked');
    }
  } else if ($(this).attr('type') == 'radio') { // radio button list
    $(this).siblings('[data-icon]')
      .attr({
        'data-icon': 'dot-circle',
        'data-prefix': 'fas'
      })
      .parent()
      .addClass('checked')
      .siblings().each(function() {
        $(this)
          .removeClass('checked');
        .children('[data-icon]')
          .attr({
            'data-icon': 'circle',
            'data-prefix': 'far'
          });
      });
  }
});</code></pre>
        </li>
        <li>
          <p>If you are using Font Awesome 5's CSS solution instead of the standard JS+SVG solution, simply modify this function to work with the Font Awesome 5 classes and weights as explained in the Font Awesome 5's official CSS <a href="https://fontawesome.com/how-to-use/on-the-web/referencing-icons/basic-use" target="_blank" title="Font Awesome 5 CSS Basic Use">documentation</a></p>
          <pre><code class="javascript">$('.custom-checklist').on('click', '[type="checkbox"], [type="radio"]', function() {
  if ($(this).attr('type') == 'checkbox') { // checkbox list
    if ($(this).is(':checked')) { // checkbox being checked, style as checked
      $(this).siblings('i')
        .removeClass('far, fa-square')
        .addClass('fas, fa-check-square')
        .parent().addClass('checked');
    } else { // checkbox being unchecked, style as unchecked
      $(this).siblings('i')
        .removeClass('fas, fa-check-square')
        .addClass('far, fa-square')
        .parent().removeClass('checked');
    }
  } else if ($(this).attr('type') == 'radio') { // radio button list
    $(this).siblings('i')
      .removeClass('far, fa-circle')
      .addClass('fas, fa-dot-circle')
      .parent()
      .addClass('checked')
      .siblings().each(function() {
        $(this)
          .removeClass('checked');
        .children('i')
          .removeClass('fas, fa-dot-circle')
          .addClass('far, fa-circle')
      });
  }
});</code></pre>
        </li>
        <li>
          <p>To build a custom checklist with different icons, set the different icons in the HTML and then change the weight of the icons from fal/far to fas to fill the icon when checked or selected. Any additional stylistic customizations can be made your CSS stylesheet. For a more robust demonstration of how this code would be built out, look at and play with the JavaScript for this pen.</p>
        </li>
      </ol>
      <hr>
      <p>The web is a beautiful place if you'd only open your browser. Checklists should be no exception. Want to take it one step further? Check out Codrops article on SVG <a href="https://tympanus.net/codrops/2013/10/15/animated-checkboxes-and-radio-buttons-with-svg/" target="_blank" title="Animated Checkboxes and Radio Buttons with SVG">animated checklists</a>.</p>
    </div>
    <a id="close-modal" href="#"><i class="fas fa-times"></i></a>
  </div>
</aside>
            
          
!
            
              @media (min-width: 768px) {
	.container {
		max-width: 720px !important;
	}
}

body {
	padding: 64px 15px 15px;
	font-family: "Nunito", arial;
	font-weight: 600;
	color: #455a64;
	background-color: #f1f3f5;
}

a {
	color: #adb5bd;
	text-decoration: none;
}

a:hover {
	color: #339af0;
	text-decoration: none;
}

header, footer {
	text-align: center;
}

header {
	margin-bottom: 32px;
}

footer {
	margin-top: 24px;
}

header a, footer a {
	display: inline-block;
	padding: 0 14px;
}

footer a {
	font-size: 16px;
}

footer a:not(:last-child) {
	border-right: 2px dashed #c9cfd4;
}

header [data-icon], footer [data-icon] {
	box-sizing: content-box;
}

header [data-icon] {
	padding-right: 12px;
}

footer [data-icon], #open-modal-top [data-icon] {
	padding-right: 8px;
	box-sizing: content-box;
}

.container {
	position: relative;
	padding: 64px 15px;
	background-color: #fff;
	border-radius: .25rem;
	box-shadow: 0 5px 10px rgba(0,0,0,.05);
	overflow: hidden;
}

.container:before, #modal-inner:before, .container:after {
	content: " ";
	position: absolute;
	background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/1580009/confetti.svg?vsn=d);
	background-position: top;
	background-repeat: repeat-x;
	width: 100%;
	height: .75rem;
	left: 0;
}

.container:before, #modal-inner:before { top: 0; }
.container:after { bottom: 0; } 

.row + .row [class*="col-"] {
	padding: 32px;
}

h1 { color: #ff7502; }

h2 {
	margin-bottom: 16px;
	font-size: 18px;
	color: #90a4ae;
	letter-spacing: 4px;
	text-transform: uppercase;
	font-weight: 800;
	white-space: nowrap;
}

h4 {
	font-size: 20px;
	font-weight: 700;
	color: #51646e;
	text-transform: uppercase;
	letter-spacing: 3px;
}

.checkbox {
	display: block;
	position: relative;
	padding-left: 32px;
	margin-bottom: 12px;
	cursor: pointer;
	font-size: 22px;
	user-select: none;
	transition: padding-left 0.15s ease-in-out;
}

.checkbox:hover {
	padding-left: 35px;
}

.checkbox input {
	position: absolute;
	opacity: 0;
	cursor: pointer;
}

.row.lists [data-icon] {
	position: absolute;
	top: 2px;
	left: 0;
	height: 25px;
	width: 25px;
	color: #78909c;
}

.checkbox:hover [data-icon] {
	color: #81d4fa;
}

.checkbox:hover,
.checkbox.checked,
.checkbox.checked [data-icon] {
	color: #03a9f4;
}

.checkbox.green:hover [data-icon] {
	color: #66ef90;
}

.checkbox.green:hover,
.checkbox.green.checked,
.checkbox.green.checked [data-icon] {
	color: #03d343;
}

#modal-wrapper {
	display: flex;
	align-items: center;
	justify-content: center;
	position: fixed;
	top: 0;
	left: 0;
	width: 100vw;
	height: 100vh;
	background-color: rgba(241, 243, 245, 0.85);
}

#modal {
	display: block;
	position: relative;
	width: 90vw;
	max-width: 900px;
	height: 90vh;
	overflow: visible;
	border-radius: .25rem;
	box-shadow: 0 5px 10px rgba(0,0,0,.05);
	background: #fff;
}

#modal-inner {
	position: absolute;
	top: 0;
	left: 0;
	width: 100%;
	height: 100%;
	padding: calc(32px + 1vw);
	overflow: scroll;
}

#modal-wrapper ol {
	list-style: none;
	counter-reset: item;
}

#modal-wrapper li {
	counter-increment: item;
	margin-bottom: 5px;
	position: relative;
}

#modal-wrapper li:before {
	content: counter(item);
	background: #339af0;
	border-radius: 100%;
	color: white;
	width: 28px;
	height: 28px;
	font-size: 16px;
	text-align: center;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	display: flex;
	position: absolute;
	top: -3px;
	left: -8px;
	transform: translateX(-100%);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

pre code.hljs {
	padding: 15px;
	border-radius: 5px;
	overflow: scroll;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

#open-modal, #close-modal {
	cursor: pointer;
}

#close-modal {
	display: flex;
	height: 36px;
	width: 36px;
	background: #ef272f;
	border-radius: 50%;
	position: absolute;
	top: 0;
	right: 0;
	transform: translate(50%, -50%) scale(1.001);
	z-index: 999;
	text-align: center;
	align-items: center;
	justify-content: center;
	font-size: 22px;
	color: #fff;
	box-shadow: 0 5px 10px -3px rgba(255, 255, 255,.5), 0 5px 10px -3px rgba(0, 0, 0,.5);
	transition: all 0.1s ease-in-out;
}

#close-modal:hover {
	transform: translate(50%, -50%) scale(1.15);
}

#close-modal:hover:active {
	transform: translate(50%, -50%) scale(0.85);
}
            
          
!
            
              $(function() {
	$('input[type="checkbox"], input[type="radio"]').each(function() {
		if ($(this).closest('[class*="list-"]').is('.list-standard')) {
			if ($(this).is(':checked')) {
				$(this).siblings('[data-icon]').attr('data-prefix', 'fas').closest('.checkbox').addClass('checked');
				if ($(this).is('[type="checkbox"]')) {
					$(this).siblings('[data-icon]').attr('data-icon', 'check-square');
				} else if ($(this).is('[type="radio"]')) {
					$(this).siblings('[data-icon]').attr('data-icon', 'dot-circle').closest('.checkbox').siblings('.checkbox').removeClass('checked').children('[type="radio"]').prop('checked', false).siblings('[data-icon]').attr({'data-icon': 'circle', 'data-prefix': 'far'});
				}
			} else {
				$(this).siblings('[data-icon]').attr('data-prefix', 'far').closest('.checkbox').removeClass('checked');
				if ($(this).is('[type="checkbox"]')) {
					$(this).siblings('[data-icon]').attr('data-icon', 'square');
				} else if ($(this).is('[type="radio"]')) {
					$(this).siblings('[data-icon]').attr('data-icon', 'circle');
				}
			}
		} else if ($(this).closest('[class*="list-"]').is('.list-custom')) {
			if ($(this).is(':checked')) {
				$(this).siblings('[data-icon]').attr('data-prefix', 'fas').closest('.checkbox').addClass('checked');
				if ($(this).is('[type="radio"]')) {
					$(this).siblings('[data-icon]').closest('.checkbox').siblings('.checkbox').removeClass('checked').children('[type="radio"]').prop('checked', false).siblings('[data-icon]').attr('data-prefix', 'far');
				}
			} else {
				$(this).siblings('[data-icon]').attr('data-prefix', 'far').closest('.checkbox').removeClass('checked');
			}
		}
	});
	$('input[type="checkbox"], input[type="radio"]').on('change', function() {
		if ($(this).closest('[class*="list-"]').is('.list-standard')) {
			if ($(this).is(':checked')) {
				$(this).siblings('[data-icon]').attr('data-prefix', 'fas').closest('.checkbox').addClass('checked');
				if ($(this).is('[type="checkbox"]')) {
					$(this).siblings('[data-icon]').attr('data-icon', 'check-square');
				} else if ($(this).is('[type="radio"]')) {
					$(this).siblings('[data-icon]').attr('data-icon', 'dot-circle').closest('.checkbox').siblings('.checkbox').removeClass('checked').children('[type="radio"]').prop('checked', false).siblings('[data-icon]').attr({'data-icon': 'circle', 'data-prefix': 'far'});
				}
			} else {
				$(this).siblings('[data-icon]').attr('data-prefix', 'far').closest('.checkbox').removeClass('checked');
				if ($(this).is('[type="checkbox"]')) {
					$(this).siblings('[data-icon]').attr('data-icon', 'square');
				} else if ($(this).is('[type="radio"]')) {
					$(this).siblings('[data-icon]').attr('data-icon', 'circle');
				}
			}
		} else if ($(this).closest('[class*="list-"]').is('.list-custom')) {
			if ($(this).is(':checked')) {
				$(this).siblings('[data-icon]').attr('data-prefix', 'fas').closest('.checkbox').addClass('checked');
				if ($(this).is('[type="radio"]')) {
					$(this).siblings('[data-icon]').closest('.checkbox').siblings('.checkbox').removeClass('checked').children('[type="radio"]').prop('checked', false).siblings('[data-icon]').attr('data-prefix', 'far');
				}
			} else {
				$(this).siblings('[data-icon]').attr('data-prefix', 'far').closest('.checkbox').removeClass('checked');
			}
		}
	});
	// open & close modal
	$('#open-modal, #open-modal-top').on('click', function(e) {
		e.preventDefault();
		$('aside').fadeIn(200);
	});
	$('#close-modal').on('click', function(e) {
		e.preventDefault();
		$('aside').fadeOut(200);
	});
	// generating code blocks for walkthrough modal
	$('pre code').each(function(i, block) { hljs.highlightBlock(block); });
});
            
          
!
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