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="topbanner">
This is just a top banner for the fun of it.
</div>
<div class="header-container">
<header>
<div class="container">
<div class="branding">
<h1>Sticky header stuffs</h1>
</div>
<nav>
<ul>
<li><a href="#" class="active" aria-current="page">Home</a></li>
<li><a href="#">Oh snap</a></li>
<li><a href="#">About us</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</div>
</header>
</div>
<div class="grid">
<main>
<h1>This is the title of my main content</h1>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras convallis sodales erat vel accumsan. Nam eget massa nec sem vulputate ullamcorper vel quis justo. Duis rhoncus tempor tempus. Nulla facilisi. Maecenas nulla ante, lacinia ac consectetur non, aliquet sollicitudin libero. Quisque congue odio sodales dui fermentum ac laoreet mauris eleifend. Nulla facilisi. Phasellus vel erat a ante pharetra pharetra.</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras convallis sodales erat vel accumsan. Nam eget massa nec sem vulputate ullamcorper vel quis justo. Duis rhoncus tempor tempus. Nulla facilisi. Maecenas nulla ante, lacinia ac consectetur non, aliquet sollicitudin libero. Quisque congue odio sodales dui fermentum ac laoreet mauris eleifend. Nulla facilisi. Phasellus vel erat a ante pharetra pharetra.</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras convallis sodales erat vel accumsan. Nam eget massa nec sem vulputate ullamcorper vel quis justo. Duis rhoncus tempor tempus. Nulla facilisi. Maecenas nulla ante, lacinia ac consectetur non, aliquet sollicitudin libero. Quisque congue odio sodales dui fermentum ac laoreet mauris eleifend. Nulla facilisi. Phasellus vel erat a ante pharetra pharetra.</p>
<p>
Donec fringilla sem at eros vulputate tempus. Maecenas interdum leo a tortor lobortis in hendrerit est pellentesque. Vestibulum non leo et nisi sollicitudin rutrum. Aliquam tristique dui tempor sapien molestie mollis. Integer viverra faucibus nulla ut posuere. Sed quis dui dictum tortor imperdiet imperdiet ut scelerisque augue. Aenean sit amet libero sit amet metus pulvinar viverra et id tortor. Nulla iaculis bibendum nisi, quis elementum risus tempus et. Nullam rutrum, dolor id vulputate feugiat, lectus tortor auctor odio, et lacinia eros neque quis neque. Praesent nibh erat, varius porttitor cursus a, condimentum vel eros. Quisque odio urna, elementum a consequat id, facilisis eget mi. Praesent imperdiet congue velit, non tempus mi sollicitudin eu. Duis vitae nisi leo, ut ultrices leo. Aliquam dolor sapien, cursus suscipit fringilla et, lacinia et ligula. Proin eu lacus leo, at accumsan nisi. Nulla facilisi. Proin vehicula mi nec augue semper eleifend. Aliquam tempus vulputate quam at malesuada. Nulla a lacus sit amet urna varius cursus. Aliquam a nunc sapien. </p>
<div class="banner">
<h2>This is an awesome banner</h2>
<p>Depending on the container, this will adjust its font-size and paddings to fit perfectly</p>
</div>
</main>
<aside>
<ul>
<li>Lorem ipsum dolor sit amet</li>
<li>lacinia ac consectetur non</li>
<li>Phasellus vel erat a ante</li>
<li> Nulla facilisi</li>
<li>ac consectetur non</li>
</ul>
<div class="banner">
<h2>This is an awesome banner</h2>
<p>Depending on the container, this will adjust its font-size and paddings to fit perfectly</p>
</div>
</aside>
</div>
<div class="warning">This is a demo for state queries, use Chrome Canary and enable the experimental web platform features</div>
@import url("https://fonts.googleapis.com/css2?family=Open+Sans:wdth@75..100&family=Oswald:wght@600&display=swap");
@layer presentation, defaultgrid, layout, demo;
@layer demo {
.header-container {
width: 100%;
position: sticky;
top: 0;
@supports (container-type: scroll-state) {
container-type: scroll-state;
header {
transition: box-shadow 0.5s ease-out;
h1 {
transition: font-size 0.5s;
}
@container scroll-state(stuck: top) {
box-shadow: rgba(0, 0, 0, 0.6) 0px 12px 28px 0px,
rgba(0, 0, 0, 0.1) 0px 2px 4px 0px,
rgba(255, 255, 255, 0.05) 0px 0px 0px 1px inset;
h1 {
font-size: 1.5rem;
}
}
}
}
}
}
@layer layout {
/* Set container type */
.grid > * {
container-type: inline-size;
}
/* Style banner with cq units */
.banner {
padding: 3cqmax;
background: #49416d;
color: #b3f2dd;
font-size: clamp(1rem, 2cqi + 0.5rem, 1.5rem);
border-radius: 0.5rem;
box-shadow: rgba(50, 50, 93, 0.25) 0px 6px 12px -2px,
rgba(0, 0, 0, 0.3) 0px 3px 7px -3px;
text-shadow: -1px -1px 1px rgba(255, 255, 255, 0.2),
1px 1px 1px rgba(0, 0, 0, 0.6);
}
.banner h2 {
font-size: clamp(1.3rem, 3cqi + 0.5rem, 2.4rem);
margin: 0 0 1cqi;
}
/* Set container name for aside */
aside {
container-name: aside;
}
/* change the bgcolor when in the sidebar */
@container aside (min-inline-size: 100px) {
.banner {
background-color: #a882dd;
color: #111;
text-shadow: none;
}
}
.topbanner {
background: salmon;
color: white;
width: 100%;
padding: 1.2rem;
text-align: center;
}
}
@layer defaultgrid {
.grid {
display: grid;
inline-size: 100%;
min-block-size: 100dvb;
gap: 3vmin;
background: #e0efde;
overflow: hidden;
> * {
padding: 1.5rem;
}
@media screen and (min-width: 768px) {
grid-template-columns: 3fr 2fr;
}
}
aside {
background: #e08d79;
}
.banner p {
margin: 0;
}
}
@layer presentation {
:root {
--color-cerulean: #0081a7;
--color-lightest: #fff;
--color-orange: #fed9b7;
--color-yellow: #fdfcdc;
--color-verdigris: #00afb9;
--color-cerulean: #0081a7;
--color-lightest: #fff;
--bg-slider: #161032;
}
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
font-family: "Open Sans", sans-serif;
font-size: 1.1rem;
line-height: 1.55;
color: #49416d;
min-block-size: 100dvb;
place-content: center;
place-items: center;
background: #d3bdb0;
}
h1 {
font-size: clamp(2rem, 5cqi + 0.5rem, 3rem);
text-shadow: -1px -1px 1px rgba(255, 255, 255, 0.2),
1px 1px 1px rgba(0, 0, 0, 0.6);
}
h1,
h2 {
font-family: "Oswald", sans-serif;
font-weight: 600;
}
header {
padding-block: 24px;
background: #0081a7;
width: 100%;
.container {
display: flex;
flex-direction: column;
align-items: center;
padding-inline: 1.5rem;
@media screen and (min-width: 768px) {
flex-direction: row;
justify-content: space-between;
gap: 50px;
}
}
}
.branding {
font-family: "Electrolize", sans-serif;
display: flex;
align-items: center;
gap: 20px;
color: var(--color-orange);
& h1 {
margin: 0;
font-size: 1.6rem;
@media screen and (min-width: 500px) {
font-size: 2rem;
}
}
}
nav ul {
display: flex;
gap: 15px;
margin-block: 15px 0;
margin-inline: 0;
padding: 0;
list-style: none;
font-size: 1rem;
@media screen and (min-width: 1000px) {
margin-block-start: 0;
font-size: 1.4rem;
}
}
a {
color: var(--color-orange);
text-decoration: none;
transition: color 0.24s;
&:is(:hover, :focus) {
color: var(--color-lightest);
}
&.active {
color: var(--color-lightest);
text-decoration: underline;
}
}
}
.warning {
position: fixed;
top: 0;
left: 0;
font-family: Arial, Helvetica, sans-serif;
font-size: 1rem;
color: black;
background: yellow;
padding: 10px;
z-index: 10;
@supports (container-type: scroll-state) {
display: none;
}
}
Also see: Tab Triggers