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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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="wrapper">
<div id="cookies" role="alert" class="cookie-banner"><div class="inner">
<div id="close" class="button button-secondary">Close</div>
<h1>Obligatory cookie banner</h1>
<div class="cookies-text">
<div class="checkboxes">
Which of these cookies can we use?
<div id="choc-chip" class="pretty-checkbox">
Chocolate chip</div>
<div id="oatmeal-raisin" class="pretty-checkbox"> Oatmeal & raisin</div>
</div>
<div id="accept" class="button button-primary">Accept all
</div>
</div>
</div>
</div>
<div class="header">
<h1 class="title"><a href="#">The Woofer Times</a></h1>
<div class="menu">
<div class="menu-item"><a href="#">News</a></div>
<div class="menu-item"><a href="#">Politics</a></div>
<div class="menu-item"><a href="#">World</a></div>
<div class="menu-item"><a href="#">Sport</a></div>
<div class="menu-item"><a href="#">Tech</a></div>
</div>
</div>
<div class="main">
<h1>You won't believe this clickbaity headline</h1>
<div class="byline"><em>N De Plume - 5th June 2021</em></div>
<p>Doggo ipsum heckin angery woofer very taste wow smol borking doggo with a long snoot for pats you are doing me a frighten, ur givin me a spook. H*ck waggy wags much ruin diet doggorino fluffer, shooberino long water shoob smol. Porgo much ruin diet wrinkler doggorino, shoob very jealous pupper.</p>
<div class="image"><img alt-"A lovely fluffy samoyed" src="https://codepen-assets.s3.eu-west-2.amazonaws.com/alex-russell-saw-Dj8cxyi9ink-unsplash-1.jpg">
<p class="caption"><em>"The most angery pupper I have ever seen" Photo: <a href="https://unsplash.com/@alexrussellsaw?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Alex Russell-Saw</a></em></p>
</div>
<p> Borkf adorable doggo boof h*ck maximum borkdrive, most angery pupper I have ever seen shibe big ol pupper, heckin angery woofer extremely cuuuuuute ruff. Woofer big ol I am bekom fat pupperino shooberino, long bois snoot. </p>
<b>And then something else happened</b>
<p>Blop smol pats doge you are doin me a concern, long water shoob wrinkler. Much ruin diet clouds fluffer long water shoob, pupper. Ruff heckin good boys and girls wow very biscit h*ck mlem, blop borking doggo. Such treat dat tungg tho doggorino boof puggorino, very jealous pupper much ruin diet.</p>
<p>Yapper long woofer what a nice floof I am bekom fat shoob ur givin me a spook such treat, borking doggo boof fluffer pupper. Heckin angery woofer borkdrive fluffer porgo doggo, smol borking doggo with a long snoot for pats long doggo. Very taste wow I am bekom fat long water shoob snoot long water shoob borkdrive heckin angery woofer, pats pupperino stop it fren long woofer heck. I am bekom fat smol boof very taste wow boofers shoob, noodle horse fluffer ruff. Clouds pupperino very good spot blop such treat most angery pupper I have ever seen, maximum borkdrive floofs bork.</p>
</strong>
</div>
<div class="footer">
<p>© some media conglomerate 2021</p>
<div class="columns">
<div class="footer-links">
<div><a href="#">About us</a></div>
<div><a href="#">Careers</a></div>
<div><a href="#">Contact us</a></div>
<div><a href="#">Help</a></div>
</div>
<div class="social">
<div class="social-link"><a href="https://twitter.com/type__error">Twitter</a></div>
<div class="social-link"><a href="https://twitter.com/type__error">Facebook</a></div>
<div class="social-link"><a href="https://twitter.com/type__error">Instagram</a></div>
<div class="social-link"><a href="https://twitter.com/type__error">Tinder</a></div>
</div>
</div>
</div>
</div>
a {
color: white;
font-weight: bold;
text-decoration: none;
}
body {
font-size: 16px;
margin: 0;
height: 100vh;
font-family: "Helvetica Neue", Arial, sans-serif;
}
.wrapper {
height: 100%;
display: flex;
flex-direction: column;
}
.header {
background-color: #420a55;
padding: 1rem;
color: white;
.menu {
display: flex;
justify-content: space-evenly;
&-item {
font-weight: bold;
}
}
}
.main {
flex: 1;
padding: 1.5rem 3rem;
a {
color: initial;
}
.image {
text-align: center;
img {
width: 60%;
}
}
}
.footer {
text-align: center;
padding: 1rem;
background: #420a55;
color: white;
.columns {
justify-content: center;
display: flex;
text-align: left;
.social {
margin-left: 1rem;
}
}
}
.cookie-banner {
position: sticky;
top: 0;
background-color: #f0f0f0;
width: 100%;
.inner {
position: relative;
padding: 1rem;
}
#close {
position: absolute;
right: 1rem;
font-size: 1rem;
cursor: pointer;
}
.pretty-checkbox {
&:before {
margin-bottom: -2px;
display: inline-block;
background-repeat: no-repeat;
content: " ";
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' fill='%23420a55' viewBox='0 0 46 46'%3e%3cpath d='M35.822 0H10.178C4.557 0 0 4.557 0 10.178v25.646C0 41.443 4.557 46 10.178 46h25.645C41.443 46 46 41.443 46 35.822V10.178C46 4.557 41.443 0 35.822 0zM40 35.822A4.182 4.182 0 0135.822 40H10.178A4.182 4.182 0 016 35.822V10.178A4.182 4.182 0 0110.178 6h25.645A4.182 4.182 0 0140 10.178v25.644z'/%3e%3c/svg%3e");
width: 16px;
height: 16px;
}
&.checked:before {
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' fill='%23420a55' viewBox='0 0 46 46'%3e%3cpath d='M35.822 0H10.178C4.557 0 0 4.557 0 10.178v25.646C0 41.443 4.557 46 10.178 46h25.645C41.443 46 46 41.443 46 35.822V10.178C46 4.557 41.443 0 35.822 0zM40 35.822A4.182 4.182 0 0135.822 40H10.178A4.182 4.182 0 016 35.822V10.178A4.182 4.182 0 0110.178 6h25.645A4.182 4.182 0 0140 10.178v25.644z'/%3e%3cpath d='M21.925 33.298a3.253 3.253 0 01-4.596 0l-7.122-7.122a3.25 3.25 0 114.597-4.596l4.243 4.242c.321.32.84.32 1.161 0l11.489-11.489c1.27-1.27 3.326-1.27 4.597 0s1.271 3.327 0 4.597L21.925 33.298z'/%3e%3c/svg%3e");
}
}
.cookies-text {
width: 80%;
display: flex;
justify-content: space-between;
}
.button {
cursor: pointer;
border: 0;
box-shadow: none;
border-radius: 6px;
font-weight: bold;
font-size: 1rem;
display: flex;
justify-content: center;
align-items: center;
padding: 0.8rem 1rem;
margin: auto 0;
&-primary {
color: white;
background-color: #420a55;
&:hover {
background: #8d6c99;
}
}
&-secondary {
background: white;
border: 1px solid #aaaaaa;
&:hover {
background: #aaaaaa;
}
}
}
&.hidden {
display: none;
}
}
let selected = [];
function selectCookie(cookie) {
if (selected.includes(cookie)) {
selected = selected.filter((c) => c !== cookie);
document.getElementById(cookie).classList.remove("checked");
return;
}
selected.push(cookie);
document.getElementById(cookie).classList.add("checked");
}
document.getElementById("choc-chip").onclick = () => selectCookie("choc-chip");
document.getElementById("oatmeal-raisin").onclick = () =>
selectCookie("oatmeal-raisin");
document.getElementById("close").onclick = closeCookies;
document.getElementById("accept").onclick = closeCookies;
function closeCookies() {
document.getElementById("cookies").classList.add("hidden");
}
Also see: Tab Triggers