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.
<header class="post-header">
<h1 class="post-title">A walk along the coast</h1>
</header>
<div class="post-body">
<p class="post-lede">In July, we went for a walk from the Brösarp hills and out to the coast near Kivik. It was one of the most beautiful days of the summer.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quibusdam laudantium eos minima dolor asperiores maxime voluptas itaque iure nostrum quos ipsam aliquam quasi amet repudiandae totam, vel, veniam sit repellat.</p>
<p>Cum, quibusdam explicabo odit ut voluptatem a, sint ea vel inventore. Earum fugit architecto voluptatem itaque dolorum modi, ipsam, aliquid quod aliquam. Assumenda magnam dolorum quisquam optio dicta ex ipsum ipsa quos, nulla quas eaque, modi fugit
provident iusto, blanditiis quod dignissimos. Doloribus, natus.</p>
<p>Perspiciatis hic architecto assumenda quod sit praesentium iure nihil, similique sapiente consequuntur modi dolorum eaque, tenetur sequi perferendis enim, veritatis earum vitae. Veritatis iure nihil perspiciatis, aspernatur reiciendis, esse quia porro
fuga velit error tenetur quod voluptates recusandae quae provident beatae! Accusamus, ipsum, dolore.</p>
<p>Commodi nulla, minus repellendus dolores enim eveniet veritatis facere ipsam nemo officia. Culpa veniam a, aperiam at. Consequuntur ducimus mollitia distinctio, perspiciatis! Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ex, cum, vel. Voluptates
sapiente ipsam error soluta nemo neque nulla tenetur aspernatur consequatur saepe incidunt atque, non, ab nihil similique repudiandae.</p>
</div>
body {
font-family: Georgia, Times New Roman, serif;
line-height: 1.5;
margin: 0;
}
header,
section,
article,
footer,
aside,
figure {
display: block;
}
.post-lede {
font-family: Avenir Next, SegoeUI, Franklin Gothic, arial, sans-serif;
font-size: 1.25em;
font-weight: 500;
}
.post-body p {
margin: 0;
}
.post-body p + p {
margin-top: 1.5em;
}
.post-body {
box-sizing: border-box;
max-width: 50em;
width: 94%;
font-size: 1.125em;
margin: -20vw auto 2em auto;
padding: 5%;
position: relative;
background-color: #fff;
}
.post-title {
font-family: Avenir Next, SegoeUI, Franklin Gothic, arial, sans-serif;
text-align: center;
text-shadow: 0 0 .5em rgba(0, 0, 0, 0.6);
font-size: calc(1em + 5vw);
margin: auto auto 23vw;
padding: .5em;
color: #fff;
}
.post-header {
overflow: hidden;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
width: 100%;
height: 54.5vw;
margin: 0 auto;
background-color: #567DA7;
background-size: cover;
background-position: 50% 0;
background-image: url(data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20xmlns%3Axlink%3D%22http%3A//www.w3.org/1999/xlink%22%20width%3D%221500%22%20height%3D%22823%22%20viewBox%3D%220%200%201500%20823%22%3E%0A%20%20%3Cfilter%20id%3D%22blur%22%20color-interpolation-filters%3D%22sRGB%22%3E%0A%20%20%20%20%3CfeGaussianBlur%20stdDeviation%3D%2220%22%20edgeMode%3D%22duplicate%22%20/%3E%0A%20%20%20%20%3CfeComponentTransfer%3E%0A%20%20%20%20%20%20%3CfeFuncA%20type%3D%22discrete%22%20tableValues%3D%221%201%22%20/%3E%0A%20%20%20%20%3C/feComponentTransfer%3E%0A%20%20%3C/filter%3E%0A%20%20%3Cimage%20filter%3D%22url%28%23blur%29%22%20xlink%3Ahref%3D%22data%3Aimage/jpeg%3Bbase64%2C/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAYEBAQEBAYEBAYJBgUGCQoHBgYHCgsJCQoJCQsPCwwMDAwLDwwNDg4ODQwRERMTEREaGRkZGh0dHR0dHR0dHR0BBgcHDAsMFg8PFhkUEBQZHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0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I7Gr4Vg5rNpWxTy799fNC4p6S+ZrW7p8IZZvk2ZqiZWJuodRIQmEkQDGhrO6PvVRd6IKurvu+rS/rgcurrs2kJvzzhv/tBmkU2Okbd1fxH/2Q%3D%3D%22%20x%3D%220%22%20y%3D%220%22%20height%3D%22100%25%22%20width%3D%22100%25%22/%3E%0A%3C/svg%3E);
}
.post-header-enhanced {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/401949/largeimg.jpg);
}
@supports (background-image: filter(url('i.jpg'), blur(1px))) {
.post-header {
transform: translateZ(0);
}
.post-header-enhanced {
animation: sharpen .5s both;
}
@keyframes sharpen {
from {
background-image: filter(url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/401949/largeimg.jpg), blur(20px));
}
to {
background-image: filter(url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/401949/largeimg.jpg), blur(0px));
}
}
}
window.onload = function loadStuff() {
var win, doc, img, header, enhancedClass;
// Quit early if older browser (e.g. IE8).
if (!('addEventListener' in window)) {
return;
}
win = window;
doc = win.document;
img = new Image();
header = doc.querySelector('.post-header');
enhancedClass = 'post-header-enhanced';
// Rather convoluted, but parses out the first mention of a background
// image url for the enhanced header, even if the style is not applied.
var bigSrc = (function() {
// Find all of the CssRule objects inside the inline stylesheet
var styles = doc.querySelector('style').sheet.cssRules;
// Fetch the background-image declaration...
var bgDecl = (function() {
// ...via a self-executing function, where a loop is run
var bgStyle, i, l = styles.length;
for (i = 0; i < l; i++) {
// ...checking if the rule is the one targeting the
// enhanced header.
if (styles[i].selectorText &&
styles[i].selectorText == '.' + enhancedClass) {
// If so, set bgDecl to the entire background-image
// value of that rule
bgStyle = styles[i].style.backgroundImage;
// ...and break the loop.
break;
}
}
// ...and return that text.
return bgStyle;
}());
// Finally, return a match for the URL inside the background-image
// by using a fancy regex i Googled up, if the bgDecl variable is
// assigned at all.
return bgDecl && bgDecl.match(/(?:\(['|"]?)(.*?)(?:['|"]?\))/)[1];
}());
// Assign an onLoad handler to the dummy image *before* assigning the src
img.onload = function() {
header.className += ' ' + enhancedClass;
};
// Finally, trigger the whole preloading chain by giving the dummy
// image its source.
if (bigSrc) {
img.src = bigSrc;
}
};
Also see: Tab Triggers