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 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.
- let max = 10; //Edit this, purposefully low to show what happens when max is reached. 1000 is fine for me, 10000 isn't
#counter
- for (let turn = 1; turn <= max; turn++)
input(type="checkbox" tabindex="-1")
.blankdec
.blankinc
.result
:root {
--background:white;
--background_alt:#E2E2E2;
--text:black;
--red:#D8334A;
--red_alt:#BF263C;
--green:#A0D468;
--green_alt:#8CC152;
}
body {
@include dark { //Dark theme, find toggle bottom right in the pen
--background:#16181D;
--background_alt:#313742;
--text:white;
--red:#BF263C;
--red_alt:#D8334A;
--green:#8CC152;
--green_alt:#A0D468;
}
display:grid;
place-items:center;
height:100vh;
counter-reset: section;
background:var(--background);
transition:.25s;
#counter {
display:grid;
grid-template-rows:80px 40px auto;
grid-gap:10px;
grid-template-areas:"inc" "dec" "value";
width:200px;
padding:10px;
border:2px solid var(--background_alt);
border-radius:20px;
//transform:scale(2); //For video for twitter for followers
transition:.25s;
.counter {
position:fixed;
top:0px;
}
.blankinc, .blankdec { //Shown when there isn't a checkbox to put in its place
place-items:center;
opacity:.5;
border-radius:10px;
cursor:not-allowed;
&.blankinc {
grid-area:inc;
background:var(--green);
}
&.blankdec {
grid-area:dec;
background:var(--red);
}
}
.result {
grid-area:value;
text-align:center;
color:var(--text);
font-size:3rem;
font-family: 'Quicksand', sans-serif;
transition:.25s;
&:before {
content:counter(section);
}
}
input {
position:relative;
z-index:1; //Above blank divs
appearance:none;
grid-area:inc; //Overwitten when decrementing
border-radius:10px;
cursor:pointer;
&:before, &:not(:checked):after { //Icon, only unchecked needs both
content:'';
position:absolute;
top:50%;
left:50%;
transform:translate(-50%, -50%);
width:40px;
height:10px;
background:var(--background);
border-radius:10px;
transition:.25s;
}
&:not(:checked):after {
transform:translate(-50%, -50%) rotate(90deg);
}
&:checked {
counter-increment: section;
grid-area:dec; //Checkboxes go under the decrement button and are stacked such that last is top
//By default inputs are not stacked at the top
background:var(--red);
box-shadow:0 0 0 1px var(--background); //This ensures that the checkboxes below don't show through at the corners giving a pixelated look, as they aren't hidden;
animation:checked .25s;
transition:box-shadow .25s;
&:hover {
background:var(--red_alt);
}
}
&:checked+input:not(:checked), //First unchecked checkbox after checked ones
&:first-child:not(:checked) { //Or first if unchecked
background:var(--green);
&:hover {
background:var(--green_alt);
}
&~input { //All inputs (all unchecked) after are hidden
display:none;
}
}
}
}
}
/*
Explanation:
There are a series of checkboxes, when a checkbox is checked it uses `counter-increment: section;` to increment the counter, in essence it allows counting of checked checkboxes. The buttons are checkboxes that change position, with green unchecked at the top and moving to the red checked
The action happens on the boundary of the checked checkboxes on top and the unchecked checkboxes under (it's possible all checkboxes are checked or unchecked, in which no checkboxes may be present on top or bottom and a default blank div is shown)
...
[x] <- These are stacked on the bottom under those after
[x] <- These are stacked on the bottom under those after
[x] <- These are stacked on the bottom with this checkbox clickable as it is stacked on top
[ ] <- These placed on top with this checkbox clickable as others are hidden
[ ] <- These placed on the top but are hidden
[ ] <- These placed on the top but are hidden
...
Checkboxes are stacked by using css grid where multiple elements given the same grid area will stack where the last element is clickable.
With this the checked checkboxes are ordered in a way that is easy to deal with and can be assigned to the decrement area and left. Just need to add a small background coloured shadow to hide the checkboxes stacked under the top giving the corners an ugly pixelated look.
The unchecked checkboxes if left would stack such that the last checkbox would be checked. With the ability to see upward at the checked checkboxes it just requires finding a checked checkbox followed by an unchecked one and select all inputs to hide.
*/
Also see: Tab Triggers