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="hero">
<div class="hero-inner">
<h1>Cats Are Awesome!</h1>
<h2><span id="count">100</span> of people agree</h2>
<button id="agree" class="btn" onclick="agree()">I agree</button>
</div>
</div>
<div class="section">
<h2>About Me</h2>
</div>
<div class="about">
<div class="outer">
<div class="column">
<img src="https://images.unsplash.com/photo-1568977805153-e0a2d26da0e0" alt="Chell" />
</div>
<div class="column">
<p>Hi, my name is Chell! </p>
<br />
<p> I am a beautiful tortie/calico/tabby cat. I have been named Peoples choice of the household since the day I blessed this home.</p>
<br />
<p> However, I am not happy. And why would such a beautiful cat like me not be happy? Well, I have the answer.</p>
<br /><strong>THE DOG.</strong></p>
<br />
<p>Ever since my mom brought home the dog (named Leela) life has been subpar. The dog always wants to smell things, play, and be a good girl overall. Honestly how lame! Also, I've caught her I few times trying to eat from the litter box. Disgusting!</p>
<br />
<p>So I created this site to celebrate how wonderful cats are, and how dogs are not wonderful.</p>
</div>
</div>
</div>
<div class="section">
<h2>Learn More</h2>
</div>
<div class="learn-more">
<p>Have dogs ruined your life too? Well maybe you can find comfort here.</p>
<div class="outer">
<div class="column">
<div class="container">
<a href="#fact" onClick="getCatFact()">
<img src="https://images.unsplash.com/photo-1580784355694-0d5295dcc007?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0MjU4OTA&ixlib=rb-4.0.3&q=80" class="image" alt="Cat" />
</a>
<div class="text">
<h2>Cat Facts</h2>
</div>
</div>
</div>
<div class="column">
<div class="container">
<a href="#fact" onClick="getDogFact()">
<img src="https://images.unsplash.com/photo-1601880348117-25c1127a95df?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0MjU5MzI&ixlib=rb-4.0.3&q=80" class="image" alt="Dog" />
</a>
<div class="text">
<h2>Dog Facts</h2>
</div>
</div>
</div>
</div>
<div class = "fact">
<h2>Click the images above to get a cat/dog fact!</h2>
<img id="image" src="https://images.unsplash.com/photo-1549545931-59bf067af9ab?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0Mjk0ODk&ixlib=rb-4.0.3&q=80"/>
<p><span id="fact"></span></p>
</div>
</div>
<div class="footer">
<div class="outer">
<p>This site is created for cat lovers. Haters are not welcome.</p>
<p><strong>Note:</strong> This site was created for me by my mother, as I still lack the ability to type. My mother would like to say she made this under duress, and does not share my view on hating dogs. She APPARENTLY likes all animals.</p>
</div>
</div>
body {
margin: 0;
/* Font */
font-family: sans-serif;
}
p {
font-family: sans-serif;
}
.hero {
/* Sizing */
width: 100vw;
height: 100vh;
/* Flexbox stuff */
display: flex;
justify-content: center;
align-items: center;
/* Text styles */
text-align: center;
/* Background styles */
background-image: url("https://images.unsplash.com/photo-1596854372407-baba7fef6e51?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0MjYwMzg&ixlib=rb-4.0.3&q=80");
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-attachment: fixed;
}
.hero h1 {
/* Text styles */
font-size: 5em;
/* Margins */
margin-top: 0;
margin-bottom: 0.5em;
}
.hero h2 {
/* Text styles */
font-size: 2em;
/* Margins */
margin-top: 0;
margin-bottom: 0.5em;
opacity: 1;
}
.hero .btn {
/* Font */
font-family: sans-serif;
/* Positioning and sizing */
display: block;
width: 200px;
/* Padding and margins */
padding: 1em;
margin-top: 50px;
margin-left: auto;
margin-right: auto;
/* Text styles */
color: black;
text-decoration: none;
font-size: 1.5em;
/* Border styles */
border: 2px solid black;
border-radius: 20px;
/* Background styles */
background-color: rgba(147, 112, 219, 0.5);
}
.section {
background-color: black;
/* Text styles */
text-align: center;
color: rgb(147, 112, 219);
/* Padding */
padding-top: 25px;
padding-bottom: 25px;
}
.section h2 {
/* Text styles */
font-size: 2em;
}
.about {
background-color: rgb(153, 204, 255);
text-align: center;
/* Padding */
padding-top: 25px;
padding-bottom: 25px;
overflow: hidden; /* make sure this doesn't cause unexpected behaviour */
}
.about .outer {
width: 60%;
margin: 0 auto;
display: flex;
align-items: center;
}
/* About image*/
.about img {
margin: auto;
width: 100%;
padding: 20px;
border-radius: 50%;
width: 300px;
height: 300px;
object-fit: cover;
}
/* Create two equal columns that floats next to each other */
.about .column {
float: left;
width: 50%;
}
.learn-more {
background-color: rgb(153, 204, 255);
text-align: center;
/* Padding */
padding-top: 25px;
padding-bottom: 25px;
overflow: hidden; /* make sure this doesn't cause unexpected behaviour */
}
.learn-more .outer {
width: 60%;
margin: 0 auto;
display: flex;
align-items: center;
}
.learn-more .column {
float: left;
width: 50%;
}
/* Learn more image*/
.learn-more .image {
margin: auto;
width: 100%;
padding: 20px;
border-radius: 50%;
width: 300px;
height: 300px;
object-fit: cover;
}
.container {
position: relative;
}
.container .text {
color: white;
position: absolute;
z-index: 999;
margin: 0 auto;
left: 0;
right: 0;
text-align: center;
top: 60%;
width: 60%;
}
/* Learn more hover*/
.learn-more .column:hover .image {
/* Background styles */
opacity: 0.3;
}
/* Learn more hover*/
.learn-more .column:hover .text {
color: black;
}
.fact {
background-color: rgba(147, 112, 219, 0.5);
width: 60%;
margin: 0 auto;
align-items: center;
text-align: center;
/* Padding */
padding-top: 25px;
padding-bottom: 25px;
overflow: hidden; /* make sure this doesn't cause unexpected behaviour */
}
/* Fact image*/
.fact img {
margin: auto;
width: 100%;
padding: 20px;
max-width: 500px;
max-height: 500px;
width: auto;
height: auto;
}
.footer {
text-align: center;
background: black;
color: rgb(147, 112, 219);
/* Padding */
padding-top: 25px;
padding-bottom: 25px;
overflow: hidden; /* make sure this doesn't cause unexpected behaviour */
}
.footer .outer {
width: 60%;
margin: 0 auto;
align-items: center;
}
async function agree() {
document.getElementById("count").innerText++;
}
async function getCatFact() {
const factlist = [
["Use sustainable energy to stay warm.", "https://images.unsplash.com/photo-1570579445398-1c555074dff6?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0Mjk1OTg&ixlib=rb-4.0.3&q=80"],
[
"Cats are resourceful, we can make anything a bed",
"https://images.unsplash.com/photo-1587045311651-a84c727f0ecd?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0Mjk2NTY&ixlib=rb-4.0.3&q=80"
],
["Cats can make themselves compact.", "https://github.com/chaotictoejam/CTS2375-Example-Final-Project/blob/master/example-1/images/chell_ball.jpg?raw=true"],
["Can climb up high", "https://images.unsplash.com/photo-1610016144621-a0b3cd5addd8?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0Mjk3NzI&ixlib=rb-4.0.3&q=80"],
["Cats know how to use a bed.", "https://images.unsplash.com/photo-1513977055326-8ae6272d90a7?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0Mjk3OTk&ixlib=rb-4.0.3&q=80"],
["Cats are perfect.", "https://images.unsplash.com/photo-1516750105099-4b8a83e217ee?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0Mjk4MTY&ixlib=rb-4.0.3&q=80"]
];
let randomFact = factlist[Math.floor(Math.random() * factlist.length)];
document.getElementById("fact").innerHTML = randomFact[0];
document.getElementById("image").src = randomFact[1];
}
async function getDogFact() {
const factlist = [["Dogs like to play in water!", "https://images.unsplash.com/photo-1505623547966-8af2af3515ac?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0Mjg5NTc&ixlib=rb-4.0.3&q=80"],
["Dogs don't understand beds are for sleeping.", "https://images.unsplash.com/photo-1553736026-ff14d158d222?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0Mjg5ODQ&ixlib=rb-4.0.3&q=80"],
["Dogs destroy their toys", "https://images.unsplash.com/photo-1588218955664-d18f4e3056e5?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0MjkwNzA&ixlib=rb-4.0.3&q=80"],
["Wear sweaters. Seriously? You have fur.", "https://images.unsplash.com/photo-1611653100849-fd8325cada0a?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0MjkwODg&ixlib=rb-4.0.3&q=80"],
["Attack the broom.", "https://github.com/chaotictoejam/CTS2375-Example-Final-Project/blob/master/example-1/images/leela_broom.gif?raw=true"],
["Like to play in dirt.", "https://images.unsplash.com/photo-1626018743149-427a9e2821ed?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzMjM4NDZ8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NzI0MjkxNjI&ixlib=rb-4.0.3&q=80"]
];
let randomFact = factlist[Math.floor(Math.random() * factlist.length)];
document.getElementById("fact").innerHTML = randomFact[0];
document.getElementById("image").src = randomFact[1];
}
Also see: Tab Triggers