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="wrapper">
<div class="sidebar">
<nav>
<ul role="list">
<li>
<a href="#">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true">
<path fill="currentColor" d="M13 7h-2v4H7v2h4v4h2v-4h4v-2h-4zm-1-5C6.48 2 2 6.48 2 12s4.48 10 10 10s10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8s8 3.59 8 8s-3.59 8-8 8" />
</svg>
Add content
</a>
</li>
<li>
<a href="#">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true">
<path fill="currentColor" d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4s-4 1.79-4 4s1.79 4 4 4m0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4" />
</svg>
Profile
</a>
</li>
<li>
<a href="#">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true">
<path fill="currentColor" d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2m0 4l-8 5l-8-5V6l8 5l8-5z" />
</svg>
Messages
</a>
</li>
<li>
<a href="#">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true">
<path fill="currentColor" d="M18 16v-5c0-3.07-1.64-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.63 5.36 6 7.92 6 11v5l-2 2v1h16v-1zm-5 0h-2v-2h2zm0-4h-2V8h2zm-1 10c1.1 0 2-.9 2-2h-4a2 2 0 0 0 2 2" />
</svg>
Alerts
</a>
</li>
</ul>
</nav>
</div>
<main>
<div class="cards">
<div class="card">
<h2>Settings</h2>
<p>This could be some sort of settings or interface panel where you can adjust your preferences. Maybe you want to give the option to show text next to the icons instead of collapsed ones. In that case you can check the following checkbox and the width will animate thanks to <br /><code>interpolate-size: allow-keywords</code>.</p>
<label class="expand">
<input type="checkbox" class="toggle-nav" />
Expand navigation
</label>
</div>
<div class="card">
<h2>Notification</h2>
<p>Another nice to have with <code>interpolate-size: allow-keywords</code> is quickly show full content height for example:</p>
<div class="alert" role="alert" id="alert">
<h3>This is a warning</h3>
<div class="text">With a whole lot of text that you might not want to show right away. 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.
</div>
<button aria-expanded="false" aria-controls="alert" aria-label="Toggle alert height">
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 24 24" aria-hidden="true">
<path fill="currentColor" d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10s10-4.48 10-10S17.52 2 12 2m0 12l-4-4h8z" />
</svg>
</button>
</div>
</div>
<div class="card">
<h2>More</h2>
This is just the beginning. It is just one of those quality of life improvements that makes animation a lot less tedious. From alerts, to navigations to accordions. This is defintatly one for my reset CSS :)
</div>
</div>
</main>
</div>
@import url("https://fonts.googleapis.com/css2?family=REM:ital,wght@0,100..900;1,100..900&display=swap");
@layer reset, presentation, navigation, controls;
@layer presentation {
:root {
--icon-size: 2rem;
--base-padding: 1rem;
@supports (interpolate-size: allow-keywords) {
interpolate-size: allow-keywords;
}
@media (width < 500px) {
--icon-size: 1.4rem;
--base-padding: 0.5rem;
}
}
}
/* Navigation and alert have more presentational styles, but to keep the demo on point, I show what happens ot hem in a seperate layer */
@layer navigation {
nav {
width: var(--icon-size);
overflow: clip;
transition: width 0.4s ease-out;
a {
display: grid;
grid-template-columns: var(--icon-size) auto;
align-items: center;
gap: 8px;
text-wrap: nowrap;
}
}
}
@layer alert {
.alert {
position: relative;
.text {
position: relative;
height: 70px;
transition: height 0.4s ease-out;
overflow: clip;
&::after {
position: absolute;
content: "";
inset-inline: 0;
inset-block-end: 0;
height: 15px;
background: linear-gradient(180deg, transparent 0%, #e8ddb5 100%);
transition: opacity 0.3s ease-out;
}
}
&:has(button[aria-expanded="true"]) .text {
height: auto;
&::after {
opacity: 0;
}
}
}
}
@layer controls {
.wrapper:has(.toggle-nav:checked) nav {
width: auto;
}
}
/* From here on it's mostly just presentation, I sometimes get carried away a bit :) */
@layer presentation {
.wrapper {
display: grid;
grid-template-columns: auto 1fr;
min-height: 100dvh;
}
.sidebar {
border-right: 4px solid #666a86;
padding: var(--base-padding);
background: #333333;
}
nav {
position: sticky;
top: 0;
a {
color: #93e1d8;
padding-block: calc(var(--base-padding) / 2);
text-decoration: none;
transition: color 0.4s ease-out;
&:is(:hover, :focus) {
color: #95b8d1;
}
}
}
h2 {
margin: 0;
padding-bottom: var(--base-padding);
margin-bottom: var(--base-padding);
border-bottom: 4px double #95b8d1;
font-size: 2rem;
letter-spacing: 0.04em;
}
.alert {
background: #e8ddb5;
border-radius: 0.5rem;
color: #333;
padding: 1rem;
button {
position: absolute;
bottom: 0;
right: 0;
background: none;
border: none;
color: #333;
transition: all 0.2s ease-out;
transform-origin: center;
cursor: pointer;
&:is(:hover, :focus) {
color: #666a86;
}
&[aria-expanded="true"] {
rotate: -180deg;
}
}
h3 {
margin: 0;
padding-bottom: calc(var(--base-padding) / 2);
margin-bottom: calc(var(--base-padding) / 2);
border-bottom: 4px double #dfbfaa;
font-size: 1.2rem;
letter-spacing: 0.02em;
}
}
.cards {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(35ch, 100%), 1fr));
gap: 30px;
padding: var(--base-padding);
}
.card {
background: #333;
padding: calc(var(--base-padding) * 2);
border-radius: 1rem;
border-width: 8px;
border-color: #666a86;
border-style: groove ridge ridge groove;
}
.expand {
display: flex;
align-items: center;
gap: 0.5rem;
font-weight: 700;
margin-top: 1.6rem;
cursor: pointer;
}
input[type="checkbox"] {
accent-color: #95b8d1;
width: 1.3rem;
aspect-ratio: 1;
}
}
@layer reset {
*,
*::before,
*::after {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100dvh;
background: #edafb8;
font-family: "REM", sans-serif;
font-size: 1.1rem;
line-height: 1.6;
color: #fff;
@media (width < 500px) {
font-size: 0.95rem;
}
}
ul[role="list"] {
margin: 0;
padding: 0;
list-style: none;
}
}
const buttons = document.querySelectorAll("button[aria-expanded]");
buttons.forEach((button) => {
button.addEventListener("click", () => {
const isExpanded = button.getAttribute("aria-expanded") === "true";
button.setAttribute("aria-expanded", !isExpanded);
});
});
Also see: Tab Triggers