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 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.
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.
If the stylesheet 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 CSS 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.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<div style="padding: 1em">
<div class="c-cb">
<input type="checkbox" name="c_input" id="c_input_1">
<label for="c_input_1">
Option 1
</label>
<!--
this span is for the checkbox animation alone.
if a checkbox needs to be checked by default, the
current CSS will automatically animate the checkmark.
Some JavaScript could be written to add/remove on
checking/unchecking the input instead, to mitigate
this possibility of extra animation.
-->
<span class="c-cb__animated"></span>
</div>
<div class="c-cb">
<input type="checkbox" id="c_input_2" disabled>
<label for="c_input_2">
Option 2
</label>
<span class="c-cb__animated"></span>
</div>
</div>
/**
Custom styles
*/
.c-cb {
padding-left: 2em;
position: relative;
}
.c-cb > input[type="checkbox"] {
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
margin-left: -2em;
margin-top: .75em;
opacity: .00001;
position: relative;
vertical-align: top;
z-index: 2;
}
/**
* Make sure the label is only as wide as the
* inner text requires it to be.
* The label should not be a block element
* or run 100% width of its container.
* Why would someone expect to click
* white space on the opposite side of the
* screen to have a checkbox checked?
*/
.c-cb > label {
display: inline-block;
padding: .75em .5em;
vertical-align: top;
}
/**
* Note, the :before pseudo-element is the new
* "bounds" or "box" of the checkbox.
* It must be the same height, width and
* position of the native checkbox element.
*/
.c-cb > label:before,
.c-cb > input[type="checkbox"] {
height: 1.125em;
left: .125em;
width: 1.125em;
}
/**
* Base styles for use on both
* pseudo elements.
*/
.c-cb > label:before,
.c-cb > label:after,
.c-cb__animated {
border: 1px solid;
content: " ";
position: absolute;
transition:
border-color .2s ease-in-out,
box-shadow .2s ease-in-out,
transform .2s ease-in-out;
}
/**
* Styles for the custom box boundary.
*/
.c-cb > label:before {
border-color: #565656;
border-radius: 2px;
box-shadow: 0 0 0 1px #565656;
height: 1.125em;
left: .125em;
top: .825em;
width: 1.125em;
}
/**
* This recreates the "check" mark.
*/
.c-cb > label:after,
.c-cb__animated {
border: 0;
border-bottom: 4px solid #565656;
border-right: 4px solid #565656;
height: .825em;
left: .425em;
top: .825em;
transform-origin: center center;
transform: rotate(45deg) scale(0);
width: .5em;
}
.c-cb__animated {
visibility: hidden;
}
/**
* ** Defining States **
*/
.c-cb > input:checked ~ label:before {
border-color: transparent;
box-shadow: 0 0 0 2px #0d5192;
}
.c-cb > input:focus ~ label:before {
border-color: transparent;
box-shadow: 0 0 0 3px #228BEC;
}
.c-cb > input:checked ~ label:after,
.c-cb > input:checked ~ .c-cb__animated {
transform: rotate(45deg) scale(1);
}
.c-cb > input:checked:focus ~ label:after,
.c-cb > input:checked ~ .c-cb__animated {
border-color: #228BEC;
}
.c-cb > input[disabled] + label:before, // ie11
.c-cb > input[disabled] + label {
opacity: .625;
}
.c-cb > input:checked ~ .c-cb__animated {
animation: expand .8s;
}
@keyframes expand {
0% {
transform: rotate(45deg) scale(0);
opacity: 1;
visibility: visible;
}
50% {
transform: rotate(45deg) scale(2.5);
opacity: 1;
}
100% {
opacity: 0;
top: 0px;
transform: rotate(45deg) scale(2.5);
visibility: hidden;
}
}
/**
some normalization and base styling to slightly pretty up the demo
*/
input,
button,
textarea,
select {
border-radius: 0; /* may change, but start consistently */
box-sizing: border-box;
font-family: inherit;
font-size: inherit;
font-weight: inherit;
line-height: normal;
margin: 0;
overflow: visible; /* show overflow in Edge */
text-transform: none; /* remove inheritance Edge, Firefox, IE */
}
html,
body {
background: #fcfcfc;
font-family: arial;
font-size: 100%;
margin: 0;
padding: 0;
}
*,
*:before,
*:after {
box-sizing: border-box;
}
body {
line-height: 1.4;
}
/**
Notes:
* The native input is visually hidden, but not as a 1px by 1px block. It is positioned and set to an almost zero opacity on top of the custom style so that it can be discovered by certain types of screen reader navigation methods.
* The checkbox UI is recreated using :before and :after pseudo elements of the sibling <label> element.
* The checkbox's :checked, :focus and :disabled states will serve as hooks to modify the pseudo elements of the label by use of sibling selectors.
* Wrapping the input within a parent container means that it can be appropriately positioned on top of the faux checkbox UI, and the wrapper being set to position relative will keep it in place.
For full documentation about this pattern
and how the particular decisions made here
promote better UX for screen readers,
please review:
https://scottaohara.github.io/a11y_styled_form_controls/src/checkbox/
For more information on other styled native form controls,
please review:
https://scottaohara.github.io/a11y_styled_form_controls/
*/
Also see: Tab Triggers