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="support">Check this out in Chrome 115+ / Chrome Canary</div>
<nav>
<div class="nav__content">
<img
src="https://assets.codepen.io/605876/bear-2022--white.png"
alt=""
/>
<a
href="https://twitter.com/intent/follow?screen_name=jh3yy"
target="_blank"
>Follow</a
>
</div>
</nav>
<section>
<div class="section__content">
<h1>
<span>All-new</span>
<span>CSS Pro</span>
</h1>
</div>
</section>
<section>
<div class="cta">
<div class="cta__content">
<a
href="https://codepen.io/jh3y/details/zYyzYpY"
target="_blank"
rel="noopener noreferrer"
>
<span>Add to Bookmarks</span>
<span>
<svg
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="currentColor"
class="w-6 h-6"
>
<path
fill-rule="evenodd"
d="M12 3.75a.75.75 0 01.75.75v6.75h6.75a.75.75 0 010 1.5h-6.75v6.75a.75.75 0 01-1.5 0v-6.75H4.5a.75.75 0 010-1.5h6.75V4.5a.75.75 0 01.75-.75z"
clip-rule="evenodd"
/>
</svg>
</span>
</a>
</div>
</div>
<div class="section__content">
<p>
Dynamic call-to-action powered by <span>container queries</span> and
<span>scroll-driven animations</span>.
</p>
</div>
</section>
<section>
<video
src="https://assets.codepen.io/605876/seoul-21116.mp4"
autoplay
playsinline
muted
loop
></video>
<div class="cta">
<div class="cta__content">
<a
href="https://codepen.io/jh3y/details/zYyzYpY"
target="_blank"
rel="noopener noreferrer"
>
<span>Heart this pen (3x)</span>
<span>
<svg
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="currentColor"
class="w-6 h-6"
>
<path
d="M11.645 20.91l-.007-.003-.022-.012a15.247 15.247 0 01-.383-.218 25.18 25.18 0 01-4.244-3.17C4.688 15.36 2.25 12.174 2.25 8.25 2.25 5.322 4.714 3 7.688 3A5.5 5.5 0 0112 5.052 5.5 5.5 0 0116.313 3c2.973 0 5.437 2.322 5.437 5.25 0 3.925-2.438 7.111-4.739 9.256a25.175 25.175 0 01-4.244 3.17 15.247 15.247 0 01-.383.219l-.022.012-.007.004-.003.001a.752.752 0 01-.704 0l-.003-.001z"
/>
</svg>
</span>
</a>
</div>
</div>
<div class="section__content">
<p>
Define transition sequences using <span>style queries</span>. Then
toggle them with <span>scroll-driven animations</span>. Resulting in
<span>scroll-triggered animations</span>.
</p>
</div>
</section>
<section>
<div class="cta">
<div class="cta__content">
<a
href="https://twitter.com/intent/tweet?text=%22Apple%20Style%20CTA%20Reveal%20with%20CSS%20scroll-driven%20animations%22%20via%20%40jh3yy%0Ahttps://codepen.io/jh3y/pen/zYyzYpY"
target="_blank"
rel="noopener noreferrer"
>
<span>Share over on</span>
<span>
<svg
role="img"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
>
<title>X</title>
<path
d="M18.901 1.153h3.68l-8.04 9.19L24 22.846h-7.406l-5.8-7.584-6.638 7.584H.474l8.6-9.83L0 1.154h7.594l5.243 6.932ZM17.61 20.644h2.039L6.486 3.24H4.298Z"
/>
</svg>
</span>
</a>
</div>
</div>
<div class="section__content">
<h2><span>Become a</span><span>CSS Pro</span></h2>
</div>
</section>
<section>
<h2>fin.</h2>
</section>
* {
box-sizing: border-box;
}
body {
display: grid;
place-items: center;
min-height: 100vh;
font-family: SF Pro Text, SF Pro Icons, Helvetica Neue, Helvetica, Arial, sans-serif;
color: hsl(0 0% 100%);
background: hsl(0, 0%, 6%);
}
section {
min-height: 100vh;
display: grid;
place-items: center;
}
.section__content {
min-height: 100vh;
position: sticky;
top: 0;
width: 100vw;
display: grid;
place-items: center;
padding: 1rem;
width: 60ch;
max-width: 100vw;
margin: 0 auto;
}
.section__content p {
font-weight: 600;
max-width: 40ch;
font-size: clamp(1rem, 1vw + 1rem, 4rem);
margin: 0;
color: hsl(0 0% 100% / 0.5);
}
.section__content h2 {
text-align: left;
display: grid;
gap: 0;
}
.section__content h2 span:first-of-type {
opacity: 0.5;
padding-left: 1rem;
font-size: clamp(1rem, 1vw + 1rem, 4rem);
}
.section__content h2 span:last-of-type {
background: linear-gradient(
90deg,
hsl(0 0% 100%),
hsl(0 0% 80%) 50%,
hsl(240deg 100% 75%),
hsl(320deg 100% 75%),
hsl(140deg 100% 75%),
hsl(10deg 100% 75%)
);
-webkit-background-clip: text;
color: transparent;
background-size: 300% 200%;
animation: bg-move both linear;
animation-timeline: --section;
animation-range: cover 0% exit 0%;
background-position: 0 0;
}
@keyframes bg-move {
to {
background-position: 100% 200%;
}
}
.section__content p span {
color: hsl(0 0% 100% / 1);
}
:is(h1, h2) {
margin: 0;
font-size: 2.5rem;
}
section:nth-of-type(1),
section:nth-of-type(2),
section:nth-of-type(3),
section:nth-of-type(4) {
position: relative;
width: 100vw;
display: block;
view-timeline-name: --section;
}
/* CTA Specific stuff goes here.... */
.cta {
position: sticky;
z-index: 10;
top: calc(100% - 6rem);
display: inline-block;
width: 100%;
display: grid;
place-items: center;
/* Activates showing the CTA */
animation: activate both linear, activate linear reverse;
animation-timeline: --section, view();
animation-range: entry, cover 50%;
}
.cta__content {
position: relative;
}
/* Word */
.cta span:nth-of-type(1) {
opacity: var(--scale, 0);
transition: opacity 0.2s 0.6s;
white-space: nowrap;
padding: 0 0 0 0.5rem;
}
/* The Bloom */
.cta__content::before {
--back: linear(
0, 0.3412 4.06%, 0.6411 8.2%,
0.9005 12.43%, 1.1205 16.77%,
1.3013 21.22%, 1.4438 25.8%,
1.549 30.54%, 1.5878 32.98%,
1.6175 35.47%, 1.6457 39.41%,
1.6518 41.44%, 1.6528 43.52%,
1.6391 47.83%, 1.6042 52.44%,
1.5562 56.74%, 1.4899 61.5%,
1.202 78.86%, 1.0988 85.97%,
1.0551 89.79%, 1.0244 93.36%,
1.0061 96.75%, 1
);
content: "";
background: hsl(210 100% 45%);
position: absolute;
inset: 0;
border-radius: 100px;
z-index: -1;
}
/* The icon holder */
.cta span:nth-of-type(2) {
width: 36px;
height: 36px;
border-radius: 50%;
background: hsl(210 100% 45%);
color: white;
padding: 0.25rem;
display: grid;
place-items: center;
}
.cta svg {
width: 20px;
fill: hsl(0 0% 100% / 0.75);
}
.cta a:is(:hover, :focus-visible) svg {
fill: white;
}
.cta a {
--elastic: linear(
0, 0.4789 7.06%, 0.7612 12.38%,
0.8693 15.13%, 0.9538 17.95%,
1.0165 20.89%, 1.059 24.04%,
1.0829 27.58%, 1.0884 31.64%,
1.0769 36.44%, 1.0202 50.6%,
1.0005 59.62%, 0.9945 70.6%, 1
);
text-decoration-line: none;
overflow: hidden;
border-radius: 100px;
padding: 1rem;
background: hsl(240 2% 20% / 1);
box-shadow: 0 1px hsl(0 0% 100% / 0.25) inset;
color: hsl(0 0% 100%);
display: grid;
align-items: center;
font-weight: 600;
letter-spacing: -0.01em;
font-size: 1.1rem;
grid-template-columns: 0 36px;
}
@keyframes activate {
0% { --active: 0; }
100% { --active: 1; }
}
section:nth-of-type(1) {
height: 200vh;
}
section:nth-of-type(2) {
--content-size: 186px;
height: 400vh;
}
section:nth-of-type(3) {
--content-size: 180px;
height: 300vh;
}
section:nth-of-type(4) {
--content-size: 140px;
height: 500vh;
}
/* Use style queries to dictate the timing, etc. */
@container style(--active: 0) {
.cta__content::before {
scale: 0;
opacity: 0;
transition: scale 0.5s var(--back);
}
.cta a {
scale: 0;
transition: scale 0.2s 0.7s, grid-template-columns 0.5s 0.2s var(--elastic);
grid-template-columns: 0 36px;
}
.cta__content span:first-of-type {
opacity: 0;
transition: opacity 0.2s 0s;
}
.cta__content span:last-of-type {
scale: 0;
opacity: 0;
transition: scale 0.2s, opacity 0.2s;
}
}
@container style(--active: 1) {
.cta__content::before {
scale: 0.99;
opacity: 1;
transition: scale 0.5s var(--back);
}
.cta a {
scale: 1;
transition: scale 0.2s 0s, grid-template-columns 0.5s 0.6s var(--elastic);
grid-template-columns: var(--content-size, auto) 36px;
}
.cta__content span:first-of-type {
opacity: 1;
transition: opacity 0.2s 0.7s;
}
.cta__content span:last-of-type {
scale: 1;
opacity: 1;
transition: scale 0.2s 0.4s, opacity 0.2s 0.4s;
}
}
/* Nav stuff */
nav {
position: fixed;
top: 0;
left: 0;
right: 0;
border-bottom: 1px solid hsl(0 0% 50%);
height: 52px;
background: hsl(0 0% 20% / 0.75);
backdrop-filter: blur(4px);
z-index: 2;
}
.nav__content {
display: flex;
align-items: center;
justify-content: space-between;
width: 800px;
max-width: 100vh;
padding: 0 1rem;
margin: 0 auto;
height: 100%;
}
nav a {
text-decoration: none;
background: hsl(210 100% 45%);
color: hsl(0 0% 98%);
font-weight: 400;
padding: 0.5rem 1rem;
border-radius: 100px;
font-size: 0.875rem;
}
nav img {
height: 50%;
justify-self: start;
}
.support {
position: fixed;
z-index: 10;
left: 1rem;
top: 1rem;
background: white;
color: black;
padding: 2rem;
border: 4px solid hsl(45 80% 50%);
}
@supports (animation-timeline: view()) {
.support {
display: none;
}
}
/* Heading */
h1 {
display: grid;
}
:is(h1, h2) {
font-size: clamp(2.5rem, 7vw + 1rem, 10rem);
text-align: center;
line-height: 1;
margin: 0;
width: 100%;
}
h1 {
position: fixed;
top: 50%;
left: 50%;
translate: -50% -50%;
}
h1 span:first-of-type {
display: inline-block;
color: hsl(0 100% 50%);
font-size: 0.35em;
}
h1 span:last-of-type {
display: inline-block;
}
h1 span:first-of-type {
display: inline-block;
animation: fade-away both linear;
animation-timeline: --section;
animation-range: entry-crossing 50% exit 50%;
}
h1 span:last-of-type {
display: inline-block;
animation: scale-up both cubic-bezier(.1,.7,.9,1.3), fade-away both linear;
animation-timeline: --section;
animation-range: entry-crossing 60% exit 70%, exit 10% exit 50%;
}
@keyframes scale-up {
to {
scale: 1.5;
}
}
@keyframes grow {
0% {
scale: 0.5;
opacity: 0;
}
}
@keyframes fade-away {
100% {
opacity: 0;
}
}
video {
position: fixed;
inset: 0;
object-fit: cover;
width: 100%;
height: 100vh;
z-index: -1;
filter: saturate(0.1) brightness(0.5);
opacity: 0;
animation: fade-in both linear, fade-out both linear;
animation-timeline: --section;
animation-range: entry 10% entry 15%, exit 10% exit 15%;
}
@keyframes fade-in {
to {
opacity: 0.2;
}
}
@keyframes fade-out {
to {
opacity: 0;
}
}
Also see: Tab Triggers