HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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 checked">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 checked">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 checked">Bed
<input type="checkbox" checked>
<i class="fas 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 checked">Taxi
<input type="radio" checked>
<i class="fas 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); });
});
Also see: Tab Triggers