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="resizer">
<section class="scroller">
<article>
<div class="indicator indicator--top">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M4.5 15.75l7.5-7.5 7.5 7.5" />
</svg>
</div>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Amet animi consequatur atque accusantium soluta cumque, temporibus ipsam eos voluptas porro architecto expedita quisquam eum et necessitatibus culpa odio, laudantium reprehenderit.</p>
<p>Maxime perferendis nostrum, temporibus quibusdam delectus, rerum laudantium ad eius reprehenderit labore accusamus voluptatibus doloremque, eveniet autem veritatis nulla nam ipsum quaerat repudiandae ut perspiciatis iste. Voluptatibus quasi ea natus.</p>
<p>Optio sapiente ipsum, non autem aspernatur aperiam magnam! Vel accusantium unde quibusdam neque. A ullam quod quia aspernatur molestias voluptatem ea in deleniti ad explicabo, pariatur facilis harum inventore aliquam.</p>
<p>Excepturi suscipit nulla iure sit, doloremque numquam. Ullam id, earum neque cum accusamus debitis illo, dolorem nostrum iste amet optio culpa. Vero labore architecto, soluta at placeat dolorum aliquam debitis.</p>
<p>Minus amet laudantium ex ab. Harum praesentium in quia accusantium aut perferendis iure inventore impedit officiis, pariatur excepturi voluptate nostrum ipsam quam quod recusandae voluptatibus sit cupiditate fugit ducimus distinctio.</p>
<p>Cumque, dolorum. Vitae, odio tempore. Illum unde architecto eligendi et. Non quibusdam iusto adipisci ullam est porro magni mollitia neque laboriosam doloribus tempore modi laudantium nostrum fugit, provident sunt dolorum!</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repellendus, quis deserunt. Nemo aliquid ratione magni labore asperiores. Consequuntur, laborum perspiciatis porro optio soluta, nesciunt est laudantium eligendi voluptatum quos vel?</p>
<p>Doloremque eligendi velit voluptas eveniet veniam nesciunt, esse harum exercitationem laborum, soluta ad, vitae ut ullam consequuntur culpa inventore reiciendis iste dolorum! Incidunt corrupti eligendi officiis dolor nemo quidem recusandae.</p>
<p>Animi inventore culpa eum eaque sed tempore illo, ipsa ea optio soluta atque itaque quos beatae dolore. Nam aliquid inventore itaque ab perferendis ratione soluta quod est, doloribus fugit magni.</p>
<p>Ad excepturi ex veniam quam quas nesciunt deleniti suscipit voluptatem omnis enim. Soluta magni dolore nostrum omnis? Tempora soluta doloremque vel veritatis, repellendus dolorem dicta dignissimos quaerat atque, recusandae quis.</p>
<p>Culpa beatae recusandae impedit unde saepe quos explicabo alias reprehenderit accusantium laudantium aspernatur, commodi veniam quasi vel ratione corrupti aliquam consequatur similique enim sunt! Quod facere cum at saepe cumque.</p>
<p>Rem eos laudantium culpa enim quibusdam, in consequatur non ea, iste illum minima aperiam accusamus ducimus repudiandae soluta, blanditiis at debitis magni excepturi delectus? Inventore necessitatibus laudantium accusantium ullam ad.</p>
<p>Alias deserunt possimus ipsum nemo provident dolore, reprehenderit id? Similique voluptas ipsa perferendis eius et, a, odit minus neque laboriosam modi quisquam, vel eum blanditiis! Aliquid soluta recusandae nostrum dolor.</p>
<p>Animi quas dolorum tempora consequatur sequi? Ratione ipsa consequuntur est quibusdam unde hic, inventore rerum alias, quasi aut maiores! Quaerat eligendi ut vitae, veniam officiis delectus animi repudiandae exercitationem! Ducimus.</p>
<p>Necessitatibus vitae porro, quos eum dolorem, aliquam corporis perspiciatis cumque facilis maxime nobis praesentium quia earum tempora quisquam provident ab laborum ea nostrum facere esse fugiat? Nostrum deleniti eligendi debitis.</p>
<p>Consequatur odit reprehenderit culpa, delectus libero pariatur placeat nobis ut, quidem cum molestias facere porro aperiam similique perferendis maxime ea debitis numquam, possimus hic. Quisquam modi ipsa consequuntur nemo sint!</p>
<div class="indicator indicator--bottom">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M19.5 8.25l-7.5 7.5-7.5-7.5" />
</svg>
</article>
</div>
</section>
</div>
<a
class="bear-link"
href="https://twitter.com/intent/follow?screen_name=jh3yy"
target="_blank"
rel="noreferrer noopener"
>
<svg
class="w-9"
viewBox="0 0 969 955"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle
cx="161.191"
cy="320.191"
r="133.191"
stroke="currentColor"
stroke-width="20"
></circle>
<circle
cx="806.809"
cy="320.191"
r="133.191"
stroke="currentColor"
stroke-width="20"
></circle>
<circle
cx="695.019"
cy="587.733"
r="31.4016"
fill="currentColor"
></circle>
<circle
cx="272.981"
cy="587.733"
r="31.4016"
fill="currentColor"
></circle>
<path
d="M564.388 712.083C564.388 743.994 526.035 779.911 483.372 779.911C440.709 779.911 402.356 743.994 402.356 712.083C402.356 680.173 440.709 664.353 483.372 664.353C526.035 664.353 564.388 680.173 564.388 712.083Z"
fill="currentColor"
></path>
<rect
x="310.42"
y="448.31"
width="343.468"
height="51.4986"
fill="#FF1E1E"
></rect>
<path
fill-rule="evenodd"
clip-rule="evenodd"
d="M745.643 288.24C815.368 344.185 854.539 432.623 854.539 511.741H614.938V454.652C614.938 433.113 597.477 415.652 575.938 415.652H388.37C366.831 415.652 349.37 433.113 349.37 454.652V511.741L110.949 511.741C110.949 432.623 150.12 344.185 219.845 288.24C289.57 232.295 384.138 200.865 482.744 200.865C581.35 200.865 675.918 232.295 745.643 288.24Z"
fill="currentColor"
></path>
</svg>
</a>
@import url('https://unpkg.com/normalize.css') layer(normalize);
@layer base {
* {
box-sizing: border-box;
}
:root {
--bg: hsl(0 0% 10%);
--color: hsl(0 0% 85%);
--line: hsl(0 0% 95% / 0.25);
--shadow: hsl(0 0% 0% / var(--shadow-alpha, 1));
--border: hsl(0 0% 20%);
color-scheme: dark only;
}
[data-light='true'] {
--bg: hsl(0 0% 85%);
--color: hsl(0 0% 10%);
--line: hsl(0 0% 5% / 0.25);
--shadow: hsl(0 0% 10% / var(--shadow-alpha, 1));
--border: hsl(0 0% 10%);
color-scheme: light only;
}
body {
display: grid;
place-items: center;
min-height: 100vh;
accent-color: hsl(250 90% 70%);
background: var(--bg);
font-family: 'SF Pro Text', 'SF Pro Icons', 'AOS Icons', 'Helvetica Neue';
line-height: 1.6;
color: var(--color);
}
body::before {
--size: 60px;
content: '';
height: 100vh;
width: 100vw;
position: fixed;
background: linear-gradient(
90deg,
var(--line) 1px,
transparent 1px var(--size)
)
0 -5vmin / var(--size) var(--size),
linear-gradient(var(--line) 1px, transparent 1px var(--size)) 0 -5vmin / var(
--size
) var(--size);
mask: linear-gradient(-15deg, transparent 80%, white);
top: 0;
z-index: -1;
}
p::selection {
background: hsl(10 100% 50% / 0.5);
}
}
@layer scroller {
.resizer {
width: 36ch;
aspect-ratio: 3 / 4;
resize: both;
overflow: hidden;
max-height: calc(100vh - 2rem);
}
.scroller {
width: 100%;
height: 100%;
overflow: auto;
position: relative;
background: canvas;
padding: 0 1rem;
border-radius: 0.5rem;
box-shadow: 0 0 2rem -1rem hsl(0 0% 10% / 0.75);
}
.scroller svg {
width: 24px;
}
}
@layer indicator {
[data-style='indicator'] {
.indicator {
position: sticky;
display: flex;
align-items: center;
justify-content: center;
background: canvas;
height: 48px;
scale: 1 1;
/* Scroll stuff */
}
.indicator::after {
content: '';
position: absolute;
z-index: -1;
inset: 0 -1rem;
background: canvas;
}
.indicator--top {
top: 0;
border-bottom: 1px solid currentColor;
opacity: calc(var(--scroll-progress-top) / 100);
}
.indicator--bottom {
bottom: 0;
border-top: 1px solid currentColor;
opacity: calc(1 - (var(--scroll-progress-bottom) / 100));
}
}
@supports (animation-timeline: scroll()) {
[data-style='indicator'] {
.indicator {
--scroll-buffer: 2rem;
opacity: 0;
animation: fade-in both linear;
animation-timeline: scroll(nearest);
animation-range: 0 var(--scroll-buffer);
}
.indicator--bottom {
animation-range: calc(100% - var(--scroll-buffer)) 100%;
animation-direction: reverse;
}
}
@keyframes fade-in {
to {
opacity: 1;
}
}
}
}
@layer shadow {
[data-style='shadow'] section {
border: 1px solid var(--border);
}
[data-style='shadow'] .scroller {
padding: 0;
background: canvas;
}
[data-style='shadow'] .scroller p {
padding: 0 1rem;
}
[data-style='shadow'] .indicator {
position: sticky;
height: 10px;
width: 100%;
}
[data-style='shadow'] .indicator::after {
content: '';
position: absolute;
height: calc(var(--shadow-height) * 1px);
width: 100%;
background: var(--shadow);
}
[data-style='shadow'] .indicator--top::after {
top: 0;
mask: linear-gradient(white, transparent);
}
[data-style='shadow'] .indicator--bottom::after {
bottom: 0;
mask: linear-gradient(transparent, white);
}
[data-style='shadow'] .indicator svg {
display: none;
}
[data-style='shadow'] .indicator--top {
transform-origin: 50% 0%;
top: 0;
scale: 1 calc(var(--scroll-progress-top) / 100);
}
[data-style='shadow'] .indicator--bottom {
transform-origin: 50% 100%;
bottom: 0;
scale: 1 calc(1 - (var(--scroll-progress-bottom) / 100));
}
@supports (animation-timeline: scroll()) {
[data-style='shadow'] {
.indicator {
--scroll-buffer: 1rem;
animation: reveal both linear;
animation-timeline: scroll(nearest);
animation-range: 0 var(--scroll-buffer);
}
.indicator--bottom {
animation-range: calc(100% - var(--scroll-buffer)) 100%;
animation-direction: reverse;
}
}
@keyframes reveal {
0% {
scale: 1 0;
}
}
}
}
@layer opening {
[data-style='opening'] section {
border-radius: 0;
}
[data-style='opening'] .scroller {
padding: 0;
background: transparent;
}
[data-style='opening'] .scroller p {
padding: 0 1rem;
}
[data-style='opening'] .indicator {
position: sticky;
height: 10px;
width: 100%;
}
[data-style='opening'] .indicator::after {
content: '';
position: absolute;
height: calc(var(--shadow-height) * 1px);
width: 100%;
background: var(--shadow);
}
[data-style='opening'] .indicator--top::after {
top: 0;
border-top: 1px solid var(--border);
mask: linear-gradient(white, transparent);
}
[data-style='opening'] .indicator--bottom::after {
bottom: 0;
border-bottom: 1px solid var(--border);
mask: linear-gradient(transparent, white);
}
[data-style='opening'] .indicator svg {
display: none;
}
[data-style='opening'] .indicator--top {
transform-origin: 50% 100%;
top: 0;
scale: 1 calc(var(--scroll-progress-top) / 100);
}
[data-style='opening'] .indicator--bottom {
transform-origin: 50% 0%;
bottom: 0;
scale: 1 calc(1 - (var(--scroll-progress-bottom) / 100));
}
@supports (animation-timeline: scroll()) {
[data-style='opening'] {
/* Animation stuff */
.indicator {
--scroll-buffer: 1rem;
animation: reveal both linear;
animation-timeline: scroll(nearest);
animation-range: 0 var(--scroll-buffer);
}
.indicator--bottom {
animation-range: calc(100% - var(--scroll-buffer)) 100%;
animation-direction: reverse;
}
}
@keyframes reveal {
0% {
scale: 1 0;
}
}
}
}
@layer mask {
[data-style='mask'] {
.resizer {
border-radius: 12px;
background: canvas;
}
.scroller {
--mask-size: 48px;
padding: 0;
background: transparent;
mask: linear-gradient(white, transparent) 50% 0 / 100% 0 no-repeat,
linear-gradient(white, white) 50% 50% / 100% 100% no-repeat,
linear-gradient(transparent, white) 50% 100% / 100% 100px no-repeat;
mask-composite: exclude;
mask-size:
100% calc((var(--scroll-progress-top) / 100) * 100px),
100% 100%,
100% calc((100 - (100 * (var(--scroll-progress-bottom) / 100))) * 1px);
}
.scroller p {
padding: 0 1rem;
}
.indicator {
display: none;
}
}
@supports (animation-timeline: scroll()) {
[data-style='mask'] {
.scroller {
mask: linear-gradient(white, transparent) 50% 0 / 100% 0 no-repeat,
linear-gradient(white, white) 50% 50% / 100% 100% no-repeat,
linear-gradient(transparent, white) 50% 100% / 100% 100px no-repeat;
mask-composite: exclude;
animation: mask-up both linear, mask-down both linear;
animation-timeline: scroll(self);
animation-range: 0 2rem, calc(100% - 2rem) 100%;
}
}
@keyframes mask-up {
100% {
mask-size: 100% 100px, 100% 100%, 100% 100px;
}
}
@keyframes mask-down {
100% {
mask-size: 100% 100px, 100% 100%, 100% 0;
}
}
}
}
@layer socials {
.bear-link {
color: currentColor;
position: fixed;
top: 1rem;
left: 1rem;
width: 48px;
aspect-ratio: 1;
display: grid;
place-items: center;
opacity: 0.8;
}
:where(.x-link, .bear-link):is(:hover, :focus-visible) {
opacity: 1;
}
.bear-link svg {
width: 75%;
}
}
import { Pane } from 'https://cdn.skypack.dev/tweakpane'
import gsap from 'https://cdn.skypack.dev/gsap@3.12.0'
import ScrollTrigger from 'https://cdn.skypack.dev/gsap@3.12.0/ScrollTrigger'
const CONFIG = {
style: 'opening',
light: false,
height: 12,
opacity: 0.5,
}
const CTRL = new Pane('Config')
CTRL.addBinding(CONFIG, 'style', {
options: { indicator: 'indicator', shadow: 'shadow', mask: 'mask', opening: 'opening' },
})
const height = CTRL.addBinding(CONFIG, 'height', { min: 0, max: 20, step: 1, label: 'size (px)'})
const alpha = CTRL.addBinding(CONFIG, 'opacity', { min: 0, max: 1, step: 0.01, label: 'alpha'})
height.hidden = true
alpha.hidden = true
const light = CTRL.addBinding(CONFIG, 'light', { label: 'light mode'})
const update = () => {
document.documentElement.dataset.style = CONFIG.style
document.documentElement.dataset.light = CONFIG.light
document.documentElement.style.setProperty('--shadow-alpha', CONFIG.opacity)
document.documentElement.style.setProperty('--shadow-height', CONFIG.height)
height.hidden = alpha.hidden = CONFIG.style === 'opening' || CONFIG.style === 'shadow' ? false : true
}
CTRL.on('change', () => {
if (!document.startViewTransition) return update()
document.startViewTransition(update)
})
update()
if (!CSS.supports('animation-timeline: scroll()')) {
console.info('falling back to GSAP')
gsap.registerPlugin(ScrollTrigger)
const scroller = document.querySelector('.scroller')
// In GSAP, jus' gonna do a scroll custom property based on the distance
ScrollTrigger.create({
scroller,
scrub: true,
start: 0,
end: 16,
ease: 'none',
trigger: 'article',
onUpdate: function(self) {
scroller.style.setProperty('--scroll-progress-top', self.progress * 100)
}
})
ScrollTrigger.create({
scroller,
trigger: 'article',
scrub: true,
ease: 'none',
start: () => {
return ScrollTrigger.maxScroll(scroller) - 16
},
end: () => {
return ScrollTrigger.maxScroll(scroller)
},
onUpdate: function(self) {
scroller.style.setProperty('--scroll-progress-bottom', self.progress * 100)
}
})
const obs = new ResizeObserver(ScrollTrigger.refresh)
obs.observe(scroller)
}
Also see: Tab Triggers