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.
<button id="toggle">Toggle</button>
<div class="clock ticking">
<div class="bigcog">
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">1</p></div>
<div class="face back"><p class="text">10</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">7</p></div>
<div class="face back"><p class="text">4</p></div>
</div>
</div>
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">5</p></div>
<div class="face back"><p class="text">8</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">11</p></div>
<div class="face back"><p class="text">2</p></div>
</div>
</div>
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">3</p></div>
<div class="face back"><p class="text">12</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">9</p></div>
<div class="face back"><p class="text">6</p></div>
</div>
</div>
</div>
<div class="bigcog">
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">1</p></div>
<div class="face back"><p class="text">10</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">7</p></div>
<div class="face back"><p class="text">4</p></div>
</div>
</div>
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">5</p></div>
<div class="face back"><p class="text">8</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">11</p></div>
<div class="face back"><p class="text">2</p></div>
</div>
</div>
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">3</p></div>
<div class="face back"><p class="text">12</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">9</p></div>
<div class="face back"><p class="text">6</p></div>
</div>
</div>
</div>
<div class="bigcog">
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">1</p></div>
<div class="face back"><p class="text">10</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">7</p></div>
<div class="face back"><p class="text">4</p></div>
</div>
</div>
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">5</p></div>
<div class="face back"><p class="text">8</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">11</p></div>
<div class="face back"><p class="text">2</p></div>
</div>
</div>
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">3</p></div>
<div class="face back"><p class="text">12</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">9</p></div>
<div class="face back"><p class="text">6</p></div>
</div>
</div>
</div>
<div class="bigcog">
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">1</p></div>
<div class="face back"><p class="text">10</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">7</p></div>
<div class="face back"><p class="text">4</p></div>
</div>
</div>
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">5</p></div>
<div class="face back"><p class="text">8</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">11</p></div>
<div class="face back"><p class="text">2</p></div>
</div>
</div>
<div class="smallcog">
<div class="head">
<div class="face front"><p class="text">3</p></div>
<div class="face back"><p class="text">12</p></div>
</div>
<div class="head">
<div class="face front"><p class="text">9</p></div>
<div class="face back"><p class="text">6</p></div>
</div>
</div>
</div>
</div>
body {
background-color: #3c404b;
}
/* Move the button out of the way */
button {
position: fixed;
top: 1em;
right: 1em;
padding: 1em;
}
/* The main container */
.clock {
position: relative;
width: 40em;
height: 40em;
margin: 2em auto;
background-color: rgb(46, 49, 58);
border-radius: 50%;
border: 1em solid #2C2F38;
box-shadow: 0 0 1em #181818;
/* Can't remember what this does */
transform-style: preserve-3d;
}
/* Initial clock styles (Showing 1's) */
.clock .bigcog {
position: absolute;
width: 40%;
height: 40%;
background-color: #282B33;
border-radius: 50%;
box-shadow: 0 0 1em #1F1E1E;
}
.clock .bigcog:nth-child(1) { right: 51%; bottom: 51%; }
.clock .bigcog:nth-child(2) { left: 51%; bottom: 51%; }
.clock .bigcog:nth-child(3) { top: 51%; right: 51%; }
.clock .bigcog:nth-child(4) { left: 51%; top: 51%; }
.clock .smallcog {
position: absolute;
width: 58%;
height: 58%;
background-color: #23252C;
border-radius: 50%;
box-shadow: 0 0 1em #161616;
}
.clock .smallcog { transform-origin: 100% 100%; right: 50%; bottom: 50%; }
.clock .head {
position: absolute;
width: 40%;
height: 40%;
}
.clock .head { transform-origin: 100% 100%; right: 50%; bottom: 50%; }
.clock .face {
position: absolute;
width: 100%;
height: 100%;
background-color: black;
color: white;
border-radius: 75% 25% 0% 25%;
border-style: solid;
border-color: white;
border-width: 0.1em 0 0 0.1em;
backface-visibility: hidden;
overflow: hidden;
background-color: #15171B;
box-shadow: 0 0 1em #1A1A1A;
}
.clock .text {
display: block;
position: absolute;
bottom: -100%;
right: -100%;
width: 200%;
height: 200%;
padding: 0;
margin: 0;
line-height: 1.2;
font-weight: 900;
font-size: 600%;
text-align: center;
}
/* Initial part rotations (For showing 1's) */
/* Rotation animation rule is
if the end is greater than the start, it'll rotate clockwise;
if the end is less than the start, it's counterclockwise.
http://stackoverflow.com/questions/10473080/how-to-control-css3-animation-rotate-direction#comment13530782_10473150 */
/* We want clockwise so end needs to be greater than start */
/* The heads are rotated -2520 and -2700 so that we can run a keyframe animation
for several rotations and keep the heads spinning clockwise (See rule above) */
.clock .head:nth-child(1) { transform: rotateZ(-2520deg); }
.clock .head:nth-child(2) { transform: rotateZ(-2700deg); }
/* The faces are back to back (only 1 visible at a time) */
.clock .face.front { transform: rotateZ(180deg) rotateY(0deg); }
.clock .face.back { transform: rotateZ(180deg) rotateY(-180deg); }
/* Rotate the smallcogs so that the smallcog that has 1 in it is in the center of the clock.
Could just rotate the bigcogs here but that makes animation far more complicated
(transforms need to be complete, any that aren't specified are lost, which makes animation of just 1 transform property tricky
so we would need 4x the number of animations to retain each bigcog's rotateZ) */
.clock .bigcog:nth-child(1) .smallcog:nth-child(1) { transform: rotateZ(180deg); }
.clock .bigcog:nth-child(1) .smallcog:nth-child(2) { transform: rotateZ(60deg); }
.clock .bigcog:nth-child(1) .smallcog:nth-child(3) { transform: rotateZ(300deg); }
.clock .bigcog:nth-child(2) .smallcog:nth-child(1) { transform: rotateZ(270deg); }
.clock .bigcog:nth-child(2) .smallcog:nth-child(2) { transform: rotateZ(150deg); }
.clock .bigcog:nth-child(2) .smallcog:nth-child(3) { transform: rotateZ(30deg); }
.clock .bigcog:nth-child(3) .smallcog:nth-child(1) { transform: rotateZ(90deg); }
.clock .bigcog:nth-child(3) .smallcog:nth-child(2) { transform: rotateZ(330deg); }
.clock .bigcog:nth-child(3) .smallcog:nth-child(3) { transform: rotateZ(210deg); }
.clock .bigcog:nth-child(4) .smallcog:nth-child(1) { transform: rotateZ(0deg); }
.clock .bigcog:nth-child(4) .smallcog:nth-child(2) { transform: rotateZ(240deg); }
.clock .bigcog:nth-child(4) .smallcog:nth-child(3) { transform: rotateZ(120deg); }
/* Position the text on the faces so that whichever text is in the center position is the right way up */
.clock .bigcog:nth-child(1) .text { transform: rotateZ(0deg); }
.clock .bigcog:nth-child(2) .text { transform: rotateZ(270deg); }
.clock .bigcog:nth-child(3) .text { transform: rotateZ(90deg); }
.clock .bigcog:nth-child(4) .text { transform: rotateZ(180deg); }
/* Ticking Animation */
/* Rotate the bigcogs to give the impression the smallcogs are rotating */
.clock.ticking .bigcog { animation: rotate-1turn-3steps 3s linear infinite; }
/* Flip from one face to another. They have to use seperate animations because one starts
at 0deg and one at -180deg and animations must be absolute - not relative */
.clock.ticking .face.front { animation: flip-1turn-2steps 2s linear infinite; }
.clock.ticking .face.back { animation: flip-1turn-2steps-alt 2s linear infinite; }
/* Rotate the head. In order to make this work we need to use keyframes to complete 5 180deg rotations,
a full 360deg rotation, 5 more 180deg rotations and another full 360deg rotation to bring us back to the start.
The interspersed full rotations allow all 12 values to be display and then go back to 1.
The relative vs absolute thing applies here too. */
.clock.ticking .head:nth-child(1) { animation: rotate-5half-1full-x2 12s linear infinite; }
.clock.ticking .head:nth-child(2) { animation: rotate-5half-1full-x2-alt 12s linear infinite; }
/* The keyframe definitions */
/* Full turn with 2 pauses starting at 0 */
@keyframes rotate-1turn-3steps {
from { transform: rotateZ(0deg); }
16.666% { transform: rotateZ(120deg); }
33.333% { transform: rotateZ(120deg); }
50% { transform: rotateZ(240deg); }
66.666% { transform: rotateZ(240deg); }
83.333% { transform: rotateZ(360deg); }
to { transform: rotateZ(360deg); }
}
/* Flip halfway, pause, finish flip. Starting at 0 */
@keyframes flip-1turn-2steps {
from { transform: rotateZ(180deg) rotateY(0deg); }
25% { transform: rotateZ(180deg) rotateY(180deg); }
50% { transform: rotateZ(180deg) rotateY(180deg); }
75% { transform: rotateZ(180deg) rotateY(360deg); }
to { transform: rotateZ(180deg) rotateY(360deg); }
}
/* Flip halfway, pause, finish flip. Starting at -180 */
@keyframes flip-1turn-2steps-alt {
from { transform: rotateZ(180deg) rotateY(-180deg); }
25% { transform: rotateZ(180deg) rotateY(0deg); }
50% { transform: rotateZ(180deg) rotateY(0deg); }
75% { transform: rotateZ(180deg) rotateY(180deg); }
to { transform: rotateZ(180deg) rotateY(180deg); }
}
/* 5 half rotations, 1 full, 5 half, 1 full. Starting at -2520 (0deg minus 7 full turns) */
@keyframes rotate-5half-1full-x2 {
from { transform: rotateZ(-2520deg); }
4.166% { transform: rotateZ(-2340deg); }
8.333% { transform: rotateZ(-2340deg); }
12.5% { transform: rotateZ(-2160deg); }
16.666% { transform: rotateZ(-2160deg); }
20.833% { transform: rotateZ(-1980deg); }
25% { transform: rotateZ(-1980deg); }
29.166% { transform: rotateZ(-1800deg); }
33.333% { transform: rotateZ(-1800deg); }
37.5% { transform: rotateZ(-1620deg); }
41.666% { transform: rotateZ(-1620deg); }
45.833% { transform: rotateZ(-1260deg); } /* Full turn */
50% { transform: rotateZ(-1260deg); }
54.166% { transform: rotateZ(-1080deg); }
58.333% { transform: rotateZ(-1080deg); }
62.5% { transform: rotateZ(-900deg); }
66.666% { transform: rotateZ(-900deg); }
70.833% { transform: rotateZ(-720deg); }
75% { transform: rotateZ(-720deg); }
79.166% { transform: rotateZ(-540deg); }
83.333% { transform: rotateZ(-540deg); }
87.5% { transform: rotateZ(-360deg); }
91.666% { transform: rotateZ(-360deg); }
95.833% { transform: rotateZ(-0deg); } /* Full Turn */
to { transform: rotateZ(-0deg); }
}
/* 5 half rotations, 1 full, 5 half, 1 full. Starting at -2700 (-180deg minus 7 full turns) */
@keyframes rotate-5half-1full-x2-alt {
from { transform: rotateZ(-2700deg); }
4.166% { transform: rotateZ(-2520deg); }
8.333% { transform: rotateZ(-2520deg); }
12.5% { transform: rotateZ(-2340deg); }
16.666% { transform: rotateZ(-2340deg); }
20.833% { transform: rotateZ(-2160deg); }
25% { transform: rotateZ(-2160deg); }
29.166% { transform: rotateZ(-1980deg); }
33.333% { transform: rotateZ(-1980deg); }
37.5% { transform: rotateZ(-1800deg); }
41.666% { transform: rotateZ(-1800deg); }
45.833% { transform: rotateZ(-1440deg); } /* Full Turn */
50% { transform: rotateZ(-1440deg); }
54.166% { transform: rotateZ(-1260deg); }
58.333% { transform: rotateZ(-1260deg); }
62.5% { transform: rotateZ(-1080deg); }
66.666% { transform: rotateZ(-1080deg); }
70.833% { transform: rotateZ(-900deg); }
75% { transform: rotateZ(-900deg); }
79.166% { transform: rotateZ(-720deg); }
83.333% { transform: rotateZ(-720deg); }
87.5% { transform: rotateZ(-540deg); }
91.666% { transform: rotateZ(-540deg); }
95.833% { transform: rotateZ(-180deg); } /* Full Turn */
to { transform: rotateZ(-180deg); }
}
(function() {
var clock = document.querySelector('.clock');
var button = document.getElementById("toggle");
var toggle = function() {
clock.classList.toggle("ticking");
};
button.addEventListener('click', toggle);
})();
Also see: Tab Triggers