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='phone'>
<div class='inside'>
<div id='title-page' class=''>
<h1>A Story</h1>
<h3>as told by a few letters</h3>
<div class='next' style='display:block;'><a href='#ch1'>↓</a></div>
</div>
<div id='ch1' class='page'>
<div class='ch1-block'>
<p>There once was a little 'a'.<br><br> Alone they sat dreaming of one day becoming a big 'a'.</p>
<div class='ch1-game'>
<h1 onclick='changeFont(this)'>a</h1>
</div>
</div>
<div class='next'><a href='#ch2' onclick='ch2Open()'>↓</a></div>
</div>
<div id='ch2' class='page'>
<div class='ch1-block'>
<div class='ch2-game'>
<h1 onclick='ch2(this)'>a</h1>
<h1 class='b'>b</h1>
<p>Because I can. Now leave me little 'b'.</p>
</div>
</div>
<div class='next'><a href='#ch3' onclick='ch3Open()'>↓</a></div>
</div>
<div id='ch3' class='page'>
<div class='ch1-block'>
<div class='ch3-game'>
<h1 onclick='ch3(this)'>a</h1>
<h1 class='c'>c</h1>
<p>I guess I am a big 'A'.</p>
</div>
</div>
<div class='next'><a href='#title-page' onclick='theEnd()'>↓</a></div>
</div>
</div>
</div>
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,500,700,900&display=swap" rel="stylesheet">
::-webkit-scrollbar {
width:5px;
}
:root {
--fontFamily:'Montserrat', sans-serif;
--hide:none;
--aAnimation:ch1 2s linear infinite;
--bAnimation:none;
--bBubble:"Why do you daydream little 'a'?";
--cAnimation:none;
--cBubble:"Whatcha doing little 'a'?"
}
html {
font-family: 'Montserrat', sans-serif;
scroll-behavior: smooth;
background:linear-gradient(to bottom right, transparent 18px, #efefef 18px, transparent 20px);
background-size:20px 20px;
}
.phone {
width:330px;
height:668px;
border-radius:20px;
box-shadow:0 0 0 2px lightgray;
position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
background:white;
}
.inside {
width:320px;
height:568px;
box-shadow:0 0 0 2px lightgray;
position:absolute;
top:50%;
left:50%;
transform:translate(-50%,-50%);
overflow:hidden;
scroll-behavior: smooth;
background:white;
}
#title-page {
width:100%;
min-height:568px;
}
#title-page h1 {
font-size:85px;
line-height:100%;
font-weight:900;
padding:0 20px;
text-align:left;
}
#title-page h3 {
padding:0 20px;
}
.next {
position: absolute;
bottom: 10px;
right: 5px;
font-size: 36px;
line-height: 100%;
user-select:none;
display:none;
animation:downArrow 2s linear infinite;
}
@keyframes downArrow {
50% { bottom:0px; }
}
.next a{
color:black;
text-decoration:none;
}
#title-page .next {
right:50%;
transform:translateX(50%);
}
/* ch1 */
.page {
margin-top:100px;
position:relative;
}
.ch1-block {
width:100%;
height:568px;
background:#efefef;
}
.page p {
padding:20px;
position:absolute;
bottom:0;
}
.ch1-game {
position:absolute;
bottom:0;
width:100%;
height:50%;
}
.page h1 {
font-size:100px;
font-weight:300;
text-align:center;
margin-top:0;
user-select:none;
cursor:pointer;
animation:var(--aAnimation);
}
@keyframes ch1 {
50% { transform:scale(1.2) }
}
.ch1-game h1:before {
content: '';
position: absolute;
top: -32%;
left: 50%;
transform: translateX(-50%);
width: 30px;
height: 120px;
background: red;
background: radial-gradient(circle, white 50%, transparent 50%);
background-size: 30px 30px;
display:var(--hide);
}
.ch1-game h1:after {
content: 'A';
position: absolute;
top: -75%;
left: 50%;
transform: translateX(-50%);
font-size: 72px;
width:115px;
height:115px;
line-height: 115px;
font-weight: 700;
font-family: var(--fontFamily);
background: white;
border-radius: 25px;
display:var(--hide);
}
/* ch2 */
#ch2 .ch1-block {
background:white;
}
#ch2 h1 {
width:50%;
position:absolute;
top:50%;
transition:1s;
}
#ch2 h1:nth-child(2) {
right:-50%;
transition:1s;
}
#ch2 h1:nth-child(2):after {
content: var(--bBubble);
position: absolute;
top: -30%;
left: -25%;
display: block;
font-size: 20px;
text-align: left;
opacity:0;
animation:var(--bAnimation);
}
@keyframes b {
100% { opacity:1; }
}
/* ch3 */
#ch3 h1:nth-child(1) {
width:50%;
position:absolute;
top:50%;
transform:scaleX(-1);
transition:1s;
}
#ch3 h1:nth-child(2) {
width:50%;
position:absolute;
right:-50%;
top:50%;
transition:1s;
}
#ch3 h1:nth-child(2):after {
content: var(--cBubble);
position: absolute;
top: -10%;
left: 0%;
display: block;
font-size: 20px;
text-align: left;
opacity: 0;
animation: var(--cAnimation);
}
@keyframes c {
100% { opacity:1; }
}
#ch3 p, #ch2 p {
bottom:40%;
opacity:0;
transition:.75s;
font-size:20px;
font-weight:300;
text-align:left;
padding-left:20px;
width:60%;
}
let root = document.documentElement
var fonts = ['monospace','serif','cursive','sans-serif']
var f = 0
function changeFont(e) {
f++
if(f < 3) {
root.style.setProperty('--fontFamily',fonts[f])
} else {
f = 0
root.style.setProperty('--fontFamily',fonts[f])
}
root.style.setProperty('--hide','block')
root.style.setProperty('--aAnimation','none')
document.querySelector('#ch1 .next').style.display = "block"
}
function ch2Open() {
document.querySelector('.b').style.right = "0"
root.style.setProperty('--bAnimation','b 1s linear .5s forwards')
}
function ch2(e) {
e.style.transform = 'scaleX(-1)'
document.querySelector('#ch2 p').style.opacity = "1"
root.style.setProperty('--bBubble',"''")
setTimeout(function(){
document.querySelector('.b').style.right = "-100%"
document.querySelector('#ch2 .next').style.display = "block"
},3500)
}
function ch3Open() {
document.querySelector('.c').style.right = "0"
root.style.setProperty('--cAnimation','c 1s linear .5s forwards')
}
function ch3(e) {
document.querySelector('#ch3 p').style.opacity = "1"
document.querySelector('#ch3 p').innerHTML = '#$%@^!'
root.style.setProperty('--cBubble',"''")
setTimeout(function(){
document.querySelector('.c').style.right = "-100%"
document.querySelector('#ch3 p').innerHTML = "I guess I am already a big 'A'."
document.querySelector('#ch3 .next').style.display = "block"
},1500)
}
function theEnd() {
document.querySelector('#title-page').style.paddingTop = '50px'
document.querySelector('#title-page h1').innerHTML = 'The End'
document.querySelector('#title-page h3').innerHTML = "no letters were harmed in the making of this production<br><br>don't be like little 'a' y'all"
document.querySelector('#title-page .next').style.display = 'none'
}
Also see: Tab Triggers