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.
<div class="toy">
<form class="ball">
<div class="window"></div>
<div class="eight">
<span>8</span>
</div>
<div class="answers">
<!-- Affirmatives -->
<input id="affirmative1" type="radio" name="answer" required>
<div class="answer up">It is<br>certain</div>
<input id="affirmative2" type="radio" name="answer" required>
<div class="answer up">It is<br>decidedly<br>so</div>
<input id="affirmative3" type="radio" name="answer" required>
<div class="answer down">Without<br>a<br>doubt</div>
<input id="affirmative4" type="radio" name="answer" required>
<div class="answer up">Yes<br>definitely</div>
<input id="affirmative5" type="radio" name="answer" required>
<div class="answer down">You may<br>rely<br>on it</div>
<input id="affirmative6" type="radio" name="answer" required>
<div class="answer down">As I<br>see it,<br>yes</div>
<input id="affirmative7" type="radio" name="answer" required>
<div class="answer up">Most<br>likely</div>
<input id="affirmative8" type="radio" name="answer" required>
<div class="answer down">Outlook<br>good</div>
<input id="affirmative9" type="radio" name="answer" required>
<div class="answer down">Yes</div>
<input id="affirmative10" type="radio" name="answer" required>
<div class="answer down">Signs<br>point to<br>yes</div>
<!-- Non-comittals -->
<input id="non-committal1" type="radio" name="answer" required>
<div class="answer down">Reply hazy<br>try<br>again</div>
<input id="non-committal2" type="radio" name="answer"required>
<div class="answer up">Ask<br>again<br>later</div>
<input id="non-committal3" type="radio" name="answer"required>
<div class="answer down">Better not<br>tell you<br>now</div>
<input id="non-committal4" type="radio" name="answer"required>
<div class="answer down">Cannot<br>predict<br>now</div>
<input id="non-committal5" type="radio" name="answer"required>
<div class="answer down">Concentrate<br>and ask<br>again</div>
<!-- Negatives -->
<input id="negative1" type="radio" name="answer" required>
<div class="answer up">Don't<br>count<br>on it</div>
<input id="negative2" type="radio" name="answer" required>
<div class="answer down">My reply<br>is<br>no</div>
<input id="negative3" type="radio" name="answer" required>
<div class="answer down">My<br>sources<br>say<br>no</div>
<input id="negative4" type="radio" name="answer" required>
<div class="answer down">Outlook<br>not so<br>good</div>
<input id="negative5" type="radio" name="answer" required>
<div class="answer up">Very<br>doubtful</div>
</div>
<div class="labels">
<label for="affirmative1"></label>
<label for="non-committal1"></label>
<label for="affirmative2"></label>
<label for="negative1"></label>
<label for="affirmative3"></label>
<label for="non-committal2"></label>
<label for="affirmative4"></label>
<label for="negative2"></label>
<label for="affirmative5"></label>
<label for="non-committal3"></label>
<label for="affirmative6"></label>
<label for="negative3"></label>
<label for="affirmative7"></label>
<label for="non-committal4"></label>
<label for="affirmative8"></label>
<label for="negative4"></label>
<label for="affirmative9"></label>
<label for="non-committal5"></label>
<label for="affirmative10"></label>
<label for="negative5"></label>
</div>
</form>
<div class="instruction">1. Press and<br>hold the ball</div>
<div class="instruction">2. Ask the<br>ball a question</div>
<div class="instruction">3. Release the<br>ball</div>
<div class="instruction">4. Read answer,<br> repeat</div>
</div>
body {
margin: 0;
}
.toy {
position: relative;
margin: 5vmin auto;
width: 90vmin;
}
.ball {
position: relative;
border-radius: 50%;
width: 90vmin;
height: 90vmin;
overflow: hidden;
background: radial-gradient(circle at 30vmin 30vmin, #444, #000);
}
/* Answers */
.answers {
width: 90vmin;
height: 90vmin;
}
.answer {
position: absolute;
justify-content: center;
align-items: center;
display: flex;
left: 36vmin;
top: 34.6vmin;
width: 18vmin;
height: 20.8vmin;
color: white;
text-align: center;
font-family: sans-serif;
font-variant: small-caps;
font-size: 2.1vmin;
line-height: 2.4vmin;
opacity: 0;
transition: opacity 1s;
animation: floating 6s linear infinite;
}
/* Triangle */
.answer::before {
content: "";
z-index: -1;
position: absolute;
left: 0;
border-left: 8.8vmin solid transparent;
border-right: 8.8vmin solid transparent;
border-radius: 0.4vmin;
width: 0.4vmin;
height: 0;
}
.answer.up::before {
top: 0.4vmin;
border-bottom: 15.2vmin solid #1c23e8;
}
.answer.down::before {
bottom: 0.4vmin;
border-top: 15.2vmin solid #1c23e8;
}
/* Overlay */
.answer::after {
content: "";
z-index: 1;
position: absolute;
left: -7vmin;
top: -5vmin;
border-radius: 50%;
width: 32vmin;
height: 32vmin;
background: linear-gradient(to left, rgba(0,0,0,0.9), rgba(0,0,0,0));
animation: rotating 6s infinite linear;
}
/* Input control */
input {
display: none;
}
input:checked + .answer {
opacity: 1;
transition: opacity 2s 1s;
}
form:active input:checked + .answer {
opacity: 0;
transition: opacity 1s;
}
/* Invisible labels */
.labels {
position: absolute;
top: 0;
animation: random 1s steps(20) infinite;
}
form:active .labels {
animation-play-state: paused;
}
label {
display: block;
width: 90vmin;
height: 90vmin;
cursor: pointer;
}
/* Window to see the answer */
.window {
position: absolute;
left: 22.5vmin;
top: 22.5vmin;
width: 45vmin;
height: 45vmin;
border-radius: 50%;
background: radial-gradient(#002, #001 18vmin, #666 18vmin, #000 18.5vmin, #000 22vmin, #666 22vmin, #000 22.5vmin);
}
/* Number 8 */
.eight {
position: absolute;
left: 22.5vmin;
top: 22.5vmin;
width: 45vmin;
height: 45vmin;
border-radius: 50%;
background: #fff;
font-size: 27vmin;
font-family: sans-serif;
text-align: center;
line-height: 45vmin;
transition: opacity 1s;
}
form:valid .eight {
opacity: 0;
}
/* "Uniform distribution" of labels */
@keyframes random {
to {
transform: translateY(-1710vmin);
}
}
/* Triangle gently floating around */
@keyframes floating {
from {
transform: rotateZ(0) rotateY(15deg) translateZ(6.8vmin) rotateZ(0);
}
to {
transform: rotateZ(1turn) rotateY(15deg) translateZ(6.8vmin) rotateZ(-1turn);
}
}
/* Roatating overlay */
@keyframes rotating {
to {
transform: rotate(1turn);
}
}
/* Instructions */
.instruction {
z-index: -1;
position: absolute;
top: -10vmin;
left: -10vmin;
width: 110vmin;
height: 110vmin;
text-align: center;
font-family: fantasy;
font-size: 3vmin;
line-height: 4.2vmin;
opacity: 0;
}
.instruction:nth-of-type(1) {
transform: rotate(-45deg);
animation: instruction 1s both;
}
.instruction:nth-of-type(2) {
transform: rotate(45deg);
animation: instruction 1s 1s both;
}
.instruction:nth-of-type(3) {
transform: rotate(-45deg) translateY(102vmin);
animation: instruction 1s 2s both;
}
.instruction:nth-of-type(4) {
transform: rotate(45deg) translateY(102vmin);
animation: instruction 1s 3s both;
}
form:valid ~ .instruction {
display: none;
}
@keyframes instruction {
to {
opacity: 1;
}
}
// ¯\_(ツ)_/¯
Also see: Tab Triggers