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.
<nav aria-hidden="true" class="fake-nav">
<ul>
<li>
<svg class="bear-logo" viewBox="0 0 793 468" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100.937 244.397C49.2932 231.644 11 185.005 11 129.422C11 64.0195 64.0195 11 129.422 11C175.508 11 215.445 37.325 235.016 75.7579C273.571 54.9524 317.697 43.1437 364.581 43.1437H428.868C475.541 43.1437 519.48 54.8465 557.912 75.4777C577.534 37.1971 617.389 11 663.362 11C728.765 11 781.785 64.0195 781.785 129.422C781.785 184.782 743.798 231.27 692.469 244.241" stroke="black" stroke-width="21" stroke-linejoin="round" />
<rect x="253.112" y="228.5" width="284.056" height="42.5905" fill="#FF1E1E" />
<path fill-rule="evenodd" clip-rule="evenodd" d="M613.051 96.1181C670.715 142.386 703.111 215.526 703.111 280.959L504.955 280.959V240.491C504.955 218.952 487.494 201.491 465.955 201.491L324.324 201.491C302.785 201.491 285.324 218.952 285.324 240.491V280.959L88.1448 280.959C88.1448 215.526 120.54 142.386 178.204 96.1181C235.869 49.8504 314.078 23.8574 395.628 23.8574C477.177 23.8574 555.387 49.8504 613.051 96.1181Z" fill="black" />
<circle cx="572.438" cy="364.836" r="25.9698" fill="black" />
<circle cx="223.403" cy="364.836" r="25.9698" fill="black" />
<path d="M464.755 411.776C464.755 438.167 433.036 467.871 397.753 467.871C362.47 467.871 330.751 438.167 330.751 411.776C330.751 385.385 362.47 372.302 397.753 372.302C433.036 372.302 464.755 385.385 464.755 411.776Z" fill="black" />
</svg>
</li>
<li>
<strong>CodePen</strong>
</li>
<li>File</li>
<li>Edit</li>
<li>Find</li>
<li>View</li>
<li>Tools</li>
<li>Window</li>
</ul>
</nav>
<nav class="expose" popover id=nav>
<ul>
<li>
<a href="#home" title="Home">
<span>Home</span>
</a>
</li>
<li>
<a href="#projects" title="Projects">
<span>Projects</span>
</a>
</li>
<li>
<a href="#contact" title="Contact">
<span>Contact</span>
</a>
</li>
<li>
<a href="#writing" title="Writing">
<span>Writing</span>
</a>
</li>
<li>
<a href="#links" title="Links">
<span>Links</span>
</a>
</li>
</ul>
</nav>
<section id="#home" data-current="true">
<div class="section__content">
<div class="section__header">
<span></span>
<span></span>
<span></span>
</div>
<h2>App Exposé<br><span>with View Transitions</span></h2>
<p>Animate grid positions using the View Transitions API. Overlay a nav using the Popover API. Use <kbd>Esc</kbd> to exit exposé mode or choose a "Tab".</p>
<p>Click the button below!</p>
</div>
</section>
<section id="#projects">
<div class="section__content">
<div class="section__header">
<span></span>
<span></span>
<span></span>
</div>
<h2>Projects</h2>
<p>Don't forget to show off all of your cool work!</p>
</div>
</section>
<section id="#contact">
<div class="section__content">
<div class="section__header">
<span></span>
<span></span>
<span></span>
</div>
<h2>Contact</h2>
<p>Maybe throw in a contact form or something.</p>
</div>
</section>
<section id="#writing">
<div class="section__content">
<div class="section__header">
<span></span>
<span></span>
<span></span>
</div>
<h2>Writing</h2>
<p>Use this section for all your blog posts and stuff.</p>
</div>
</section>
<section id="#links">
<div class="section__content">
<div class="section__header">
<span></span>
<span></span>
<span></span>
</div>
<h2>Links</h2>
<p>Put all your cool links here for your friends.</p>
</div>
</section>
<button popovertarget=nav>
<span class="sr-only">Open Menu</span>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
<path d="M11.644 1.59a.75.75 0 01.712 0l9.75 5.25a.75.75 0 010 1.32l-9.75 5.25a.75.75 0 01-.712 0l-9.75-5.25a.75.75 0 010-1.32l9.75-5.25z" />
<path d="M3.265 10.602l7.668 4.129a2.25 2.25 0 002.134 0l7.668-4.13 1.37.739a.75.75 0 010 1.32l-9.75 5.25a.75.75 0 01-.71 0l-9.75-5.25a.75.75 0 010-1.32l1.37-.738z" />
<path d="M10.933 19.231l-7.668-4.13-1.37.739a.75.75 0 000 1.32l9.75 5.25c.221.12.489.12.71 0l9.75-5.25a.75.75 0 000-1.32l-1.37-.738-7.668 4.13a2.25 2.25 0 01-2.134-.001z" />
</svg>
</button>
*,
*:after,
*:before {
box-sizing: border-box;
}
* {
box-sizing: border-box;
}
body {
background: url('https://i.redd.it/bwtmgb168k651.jpg');
background-size: cover;
display: grid;
grid-template-columns: repeat(var(--grid-size), 1fr);
grid-template-rows: repeat(var(--grid-size), 1fr);
min-height: 100vh;
font-family: sans-serif, system-ui;
}
:root {
--grid-size: 20;
}
[popover] {
position: fixed;
inset: 0;
margin: 0;
width: unset;
height: unset;
border: 0;
display: none;
background: transparent;
}
[popover]:popover-open {
display: block;
}
.fake-nav {
position: fixed;
height: 2rem;
left: 0;
right: 0;
display: flex;
align-items: center;
background: hsl(0 0% 90% / 0.75);
backdrop-filter: blur(4px);
translate: 0 -100%;
view-transition-name: nav;
}
.fake-nav ul {
display: flex;
list-style-type: none;
align-items: center;
gap: 1rem;
padding: 0 1rem;
}
.bear-logo {
height: 1rem;
}
[data-exposed=true] .fake-nav {
translate: 0 0;
}
.expose {
position: fixed;
inset: 0;
z-index: 10;
padding: 0;
}
a {
text-decoration: none;
}
a span {
font-weight: bold;
background: hsl(0 0% 80% / 0.75);
backdrop-filter: blur(4px);
padding: 0.5rem 1rem;
border-radius: 0.25rem;
opacity: 0;
color: hsl(0 0% 20%);
text-decoration: none;
}
a:is(:hover, :focus-visible) span {
opacity: 1;
}
.expose > ul {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
display: grid;
grid-template-columns: repeat(var(--grid-size), 1fr);
grid-template-rows: repeat(var(--grid-size), 1fr);
list-style-type: none;
}
.expose li {
display: grid;
place-items: center;
grid-area: var(--y, 1) / var(--x, 1) / span var(--span, 1) / span var(--span, 1);
}
li a {
height: 100%;
width: 100%;
display: grid;
place-items: center;
}
h2 {
font-size: clamp(3rem, 4vw + 1rem, 10rem);
text-align: center;
}
section {
overflow: hidden;
grid-column: 1 / -1;
grid-row: 1 / -1;
position: relative;
}
[data-current=true] { z-index: 2; }
body > button {
view-transition-name: launch;
position: fixed;
bottom: 2rem;
left: 50%;
translate: -50% 0;
border-radius: 50%;
aspect-ratio: 1;
z-index: 10;
border: 0;
display: grid;
place-items: center;
cursor: pointer;
width: 48px;
box-shadow: 0rem 0.5rem 1rem hsl(0 0% 0% / 0.5);
}
body > button:is(:focus-visible) {
outline: 0.3rem solid hsl(210 100% 60%);
outline-offset: 0.25em;
}
[data-exposed=true] > button {
translate: -50% 200%;
}
body > button svg {
width: 75%;
fill: hsl(0 0% 10%);
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
nav li:hover a,
nav a:focus-visible {
outline: 0.3rem solid hsl(210 100% 60%);
outline-offset: 0.25em;
}
[data-exposed=true] section {
grid-area: var(--y, 1) / var(--x, 1) / span var(--span, 1) / span var(--span, 1);
overflow: hidden;
position: relative;
filter: drop-shadow(0.5rem 1rem 1rem hsl(0 0% 10% / 0.75));
}
[data-exposed=true] .section__content {
scale: calc((1 / var(--grid-size)) * var(--span, 1));
position: absolute;
top: 0%;
left: 0%;
translate: 0% 0%;
transform-origin: 0% 0;
}
.section__content {
width: 100vw;
min-height: 100vh;
border-radius: 1rem;
background: hsl(0 0% 10%);
overflow: hidden;
position: relative;
display: grid;
place-items: center;
align-content: center;
gap: 1rem;
color: hsl(0 0% 98%);
padding: 1rem;
}
p {
width: 66ch;
max-width: 100%;
text-align: center;
}
h2 {
margin: 0;
line-height: 1.5;
background: linear-gradient(90deg, hsl(0 0% 50%), hsl(0 0% 98%), hsl(0 0% 50%));
color: transparent;
background-clip: text;
}
h2 span {
font-weight: 300;
font-size: 0.65em;
font-variant: small-caps;
}
section:nth-of-type(even) .section__content {
background: hsl(0 0% 100%);
color: hsl(0 0% 10%);
}
section:nth-of-type(even) .section__content h2 {
background: linear-gradient(90deg, hsl(0 0% 50%), hsl(0 0% 8%), hsl(0 0% 50%));
color: transparent;
background-clip: text;
}
.section__header {
height: 2rem;
position: absolute;
top: 0;
left: 0;
right: 0;
background: hsl(0 0% 90%);
display: flex;
padding: 0 1rem;
align-items: center;
gap: 0.5rem;
}
.section__header span {
height: 40%;
border: 1px solid hsl(0 0% 50%);
aspect-ratio: 1;
background: hsl(0 0% 80%);
border-radius: 50%;
}
.section__header span:nth-of-type(1) {
background: hsl(10 100% 50%);
}
.section__header span:nth-of-type(2) {
background: hsl(45 100% 70%);
}
.section__header span:nth-of-type(3) {
background: hsl(150 100% 40%);
}
/* Home */
:is(li, section):nth-of-type(4) {
--hue: 150;
--x: 11;
--y: 7;
--span: 8;
}
/* Projects */
:is(li, section):nth-of-type(2) {
--hue: 210;
--x: 2;
--y: 2;
--span: 5;
}
/* Contact */
:is(li, section):nth-of-type(3) {
--hue: 280;
--x: 13;
--y: 2;
--span: 4;
}
/* Writing */
:is(li, section):nth-of-type(1) {
--hue: 320;
--x: 2;
--y: 10;
--span: 8;
}
/* Links */
:is(li, section):nth-of-type(5) {
--hue: 20;
--x: 14;
--y: 16;
--span: 4;
}
const SECTIONS = document.querySelectorAll('section')
const ANCHORS = document.querySelectorAll('a')
const POPOVER = document.querySelector('#nav')
SECTIONS.forEach((s, index) => {
s.style.viewTransitionName = `section--${index}`
})
let exposed = false
const LAUNCH = (event) => {
if (event) {
exposed = event.newState === 'open' ? true : false
} else {
exposed = false
POPOVER.hidePopover()
}
document.startViewTransition(() => {
document.body.dataset.exposed = exposed
})
}
const SELECT = event => {
ANCHORS.forEach(ANCHOR => {
ANCHOR[event.currentTarget.href === ANCHOR.href ? 'setAttribute' : 'removeAttribute']('autofocus', true)
})
SECTIONS.forEach(SECTION => {
SECTION.dataset.current = event.currentTarget.getAttribute('href') === SECTION.id ? true : false
})
LAUNCH()
}
ANCHORS.forEach(anchor => anchor.addEventListener('click', SELECT))
POPOVER.addEventListener('beforetoggle', LAUNCH)
Also see: Tab Triggers