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.
<h1>Pure CSS Tower of Hanoi</h1>
<form>
<div class="discs">
<input id="one" type="text" tabindex="-1" readonly>
<input name="one" type="radio" tabindex="-1" checked>
<input name="one" type="radio" tabindex="-1">
<input name="one" type="radio" tabindex="-1">
<label for="one"></label>
<div class="disc one"></div>
<input id="two" type="text" tabindex="-1" readonly>
<input name="two" type="radio" tabindex="-1" checked>
<input name="two" type="radio" tabindex="-1">
<input name="two" type="radio" tabindex="-1">
<label for="two"></label>
<div class="disc two"></div>
<input id="three" type="text" tabindex="-1" readonly>
<input name="three" type="radio" tabindex="-1" checked>
<input name="three" type="radio" tabindex="-1">
<input name="three" type="radio" tabindex="-1">
<label for="three"></label>
<div class="disc three"></div>
<input id="four" type="text" tabindex="-1" readonly>
<input name="four" type="radio" tabindex="-1" checked>
<input name="four" type="radio" tabindex="-1">
<input name="four" type="radio" tabindex="-1">
<label for="four"></label>
<div class="disc four"></div>
<input id="five" type="text" tabindex="-1" readonly>
<input name="five" type="radio" tabindex="-1" checked>
<input name="five" type="radio" tabindex="-1">
<input name="five" type="radio" tabindex="-1">
<label for="five"></label>
<div class="disc five"></div>
<input id="six" type="text" tabindex="-1" readonly>
<input name="six" type="radio" tabindex="-1" checked>
<input name="six" type="radio" tabindex="-1">
<input name="six" type="radio" tabindex="-1">
<label for="six"></label>
<div class="disc six"></div>
<input id="zero" type="text" tabindex="-1" readonly>
<div class="spacer a"></div>
<div class="separator ab"></div>
<div class="spacer b"></div>
<div class="separator bc"></div>
<div class="spacer c"></div>
<div class="tower a"></div>
<div class="tower b"></div>
<div class="tower c"></div>
<div class="win">You win! :)</div>
</div>
<div class="bottom"></div>
<button type="reset">New Game</button>
</form>
/* Controls/Logic */
label,
input {
position: absolute;
top: -10vmin;
margin: 0;
border: 0;
padding: 0;
width: 30vmin;
height: 52.5vmin;
cursor: pointer;
opacity: 0;
pointer-events: none;
-webkit-tap-highlight-color: transparent;
}
input:nth-child(6n + 2),
input:checked + input + input + label {
left: 0;
}
input:nth-child(6n + 3),
input:checked + input + label {
left: 30vmin;
}
input:nth-child(6n + 4),
input:checked + label {
left: 60vmin;
}
label,
input:hover,
input[readonly]:focus + input,
input[readonly]:focus + input + input,
input[readonly]:focus + input + input + input {
pointer-events: initial;
}
input[readonly],
input:nth-child(6n + 2):checked ~ input:nth-child(6n + 2),
input:nth-child(6n + 3):checked ~ input:nth-child(6n + 3),
input:nth-child(6n + 4):checked ~ input:nth-child(6n + 4) {
pointer-events: none;
}
#one ~ input,
#one ~ label {
z-index: 6;
}
#two ~ input,
#two ~ label {
z-index: 5;
}
#three ~ input,
#three ~ label {
z-index: 4;
}
#four ~ input,
#four ~ label {
z-index: 3;
}
#five ~ input,
#five ~ label {
z-index: 2;
}
#six ~ input,
#six ~ label {
z-index: 1;
}
input#zero {
z-index: 7;
}
input#zero:focus {
pointer-events: none;
}
input[readonly]:focus + input:checked ~ #zero {
left: 0;
pointer-events: initial;
}
input[readonly]:focus + input + input:checked ~ #zero {
left: 30vmin;
pointer-events: initial;
}
input[readonly]:focus + input + input + input:checked ~ #zero {
left: 60vmin;
pointer-events: initial;
}
/* Discs */
.discs {
position: relative;
display: flex;
flex-flow: column wrap;
justify-content: flex-end;
margin: 10vmin auto 0;
width: 90vmin;
height: 35vmin;
}
.disc {
z-index: 1;
border-radius: 1vmin;
height: 4vmin;
pointer-events: none;
transition: order 0.3s step-end;
}
input:checked + input + input + label + .disc {
order: 3;
}
input:checked + input + label + .disc {
order: 6;
}
input:checked + label + .disc {
order: 9;
}
input:focus + input:checked + input + input + label + .disc {
order: 1;
transition: order 0s;
animation: float 3s ease-in-out infinite alternate;
}
input:focus + input + input:checked + input + label + .disc {
order: 4;
transition: order 0s;
animation: float 3s ease-in-out infinite alternate;
}
input:focus + input + input + input:checked + label + .disc {
order: 7;
transition: order 0s;
animation: float 3s ease-in-out infinite alternate;
}
@keyframes float {
50% {
transform: translateY(-1vmin);
}
}
input:focus + input:hover + input + input + label + .disc,
input + input:active + input + input + label + .disc {
order: 1;
}
input:focus + input + input:hover + input + label + .disc,
input + input + input:active + input + label + .disc {
order: 4;
}
input:focus + input + input + input:hover + label + .disc,
input + input + input + input:active + label + .disc {
order: 7;
}
.one {
margin: 0 10vmin;
width: 10vmin;
background: linear-gradient(to right, #eea668, #ed7e1d, #e67e22);
}
.two {
margin: 0 8vmin;
width: 14vmin;
background: linear-gradient(to right, #8ac4ea, #0f9fff, #3498db);
}
.three {
margin: 0 6vmin;
width: 18vmin;
background: linear-gradient(to right, #f0d775, #fc0, #e6bd19);
}
.four {
margin: 0 4vmin;
width: 22vmin;
background: linear-gradient(to right, #666, #000, #333);
}
.five {
margin: 0 2vmin;
width: 26vmin;
background: linear-gradient(to right, #7ee2a8, #09f16a, #2ecc71);
}
.six {
width: 30vmin;
background: linear-gradient(to right, #f2a097, #ff3a24, #e74c3c);
}
/* Spacers/Separators */
.spacer {
width: 30vmin;
height: 1px;
flex-grow: 0;
pointer-events: none;
transition: flex 0.3s;
}
.separator {
width: 0;
height: 100%;
}
.a {
order: 2;
}
.ab {
order: 3;
}
.b {
order: 5;
}
.bc {
order: 6;
}
.c {
order: 8;
}
input[readonly]:focus + input:hover ~ .a,
input[readonly]:focus + input + input:hover ~ .b,
input[readonly]:focus + input + input + input:hover ~ .c {
transition: flex 0s;
flex-grow: 1;
}
input[readonly]:focus + input:checked ~ .a,
input[readonly]:focus + input + input:checked ~ .b,
input[readonly]:focus + input + input + input:checked ~ .c {
flex-grow: 1;
}
/* Winning */
.win {
z-index: 7;
position: absolute;
left: 0;
right: 0;
top: -10vmin;
bottom: -7.5vmin;
color: #966f33;
font-family: Arial, sans-serif;
font-size: 6vmin;
line-height: 17.5vmin;
opacity: 0;
pointer-events: none;
transition: opacity 0.3s;
}
input:nth-child(6n + 4):checked ~ input:nth-child(6n + 4):checked ~ input:nth-child(6n + 4):checked ~ input:nth-child(6n + 4):checked ~ input:nth-child(6n + 4):checked ~ input:nth-child(6n + 4):checked ~ .win {
opacity: 1;
pointer-events: initial;
}
/* Everything Else */
body {
margin: 0;
background-color: #f8f8f8;
}
h1 {
margin: 0;
padding: 5vmin;
color: rgba(0, 0, 0, 0.5);
font-family: Arial, sans-serif;
font-size: 7.5vmin;
font-weight: lighter;
text-align: center;
background: linear-gradient(to right, rgba(150, 111, 51, 0.4), rgba(150, 111, 51, 0.2)),
repeating-linear-gradient(to right, #eec487, #eec487 3vmin, #f3cf9a 3vmin, #f3cf9a 6vmin, #f8d8a2 6vmin, #f8d8a2 9vmin, #f1ca88 9vmin, #f1ca88 12vmin, #f4d09e 12vmin, #f4d09e 15vmin, #faddb0 15vmin, #faddb0 18vmin, #eec88a 18vmin, #eec88a 21vmin);
}
form {
text-align: center;
}
.tower {
position: absolute;
top: 7.5vmin;
border-radius: 1vmin;
width: 5vmin;
height: 30vmin;
background: linear-gradient(to right, #d7b889, #b27315, #966f33);
}
.a {
left: 12.5vmin;
}
.b {
left: 42.5vmin;
}
.c {
left: 72.5vmin;
}
.bottom {
position: relative;
display: block;
margin: 0 auto;
border-radius: 1vmin;
width: 95vmin;
height: 7.5vmin;
background: linear-gradient(to right, rgba(255, 255, 255, 0.3), transparent),
linear-gradient(#b27315, #966f33 13%, #faddb0 14.5%, #faddb0 27.5%, #966f33 29%, #966f33 42%, #faddb0 43.5%, #d7b889 56.5%, #966f33 58%, #966f33 71%, #d7b889 72.5%, #d7b889 85.5%, #966f33 87%, #b27315);
}
button {
margin: 7.5vmin auto;
border: none;
border-radius: 1vmin;
width: 35vmin;
height: 10vmin;
font-size: 4vmin;
color: rgba(0, 0, 0, 0.5);
background: linear-gradient(to right, #c39550, #966f33);
outline: none;
cursor: pointer;
transition: background 0.3s;
}
button:hover {
background: linear-gradient(to right, #caa163, #a77b39);
}
button:active {
background: linear-gradient(to right, #cf9844, #9e6f29);
}
// ¯\_(ツ)_/¯
Also see: Tab Triggers