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="site">
<header>
<nav>
<ul role="list">
<li>
<a href="#first">First</a>
</li>
<li>
<a href="#second">Second</a>
</li>
<li>
<a href="#third">Third</a>
</li>
<li>
<a href="#slider">Slider</a>
</li>
<li>
<a href="#overflow">Overflow</a>
</li>
</ul>
</nav>
</header>
<main>
<section id="first">
This is the first section. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum enim laborum aliquam quos beatae? Reprehenderit quibusdam sapiente mollitia nostrum sed consectetur, asperiores eveniet magnam quae quisquam quidem voluptas eligendi nam officiis harum vero maiores ab soluta iste. Id impedit, inventore dolor, totam esse eum, repudiandae dignissimos amet quo possimus ex. Lorem ipsum dolor sit amet consectetur adipisicing elit. Minus provident perspiciatis accusamus vel consequuntur doloribus, fugiat laudantium incidunt consequatur ipsam suscipit aliquid in culpa neque quae tenetur. Modi, labore autem!
</section>
<section id="second">
This is the second section. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum enim laborum aliquam quos beatae? Reprehenderit quibusdam sapiente mollitia nostrum sed consectetur, asperiores eveniet magnam quae quisquam quidem voluptas eligendi nam officiis harum vero maiores ab soluta iste. Id impedit, inventore dolor, totam esse eum, repudiandae dignissimos amet quo possimus ex. Lorem ipsum dolor sit amet consectetur adipisicing elit. Excepturi possimus reiciendis quaerat, architecto culpa debitis molestiae numquam sequi deleniti qui corporis doloribus quibusdam ut pariatur magnam illo voluptatum vitae rerum natus aspernatur ab iste tempora! Corporis ipsa quam necessitatibus esse.
</section>
<section id="third">
This is the third section. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum enim laborum aliquam quos beatae? Reprehenderit quibusdam sapiente mollitia nostrum sed consectetur, asperiores eveniet magnam quae quisquam quidem voluptas eligendi nam officiis harum vero maiores ab soluta iste. Id impedit, inventore dolor, totam esse eum, repudiandae dignissimos amet quo possimus ex. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit possimus assumenda quo praesentium dolorem esse asperiores rerum quod error quasi, sit ex accusantium architecto quaerat excepturi impedit repellat porro, culpa numquam est aut. Aut unde perferendis temporibus officiis possimus nobis reprehenderit rerum similique illum architecto?
</section>
<section id="slider">
<figure>
<img src='https://images.unsplash.com/photo-1631466266525-53e979c9e29b?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYzMjg1NDI4NQ&ixlib=rb-1.2.1&q=80&w=800' alt=''>
<figcaption>
<h1>This is a caption</h1>
</figcaption>
</figure>
<figure>
<img src='https://images.unsplash.com/photo-1630241040421-f777fdbc7c8e?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYzMjg1NDI3Nw&ixlib=rb-1.2.1&q=80&w=800' alt=''>
<figcaption>
<h1>This is a caption</h1>
</figcaption>
</figure>
<figure>
<img src='https://images.unsplash.com/photo-1631931020352-da7c5165e715?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYzMjg1NDI2Mg&ixlib=rb-1.2.1&q=80&w=800' alt=''>
<figcaption>
<h1>This is a caption</h1>
</figcaption>
</figure>
<figure>
<img src='https://images.unsplash.com/photo-1631168056607-dcb48cb3b63d?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYzMjg1NDI1NA&ixlib=rb-1.2.1&q=80&w=800' alt=''>
<figcaption>
<h1>This is a caption</h1>
</figcaption>
</figure>
</section>
<section id="overflow">
<div class="overflow">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Fugit maiores eius quidem labore magni temporibus fugiat repudiandae in ipsa voluptates aliquid debitis nesciunt sed itaque architecto, iste odio tenetur deserunt quam quas velit ipsum delectus accusantium. Natus totam tempora labore, eveniet consectetur veniam sequi illo numquam quas fugit, et in, explicabo itaque velit nesciunt adipisci ea omnis! Id debitis repellendus recusandae exercitationem aperiam ad ducimus. Reiciendis dolorem consequatur distinctio repudiandae voluptates, necessitatibus, esse autem consectetur quibusdam earum vero ipsa corporis. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Sapiente quas dolores aspernatur debitis libero voluptatem quae, atque dicta ratione laborum quaerat! Nostrum eligendi facere totam doloribus dolore dolorum, distinctio veritatis quidem blanditiis iusto earum, aliquam nemo. Nisi eveniet facilis odit deserunt dolore, sapiente velit! Deserunt, odit quos doloribus eligendi suscipit ipsam repellendus voluptatem maiores deleniti obcaecati, consequuntur doloremque magni repellat neque nulla? Nulla dignissimos repellendus odit accusantium, deleniti beatae temporibus!
</div>
</section>
</main>
</div>
<!--<div id="mark"></div>-->
html {
--timing: .2s;
scroll-behavior: smooth;
scroll-padding-top: 60px;
}
body {
//overscroll-behavior: none;
}
.site {
display: grid;
grid:
auto /
minmax(1em, 1fr)
minmax(0, 600px)
minmax(1em, 1fr);
margin: 5rem auto;
}
main {
padding-bottom: 80vh;
}
header {
margin-bottom: 5rem;
position: sticky;
top: -1px;
z-index: 10;
box-shadow:
0 20px 25px -5px rgba(0, 0, 0, 0.0001),
0 10px 10px -5px rgba(0, 0, 0, 0.0001);
}
nav {
background: #24b47e;
overflow-x: auto;
width: 100%;
-webkit-overflow-scrolling: touch;
@media (max-width: 420px) {
background-image:
/* Shadows */
linear-gradient(to right, #24b47e, #24b47e),
linear-gradient(to right, #24b47e, #24b47e),
/* Shadow covers */
linear-gradient(to right, rgba(0,0,0,.2), rgba(255,255,255,0)),
linear-gradient(to left, rgba(0,0,0,.2), rgba(255,255,255,0));
background-position: left center, right center, left center, right center;
background-repeat: no-repeat;
background-color: #24b47e;
background-size: 20px 100%, 20px 100%, 10px 100%, 10px 100%;
/* Opera doesn't support this in the shorthand */
background-attachment: local, local, scroll, scroll;
}
}
nav::-webkit-scrollbar {
display: none;
}
nav ul {
display: flex;
justify-content: space-evenly;
text-align: center;
flex-wrap: nowrap;
@media (max-width: 420px) {
justify-content: flex-start;
}
}
nav a {
color: #fff !important;
padding: 1rem;
display: inline-block;
font-weight: 700;
}
section + section {
margin-top: 3rem;
}
/* Slider */
#slider {
width: 100%;
overflow-x: auto;
display: grid;
grid: 400px / auto-flow 90%;
gap: 10px;
scroll-snap-type: x mandatory;
overscroll-behavior-x: contain;
padding-bottom: 1em;
perspective: 2px;
transform-style: preserve-3d;
}
figure {
display: grid;
place-items: end center;
scroll-snap-align: center;
scroll-snap-stop: always;
overflow: hidden;
background: #000;
transform-style: preserve-3d;
}
img {
height: 100%;
width: 100%;
object-fit: cover;
transform: translateZ(-1px) scale(1.6);
opacity: 0.5;
will-change: transform;
}
img,
figcaption {
grid-area: 1 / 1;
}
figcaption {
padding: 2rem;
z-index: 1;
}
h1 {
font-size: 3rem;
color: #fff;
}
/* Overflow */
.overflow {
height: 300px;
overflow: auto;
overscroll-behavior: contain;
padding: 2rem;
background: #73e4a2;
border-radius: 4px;
box-shadow:
0 20px 25px -5px rgba(0, 0, 0, 0.1),
0 10px 10px -5px rgba(0, 0, 0, 0.04);
color: #005450;
}
#mark {
position: absolute;
width: 1px;
height: 1px;
top: calc(var(--top) * 1px);
left: 0;
}
html,
body {
height: 100%;
background: #f2f7f1;
}
/* Header effect */
.site > :not(header) {
grid-column: 2 / -2;
}
header {
display: grid;
grid: inherit;
grid-column: 1 / -1;
}
header > * {
grid-column: 2 / -2;
}
header:before,
header:after {
content: '';
background: #24b47e;
transform: scaleX(var(--resize, 0));
transition: var(--timing) cubic-bezier(.5, 0, .5, 1);
z-index: -1;
}
header:before {
grid-column-start: 1;
transform-origin: right;
}
header:after {
grid-column-start: 3;
transform-origin: left;
}
/*.resize-box header:before,
.resize-box header:after {
--resize: 1;
}*/
.resize-box::before,
.resize-box::after {
--resize: 1;
}
header {
transition: calc(var(--timing) * .25) box-shadow;
}
/*.resize-box header {
transition: calc(var(--timing) * 1.25) calc(var(--timing) * .25) box-shadow cubic-bezier(.5, 0, .5, 1);
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}*/
.resize-box {
transition: calc(var(--timing) * 1.25) calc(var(--timing) * .25) box-shadow cubic-bezier(.5, 0, .5, 1);
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
//const bd = document.body;
const header = document.querySelector('header');
/*const headerTop = document.querySelector('header').getBoundingClientRect().top;
bd.style.setProperty('--top', headerTop)*/
/*let observer = new IntersectionObserver(entries => {
!entries[0].isIntersecting ?
bd.classList.add("resize-box") :
bd.classList.remove("resize-box")
});*/
const observer = new IntersectionObserver(
([e]) => e.target.classList.toggle("resize-box", e.intersectionRatio < 1),
{ threshold: 1 }
);
observer.observe(header);
Also see: Tab Triggers