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 = [
- { name: "masthead" },
- { name: "tiles" },
- { name: "text" },
- { name: "two-columns" },
- { name: "subscribe" },
- ];
- var text = 'Lorem ipsum dolor, sit amet consectetur adipisicing elit. Culpa, tenetur deserunt! Obcaecati eius aut, facere porro amet atque laborum eos, numquam asperiores minus accusantium et tempore repellat voluptatum natus corrupti?';
header
label.menu(for="burger")
input#burger(type="checkbox")
svg.burger(viewBox="0 0 100 100", width="64")
path.line.top(
d="m 30,33 h 40 c 13.100415,0 14.380204,31.80258 6.899646,33.421777 -24.612039,5.327373 9.016154,-52.337577 -12.75751,-30.563913 l -28.284272,28.284272"
)
path.line.middle(
d="m 70,50 c 0,0 -32.213436,0 -40,0 -7.786564,0 -6.428571,-4.640244 -6.428571,-8.571429 0,-5.895471 6.073743,-11.783399 12.286435,-5.570707 6.212692,6.212692 28.284272,28.284272 28.284272,28.284272"
)
path.line.bottom(
d="m 69.575405,67.073826 h -40 c -13.100415,0 -14.380204,-31.80258 -6.899646,-33.421777 24.612039,-5.327373 -9.016154,52.337577 12.75751,30.563913 l 28.284272,-28.284272"
)
nav
ul
each l in nav
li
a(
href='#' + l.name,
title=l.name,
style={ '--an': '--' + l.name, '--at': '--' + l.name + '-s' }
) #{l.name}
main
section(id=nav[0].name, style={ '--name': '--' + nav[0].name + '-s' })
.flying-squares
each square in [1, 2, 3]
.square
.masthead
h1= nav[0].name
p Press on the heart if you are also a CSS Developer 😃.
section(id=nav[1].name, style={ '--name': '--' + nav[1].name + '-s' })
.tile-section
.tile-container
- for(x = 1; x <= 20; x++)
.tile
section(id=nav[2].name, style={ '--name': '--' + nav[2].name + '-s' })
.read
div Reading progress
.text
h2 Smooth appearance of text when scrolling
- for (x = 1; x <= 15; x++)
p= text
section(id=nav[3].name, style={ '--name': '--' + nav[3].name + '-s' })
.two-columns
h2 Picture arrived on the right
.content
.cards
- for (x = 0; x <= 2; x++)
.card
h3.title Card title
.subtitle Subtitle
p= text
.preview
.img
section(id=nav[4].name, style={ '--name': '--' + nav[4].name + '-s' })
.subscribe
h2 Subscribe now
p= text
form(action='' method='POST')
input(type='email' placeholder='Enter your email')
button.btn(type='submit')
span Subscribe
.scroll
span scroll
.divider
span down
footer
a(
href="https://twitter.com/intent/follow?screen_name=andrejsharapov",
target="_blank"
)
span X
:root {
--text-color: hsl(230 16% 28%);
/* header */
--header-bg: hsl(0 0% 100% / 75%);
/* section */
--section: hsl(0 0% 93%);
--section-even: hsl(210deg 15% 92%);
/* tiles */
--red: hsl(10 83% 52%);
--green: hsl(157 91% 43%);
--blue: hsl(210 100% 45%);
--purple: hsl(266 100% 67%);
--yellow: hsl(49 100% 73%);
--black: hsl(0 0% 0%);
/* */
--cubic: cubic-bezier(0.25, 0.1, 0, 2.05);
}
* {
box-sizing: border-box;
}
@media (prefers-reduced-motion: no-preference) {
html {
scroll-behavior: smooth;
}
}
body {
margin: 0;
display: grid;
overflow-x: hidden;
font-family: "Righteous", sans-serif;
/* scope */
timeline-scope: --masthead-s, --tiles-s, --text-s, --two-columns-s,
--subscribe-s;
}
header {
--show: none;
--position: relative;
--b: 0;
--s: 10%;
--nav-bg: var(--yellow);
position: sticky;
top: 0;
z-index: 2;
inline-size: 100%;
transition: all 200ms linear;
/* animation */
animation: height-resize both linear;
animation-timeline: scroll();
animation-range: entry 0% exit 20%;
.menu {
position: fixed;
top: 0.25rem;
left: 0.25rem;
z-index: 2;
cursor: pointer;
& input[type="checkbox"] {
display: none;
}
.burger {
display: var(--show);
background-color: var(--header-bg);
& path {
fill: none;
stroke: currentcolor;
stroke-width: 3;
transition: stroke-dasharray 400ms, stroke-dashoffset 400ms;
&.top {
stroke-dasharray: 40 172;
}
&.middle {
stroke-dasharray: 40 111;
}
&.bottom {
stroke-dasharray: 40 172;
}
}
}
&:has(input[type="checkbox"]:checked) {
.burger {
& path {
&.top {
stroke-dashoffset: -132px;
}
&.middle {
stroke-dashoffset: -71px;
}
&.bottom {
stroke-dashoffset: -132px;
}
}
}
}
}
& nav {
position: var(--position);
inline-size: inherit;
display: flex;
align-items: center;
justify-content: center;
/* blur background */
background-color: var(--header-bg);
backdrop-filter: blur(6px);
& ul {
list-style-type: none;
display: flex;
padding: 0;
grid-column-gap: 3rem;
& li {
position: relative;
padding: 0.5rem 1rem;
text-transform: uppercase;
color: var(--text-color);
transition: transform 0.25s var(--cubic);
&::after {
position: absolute;
content: "";
left: 0;
bottom: var(--b);
z-index: -1;
inline-size: 100%;
block-size: var(--s);
background-color: var(--nav-bg);
transition: all 0.25s var(--cubic);
}
&:has(a:hover) {
--b: 10%;
--s: 70%;
}
}
}
}
}
@media (width <= 48rem) {
body {
&:has(input[id="burger"]:checked) {
scrollbar-gutter: stable;
overflow-y: hidden;
}
}
header {
--position: absolute;
--translateY: -100%;
--show: block;
--nav-bg: var(--green);
& nav {
top: 0;
translate: 0 var(--translateY);
inline-size: 100%;
block-size: 100dvh;
padding-inline: 1rem;
transition: all 200ms ease-in-out;
& ul {
block-size: 100%;
flex-direction: column;
justify-content: space-evenly;
}
}
& .menu {
&:has(input[type="checkbox"]:checked) {
& ~ nav {
--translateY: 0;
}
}
}
}
}
@keyframes height-resize {
to {
padding-block: 0;
}
}
:is(h1, h2) {
margin: 0;
font-size: calc(2rem + 0.25vw);
}
a {
text-decoration: none;
color: currentColor;
/* animation */
animation: avtive-link both linear;
anchor-name: var(--an);
animation-timeline: var(--at);
&:not(:hover) {
opacity: calc(0.5 + var(--active, 0));
}
}
section {
min-block-size: 100vh;
background-color: var(--section);
/* for animation */
view-timeline-name: var(--name);
&:nth-child(even) {
--section: var(--section-even);
}
}
.flying-squares {
position: absolute;
z-index: 1;
.square {
position: inherit;
width: 15vw;
height: 15vw;
rotate: 0.4turn;
background-color: var(--square-color);
top: var(--y);
left: var(--x);
opacity: 0.3;
rotate: var(--rx) var(--ry) var(--rz) 0.55turn;
animation: flying 2s infinite alternate both;
&:nth-of-type(1) {
--y: 17vh;
--x: 8vw;
--rx: 0.5;
--ry: 2.1;
--rz: 1.6;
--square-color: var(--red);
animation-delay: 1s;
}
&:nth-of-type(2) {
--y: 8vh;
--x: 76vw;
--rx: 1.7;
--ry: 2.3;
--rz: 2.1;
--square-color: var(--purple);
}
&:nth-of-type(3) {
--y: 60vh;
--x: 40vw;
--rx: 1.75;
--ry: 3.5;
--rz: 2.7;
--square-color: var(--green);
animation-delay: 0.5s;
}
}
}
@keyframes flying {
to {
translate: 0 -5vh;
}
}
.masthead {
max-inline-size: 100vw;
block-size: 100vh;
overflow: hidden;
display: grid;
place-content: center;
padding-inline: 1rem;
& h1 {
position: fixed;
top: 50%;
left: 50%;
translate: -50% -50%;
text-transform: uppercase;
/* animation */
animation: scale-up both linear, fade-away both linear;
animation-timeline: var(--name);
animation-range: entry-crossing 70% exit 90%, exit 10% exit 70%;
}
}
@keyframes scale-up {
100% {
top: 0;
scale: 5;
}
}
@keyframes fade-away {
100% {
opacity: 0;
}
}
.tile-section {
position: sticky;
top: 0;
max-inline-size: 100vw;
block-size: 200vh;
overflow: hidden;
& .tile-container {
position: absolute;
top: 50%;
left: 50%;
translate: -50% -50%;
scale: 3;
inline-size: 100%;
block-size: 100vh;
display: grid;
grid-template: repeat(4, 1fr) / repeat(5, 1fr);
rotate: 0.12turn;
& .tile {
inline-size: 100%;
block-size: 100%;
background-color: var(--tile);
/* animation */
animation: tile both linear;
/* animation-timeline: scroll(root); */
animation-timeline: var(--name);
animation-range: entry 100% exit 0%;
&:nth-of-type(5n + 2),
&:nth-of-type(5n + 4) {
--tile: var(--green);
--vertical: 100%;
--horizontal: 100%;
&:nth-of-type(odd) {
--tile: var(--red);
--vertical: 100%;
--horizontal: -100%;
}
}
&:nth-of-type(5n + 1),
&:nth-of-type(5n + 3),
&:nth-of-type(5n + 5) {
--tile: var(--blue);
--vertical: -100%;
--horizontal: 100%;
&:not(:nth-of-type(odd)) {
--tile: var(--yellow);
--vertical: -100%;
--horizontal: -100%;
}
}
}
}
}
@keyframes tile {
0% {
translate: 0 0;
}
50% {
translate: 0 var(--vertical);
}
100% {
translate: var(--horizontal) var(--vertical);
}
}
.text {
max-inline-size: 80ch;
margin-inline: auto;
padding: 3rem 1rem;
counter-reset: chapter 0;
& > *:not(h2) {
text-wrap: pretty;
counter-increment: chapter 1;
/* animation */
animation: show-text both linear;
animation-timeline: view(y 80vh auto);
&::before {
content: counter(chapter, upper-roman) ". "; /* lower-alpha */
}
}
}
/* :has(.text) {
counter-reset: chapter 0;
& p {
counter-increment: chapter 1;
}
.read > * {
&::after {
content: ' ' counter(chapter) '%';
}
}
} */
@keyframes show-text {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.read {
position: fixed;
top: 68px;
left: 0;
z-index: 3;
inline-size: 0;
max-inline-size: 100%;
text-align: right;
white-space: nowrap;
padding-block: 0.125rem;
padding-inline-end: 0.5rem;
background-image: linear-gradient(
0.25turn,
var(--red),
var(--yellow),
var(--green),
var(--blue),
var(--purple)
);
opacity: 0;
transition: opacity 200ms linear;
/* animation */
animation: read-text both linear;
animation-timeline: var(--name);
animation-range: entry 100% exit 100%;
& div {
filter: invert(100%);
}
}
@keyframes read-text {
1% {
opacity: 1;
}
99% {
inline-size: 100%;
opacity: 1;
}
100% {
opacity: 0;
}
}
.two-columns {
--columns: 1;
--translateX: 0;
max-inline-size: 80ch;
margin-inline: auto;
block-size: 100%;
padding: 3rem 1rem;
.content {
display: grid;
grid-template-columns: repeat(var(--columns), 1fr);
place-content: center;
gap: 2rem;
.cards {
margin-block-start: 2rem;
display: flex;
flex-direction: column;
justify-content: space-between;
.card {
box-shadow: inset 0 0 0.125rem var(--text-color);
/* animation */
animation: show both linear;
animation-timeline: var(--name);
animation-range: entry-crossing var(--range-start);
&:nth-of-type(1) {
--range-start: 10%;
}
&:nth-of-type(2) {
--range-start: 40%;
}
&:nth-of-type(3) {
--range-start: 70%;
}
&:not(:last-of-type) {
margin-block-end: 2rem;
}
& * {
margin: 0;
padding-inline: 1rem;
}
.title {
padding-block-start: 1rem;
}
.subtitle {
padding-block-start: 0.25rem;
padding-block-end: 1rem;
opacity: 0.5;
}
& p {
padding-block-end: 1rem;
}
}
}
}
.preview {
position: relative;
margin-block: 2rem;
block-size: calc(100% - 1rem);
.img {
left: var(--translateX);
block-size: inherit;
min-block-size: 24rem;
object-fit: cover;
background: var(--red);
}
}
}
@media (width >= 48rem) {
.two-columns {
--columns: 2;
--translateX: 150%;
.preview {
.img {
position: absolute;
top: 0;
aspect-ratio: 0.5;
/* animation */
animation: fade-right both linear;
animation-timeline: scroll(root);
animation-range: entry 5% exit 90%;
}
}
}
}
@keyframes fade-right {
to {
left: 0;
}
}
@keyframes show {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.subscribe {
max-inline-size: 80ch;
margin-inline: auto;
block-size: 100vh;
padding: 3rem 1rem;
display: grid;
place-content: center;
text-align: center;
& form {
position: relative;
margin-block-start: 2rem;
/* animation */
animation: slide-up both linear;
animation-timeline: var(--name);
animation-range: entry-crossing 40%;
& input {
inline-size: 100%;
border: 0;
min-block-size: 3rem;
margin-block-end: 1rem;
padding-inline: 0.5rem;
font-size: calc(1rem + 0.25vw);
box-shadow: 0 0 0.125rem var(--text-color);
&:focus {
outline: thin solid var(--purple);
}
}
& button {
padding: 0.75rem 1rem;
text-transform: uppercase;
cursor: pointer;
background-color: var(--purple);
border: 0;
&:focus {
outline: thin solid var(--purple);
}
& span {
font-weight: 700;
filter: invert(100%);
}
}
}
}
@keyframes slide-up {
from {
scale: 0;
}
to {
scale: 1;
}
}
.scroll {
position: fixed;
top: 50%;
left: 0.35rem;
translate: 0 -50%;
writing-mode: vertical-lr;
rotate: 0.5turn;
display: flex;
align-items: center;
gap: 0.5rem;
opacity: 0.5;
& .divider {
inline-size: 2rem;
block-size: 2px;
background-color: currentColor;
opacity: 0.5;
}
& span {
text-transform: lowercase;
font-weight: bold;
}
}
@keyframes avtive-link {
50% {
--active: 1;
}
}
footer {
display: grid;
place-content: center;
padding-block: 1rem;
& a {
--active: 1;
padding: 0.5rem 1rem;
background-color: var(--black);
& span {
filter: invert(75%);
}
}
}
Also see: Tab Triggers