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.
<header>
<h1>Buttons: A Retrospective</h1>
<p>An overview of the buttons I have designed and/or built for various products from 2009 to present. Try using both the mouse and keyboard to interact with all the buttons, and see how design aesthetics changed over time. Use the OG switch <span aria-hidden="true" style="display:inline-block;margin-block:-1ex;margin-inline:-1ch;transform:scale(0.6);pointer-events:none;"><input type="checkbox" aria-label="Original colors" role="switch" tabindex="-1" checked></span> in each figure to see the buttons in original color scheme. 👉 See more of my work on <a href="https://mikemai.net">my website</a>.</p>
</header>
<main>
<section>
<h2>Early 2020s</h2>
<h3>Bolt Design System</h3>
<figure class="bds">
<input type="checkbox" aria-label="Original Bolt Design System colors" role="switch">
<button type="button" aria-describedby="demo" class="button">
Try Pega
<svg aria-hidden="true" viewBox="0 0 448 512" width="100" title="arrow-right">
<path d="M190.5 66.9l22.2-22.2c9.4-9.4 24.6-9.4 33.9 0L441 239c9.4 9.4 9.4 24.6 0 33.9L246.6 467.3c-9.4 9.4-24.6 9.4-33.9 0l-22.2-22.2c-9.5-9.5-9.3-25 .4-34.3L311.4 296H24c-13.3 0-24-10.7-24-24v-32c0-13.3 10.7-24 24-24h287.4L190.9 101.2c-9.8-9.3-10-24.8-.4-34.3z" />
</svg>
</button>
<button type="button" aria-describedby="demo" class="button secondary">
See Docs
<svg aria-hidden="true" viewBox="0 0 384 512" width="100" title="file-alt">
<path d="M224 136V0H24C10.7 0 0 10.7 0 24v464c0 13.3 10.7 24 24 24h336c13.3 0 24-10.7 24-24V160H248c-13.2 0-24-10.8-24-24zm64 236c0 6.6-5.4 12-12 12H108c-6.6 0-12-5.4-12-12v-8c0-6.6 5.4-12 12-12h168c6.6 0 12 5.4 12 12v8zm0-64c0 6.6-5.4 12-12 12H108c-6.6 0-12-5.4-12-12v-8c0-6.6 5.4-12 12-12h168c6.6 0 12 5.4 12 12v8zm0-72v8c0 6.6-5.4 12-12 12H108c-6.6 0-12-5.4-12-12v-8c0-6.6 5.4-12 12-12h168c6.6 0 12 5.4 12 12zm96-114.1v6.1H256V0h6.1c6.4 0 12.5 2.5 17 7l97.9 98c4.5 4.5 7 10.6 7 16.9z" />
</svg>
</button>
</figure>
</section>
<section>
<h2>Late 2010s</h2>
<h3>Sonicbids</h3>
<figure class="sonicbids">
<input type="checkbox" aria-label="Original Sonicbids colors" role="switch">
<button type="button" aria-describedby="demo" class="button">Sign In</button>
<button type="button" aria-describedby="demo" class="button secondary">Join</button>
</figure>
<h3>Fullbridge</h3>
<figure class="fullbridge">
<input type="checkbox" aria-label="Original Fullbridge colors" role="switch">
<button type="button" aria-describedby="demo" class="button">New Program</button>
<button type="button" aria-describedby="demo" class="button secondary">
<svg aria-hidden="true" viewBox="0 0 352 512" width="100" title="times">
<path d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z" />
</svg>
Delete
</button>
</figure>
</section>
<section>
<h2>Mid 2010s</h2>
<h3>Bluetrain Mobile</h3>
<figure class="btm">
<input type="checkbox" aria-label="Original Bluetrain Mobile colors" role="switch">
<button type="button" aria-describedby="demo" class="button" aria-label="Request a demo">Request a demo</button>
</figure>
<h3>Campus.com</h3>
<figure class="campus">
<input type="checkbox" aria-label="Original Campus.com colors" role="switch">
<button type="button" aria-describedby="demo" class="button">
Start My Future
<svg aria-hidden="true" viewBox="0 0 512 512" width="100" title="arrow-circle-right">
<path d="M256 8c137 0 248 111 248 248S393 504 256 504 8 393 8 256 119 8 256 8zm-28.9 143.6l75.5 72.4H120c-13.3 0-24 10.7-24 24v16c0 13.3 10.7 24 24 24h182.6l-75.5 72.4c-9.7 9.3-9.9 24.8-.4 34.3l11 10.9c9.4 9.4 24.6 9.4 33.9 0L404.3 273c9.4-9.4 9.4-24.6 0-33.9L271.6 106.3c-9.4-9.4-24.6-9.4-33.9 0l-11 10.9c-9.5 9.6-9.3 25.1.4 34.4z" />
</svg>
</button>
</figure>
<h3>Art Technology Group</h3>
<figure class="atg">
<input type="checkbox" aria-label="Original Art Technology Group colors" role="switch">
<button type="button" aria-describedby="demo" class="button">New Case</button>
<button type="button" aria-describedby="demo" class="button secondary">Close Case</button>
</figure>
<h3>Acadian Asset Management</h3>
<figure class="acadian">
<input type="checkbox" aria-label="Original Acadian Asset Management colors" role="switch">
<button type="button" aria-describedby="demo" class="button">
Fund Information
<svg aria-hidden="true" viewBox="0 0 320 512" width="100" title="caret-down">
<path d="M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z" />
</svg>
</button>
</figure>
</section>
<section>
<h2>Early 2010s</h2>
<h3>Beth Israel Deaconess Medical Center</h3>
<figure class="bidmc">
<input type="checkbox" aria-label="Original Beth Israel Deaconess Medical Center colors" role="switch">
<button type="button" aria-describedby="demo" class="button">Request an appointment</button>
</figure>
<h3>Dental Partners of Boston</h3>
<figure class="dpb">
<input type="checkbox" aria-label="Original Dental Partners of Boston colors" role="switch">
<button type="button" aria-describedby="demo" class="button">
Contact Us
<svg aria-hidden="true" viewBox="0 0 448 512" width="100" title="phone-square-alt">
<path d="M400 32H48A48 48 0 0 0 0 80v352a48 48 0 0 0 48 48h352a48 48 0 0 0 48-48V80a48 48 0 0 0-48-48zm-16.39 307.37l-15 65A15 15 0 0 1 354 416C194 416 64 286.29 64 126a15.7 15.7 0 0 1 11.63-14.61l65-15A18.23 18.23 0 0 1 144 96a16.27 16.27 0 0 1 13.79 9.09l30 70A17.9 17.9 0 0 1 189 181a17 17 0 0 1-5.5 11.61l-37.89 31a231.91 231.91 0 0 0 110.78 110.78l31-37.89A17 17 0 0 1 299 291a17.85 17.85 0 0 1 5.91 1.21l70 30A16.25 16.25 0 0 1 384 336a17.41 17.41 0 0 1-.39 3.37z" />
</svg>
</button>
</figure>
</section>
<span id="demo" hidden>Non-functional, for demonstrational purpose only.</span>
</main>
button {
border: 0;
cursor: pointer;
}
.button {
--button-text: var(--color-text-on-primary);
--button-bg: var(--color-primary);
--button-shadow: var(--color-primary-dark);
--button-hover-bg: var(--color-primary-light);
--button-hover-shadow: var(--color-primary);
--button-active-bg: var(--color-primary-dark);
display: inline-flex;
align-items: center;
gap: 0.4em;
vertical-align: middle;
font-family: var(--font);
font-size: 0.9rem;
color: var(--button-text);
line-height: 1;
text-decoration: none;
background-color: var(--button-bg);
&.secondary {
--button-text: var(--color-text-on-secondary);
--button-bg: var(--color-secondary);
--button-shadow: var(--color-secondary-dark);
--button-hover-bg: var(--color-secondary-light);
--button-hover-shadow: var(--color-secondary);
--button-active-bg: var(--color-secondary-dark);
}
}
.bds {
> input:checked ~ .button {
--color-primary: #3e67bb;
--color-primary-light: #{lighten(#3e67bb, 15%)};
--color-primary-dark: #{darken(#3e67bb, 15%)};
--color-text-on-primary: white;
--color-secondary: #ffc836;
--color-secondary-light: #{lighten(#ffc836, 15%)};
--color-secondary-dark: #{darken(#ffc836, 15%)};
--color-text-on-secondary: black;
--color-tertiary-light: white;
}
.button {
position: relative;
transform: translatey(0);
padding-block: 1em;
padding-inline: 1.5em;
font-weight: 600;
border-radius: 0.3em;
transition: transform 150ms ease-out;
&:before,
&:after {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
border-radius: inherit;
transition: opacity 150ms ease-out;
}
&:before {
opacity: 0.4;
background: linear-gradient(to bottom, rgba(black, 0), rgba(black, 0.3));
box-shadow: 0 0.2em 0.75em gray;
}
&:after {
opacity: 0;
box-shadow: 0 0.4em 1.5em var(--button-hover-shadow);
}
&:hover {
transform: translatey(-2px);
&:after {
opacity: 0.4;
}
}
&:active {
background-color: var(--button-active-bg);
transform: translatey(2px);
}
&:focus {
outline: 0.2em solid var(--color-tertiary-light);
outline-offset: 0.1em;
}
}
}
.sonicbids {
> input:checked ~ .button {
--color-primary: rgb(218, 101, 41);
--color-primary-light: #{lighten(rgb(218, 101, 41), 6%)};
--color-primary-dark: #{darken(rgb(218, 101, 41), 10%)};
--color-text-on-primary: white;
--color-secondary: #0c88b1;
--color-secondary-light: #{lighten(#0c88b1, 6%)};
--color-secondary-dark: #{darken(#0c88b1, 6%)};
--color-text-on-secondary: white;
}
.button {
position: relative;
z-index: 1;
padding-block: 0.75rem;
padding-inline: 1.25rem;
font-size: 1.25rem;
font-weight: 500;
letter-spacing: 0.01em;
border-radius: 5px;
transition: transform 80ms ease-in, background-color 80ms ease-in;
&:before {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
opacity: 1;
transform: translate(0);
transform-origin: bottom;
border-radius: inherit;
box-shadow: 0 0.25em 0 var(--button-shadow);
transition: transform 80ms ease-in;
}
&:hover {
background-color: var(--button-hover-bg);
}
&:active {
background-color: var(--button-active-bg);
transform: translatey(0.25em);
&:before {
transform: translatey(-0.25em);
}
}
&:focus {
z-index: 2;
outline: 0.1em dotted currentcolor;
outline-offset: -0.2em;
}
}
}
.fullbridge {
> input:checked ~ .button {
--color-primary: #101010;
--color-primary-light: #{lighten(#101010, 6%)};
--color-primary-dark: #{darken(#101010, 10%)};
--color-text-on-primary: white;
--color-secondary: darkred;
--color-secondary-light: #{lighten(darkred, 6%)};
--color-secondary-dark: #{darken(darkred, 6%)};
--color-tertiary-light: #13a8e1;
}
.button {
position: relative;
z-index: 1;
padding-block: 0.9em;
padding-inline: 1em;
font-size: 1.2rem;
font-weight: 400;
border-radius: 1px;
box-shadow: 0 0 0.5em rgba(gray, 0.2);
transition: background-color 250ms ease-in-out;
&:before {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
transform: scalex(0);
transform-origin: right;
background-color: rgba(white, 0.2);
transition: transform 250ms ease-in-out;
}
&:hover {
&:before {
transform: scalex(1);
transform-origin: left;
}
}
&:active {
background-color: var(--button-active-bg);
transform: translatey(1px);
&:before {
transform: translatey(-1px);
}
}
&:focus {
outline: 0.2em solid var(--color-tertiary-light);
outline-offset: 0.1em;
}
}
}
.btm {
--color-primary: #aa076b;
--color-primary-light: #{lighten(#aa076b, 5%)};
--color-primary-dark: #{darken(#aa076b, 10%)};
--color-text-on-primary: white;
> input:checked ~ .button {
--color-primary: #82ac00;
--color-primary-light: #{lighten(#82ac00, 15%)};
--color-primary-dark: #{darken(#82ac00, 15%)};
--color-text-on-primary: white;
--color-tertiary-light: #009cbe;
}
.button {
position: relative;
z-index: 1;
padding-block: 1.25rem;
padding-inline: 1.5rem;
font-weight: 700;
font-size: 1.2rem;
letter-spacing: 0.02em;
text-transform: uppercase;
text-shadow: 1px -1px 1px rgba(black, 0.4);
white-space: nowrap;
border-radius: 0.5em;
box-shadow: 0 0 0 1px var(--color-primary-dark),
inset 0 0 0 1px rgba(white, 0.4);
&:before,
&:after {
content: "";
position: absolute;
right: 1px;
left: 1px;
block-size: calc(50% - 1px);
z-index: -1;
transition: transform 150ms ease-out, opacity 150ms ease-out;
}
&:before {
top: 1px;
border-top-left-radius: inherit;
border-top-right-radius: inherit;
background-image: linear-gradient(
to bottom,
rgba(black, 0),
rgba(black, 0.1)
);
transform-origin: top;
}
&:after {
bottom: 1px;
border-bottom-left-radius: inherit;
border-bottom-right-radius: inherit;
background-image: linear-gradient(
to bottom,
rgba(black, 0.2),
rgba(black, 0.45)
);
transform-origin: bottom;
}
&:hover {
&:before,
&:after {
transform: scaley(0);
opacity: 0;
}
}
&:active {
background-image: linear-gradient(
to bottom,
rgba(black, 0.2),
rgba(black, 0.2)
);
&:before,
&:after {
transform: scaley(0);
opacity: 0;
}
}
&:focus {
outline: 0.2em solid var(--color-tertiary-light);
outline-offset: 0.1em;
}
}
}
.campus {
--color-primary: #{darken(#aa076b, 5%)};
--color-primary-light: #{lighten(#aa076b, 3%)};
--color-primary-dark: #{darken(#aa076b, 10%)};
--color-text-on-primary: white;
> input:checked ~ .button {
--color-primary: darkblue;
--color-primary-light: #{lighten(darkblue, 15%)};
--color-primary-dark: #{darken(darkblue, 15%)};
--color-text-on-primary: white;
--color-tertiary-light: blue;
}
.button {
position: relative;
z-index: 1;
overflow: hidden;
padding-block: 1rem;
padding-inline: 1.5rem;
font-weight: 900;
font-size: 1.2rem;
white-space: nowrap;
text-shadow: -1px -1px 1px rgba(black, 0.4);
border-radius: 100em;
background-image: linear-gradient(
to bottom,
rgba(white, 0.3) 0%,
rgba(white, 0.2) 48%,
rgba(white, 0) 52%,
rgba(white, 0)
);
box-shadow: 0 0 0 2px var(--color-primary-light);
transition: background-color 250ms ease-out;
&:hover {
background-color: var(--color-primary-light);
}
&:active {
background: var(--color-primary-dark);
}
&:focus {
outline: 0.2em solid var(--color-tertiary-light);
outline-offset: 0.2em;
}
}
}
.atg {
--color-secondary: #{lighten(#aa076b, 50%)};
--color-secondary-light: #{lighten(#aa076b, 55%)};
--color-secondary-dark: #{lighten(#aa076b, 20%)};
--color-text-on-secondary: black;
> input:checked ~ .button {
--color-primary: lightblue;
--color-primary-light: #{lighten(lightblue, 6%)};
--color-primary-dark: #{darken(lightblue, 25%)};
--color-text-on-primary: black;
--color-secondary: #f4f4f4;
--color-secondary-light: #{lighten(#f4f4f4, 6%)};
--color-secondary-dark: #{darken(#f4f4f4, 35%)};
--color-text-on-secondary: black;
--color-tertiary: lightblue;
}
.button {
position: relative;
z-index: 1;
padding-block: 0.5em;
padding-inline: 1em;
font-weight: 600;
text-shadow: 1px 1px 1px rgba(white, 0.4);
border-radius: 5px;
background-image: linear-gradient(
to bottom,
rgba(white, 0.6) 0%,
rgba(white, 0.7) 40%,
rgba(white, 0.05) 60%,
rgba(white, 0.05)
);
box-shadow: 0 0 0 0.1em rgba(gray, 0.25), inset 0 0 0.1em rgba(white, 0.8);
transition: color 150ms ease-in;
&.secondary {
background-image: linear-gradient(
to bottom,
rgba(black, 0) 0%,
rgba(black, 0.05) 40%,
rgba(black, 0.25) 60%,
rgba(black, 0.25)
);
}
&:before {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
opacity: 0.9;
transform: scaley(0);
transform-origin: top;
border-radius: inherit;
background: var(--color-tertiary-light);
transition: transform 150ms ease-in;
}
&:hover,
&:focus {
&:before {
transform: scaley(1);
transform-origin: bottom;
}
}
&:active {
background-image: unset;
background-color: var(--button-active-bg);
&:before {
opacity: 0;
}
}
&:focus {
outline: 0.2em solid var(--color-tertiary-light);
outline-offset: 0.1em;
}
}
}
.acadian {
--color-primary: #{darken(#aa076b, 5%)};
--color-primary-light: #{lighten(#aa076b, 3%)};
--color-primary-dark: #{darken(#aa076b, 10%)};
--color-text-on-primary: white;
> input:checked ~ .button {
--color-primary: #003453;
--color-primary-light: #{lighten(#003453, 15%)};
--color-primary-dark: #{darken(#003453, 15%)};
--color-tertiary-light: #2d608b;
}
.button {
position: relative;
z-index: 1;
padding-block: 0.75em;
padding-inline: 1em;
font-weight: 700;
text-shadow: 1px -1px 1px rgba(black, 0.1);
border: 1px solid var(--color-primary-light);
transition: color 150ms ease-in, text-shadow 150ms ease-in;
&:before {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
opacity: 1;
background-image: linear-gradient(
to bottom,
rgba(black, 0) 0%,
rgba(black, 0) 50%,
rgba(black, 0.4) 51%,
rgba(black, 0.4)
);
transition: opacity 150ms ease-in;
}
&:hover,
&:active {
text-shadow: 1px -1px 1px rgba(black, 0.4);
&:before {
opacity: 0;
}
}
&:active {
background-color: var(--button-active-bg);
transform: translatey(2px);
}
&:focus {
outline: 0.2em solid var(--color-tertiary-light);
outline-offset: 0.1em;
}
}
}
.bidmc {
--color-primary: #{darken(#aa076b, 5%)};
--color-primary-light: #{lighten(#aa076b, 5%)};
--color-primary-dark: #{darken(#aa076b, 15%)};
--color-text-on-primary: white;
> input:checked ~ .button {
--color-primary: #283891;
--color-primary-light: #{lighten(#283891, 5%)};
--color-primary-dark: #{darken(#283891, 5%)};
--color-tertiary-light: #1c9bd7;
}
.button {
position: relative;
z-index: 1;
padding-block: 0.65rem;
padding-inline: 1rem;
font-weight: 900;
text-shadow: 0 0 2px darkgreen;
border: 1px solid darken(darkslategray, 1%);
border-radius: 3px;
background-image: linear-gradient(
to bottom,
rgba(white, 0.1),
rgba(white, 0)
);
&:before,
&:after {
content: "";
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: -1;
border-radius: inherit;
}
&:before {
opacity: 0;
background-image: linear-gradient(
to bottom,
rgba(white, 0.2),
rgba(white, 0.1)
);
transition: opacity 150ms ease-in;
}
&:after {
opacity: 0;
box-shadow: 0 0 0 0.3em var(--color-primary-light);
transition: opacity 150ms ease-in;
}
&:hover {
&:before {
opacity: 1;
}
&:after {
opacity: 0.3;
}
}
&:active {
background-image: unset;
border: 1px solid var(--color-primary-dark);
background-color: var(--button-active-bg);
&:before,
&:after {
display: none;
}
}
&:active,
&:focus {
&:after {
display: none;
}
}
&:focus {
outline: 0.2em solid var(--color-tertiary-light);
outline-offset: 0.1em;
}
}
}
.dpb {
> input:checked ~ .button {
--color-primary: crimson;
--color-primary-light: #{lighten(crimson, 10%)};
--color-primary-dark: #{darken(crimson, 10%)};
--color-text-on-primary: white;
}
.button {
padding-block: 0.5rem;
padding-inline: 0.75rem;
font-weight: 700;
border-radius: 1px;
box-shadow: 0 0 0 1px rgba(black, 0.2);
transition: background-color 150ms ease-in;
&:hover {
background-color: var(--button-hover-bg);
}
&:active {
background-color: var(--button-active-bg);
}
&:focus {
outline: 0.2em solid var(--color-primary-light);
outline-offset: 0.2em;
}
}
}
/* ------------------------------------ *\
Demo code
\* ------------------------------------ */
:root {
--font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", sans-serif;
--color-text: #f4f4f4;
--color-bg: black;
--color-primary: #ffc50b;
--color-primary-light: #{lighten(#ffc50b, 10%)};
--color-primary-dark: #{darken(#ffc50b, 12%)};
--color-text-on-primary: black;
--color-secondary: #aa076b;
--color-secondary-light: #{lighten(#aa076b, 3%)};
--color-secondary-dark: #{darken(#aa076b, 5%)};
--color-text-on-secondary: white;
--color-tertiary: #0c799a;
--color-tertiary-light: #{lighten(#0c799a, 20%)};
--color-tertiary-dark: #{darken(#0c799a, 10%)};
--color-text-on-tertiary: white;
color: var(--color-text);
background-color: var(--color-bg);
color-scheme: dark; // Dark mode forever and ever.
}
*,
*:before,
*:after {
margin: 0;
padding: 0;
font-feature-settings: "kern";
font-kerning: normal;
-moz-osx-font-smoothing: grayscale !important;
-webkit-font-smoothing: antialiased !important;
box-sizing: border-box;
}
html {
overflow-x: hidden;
font-family: var(--font);
font-size: clamp(110%, calc(100% + 0.5vw), 200%);
line-height: 1.5;
}
body {
padding-block: 10vmin 20vmin;
padding-inline: calc((100vw - min(80vw, 66ch)) / 2);
background: linear-gradient(
217deg,
rgba(magenta, 0.1),
rgba(magenta, 0) 70.71%
),
linear-gradient(127deg, rgba(cyan, 0.1), rgba(cyan, 0) 70.71%),
linear-gradient(336deg, rgba(yellow, 0.1), rgba(yellow, 0) 70.71%);
}
main {
--color-main-timeline-year: var(--color-tertiary-light);
--color-main-timeline-border: var(--color-secondary-dark);
--color-main-timeline-diamond: var(--color-primary);
border-inline-start: 1px solid var(--color-main-timeline-border);
animation: fadein 2s cubic-bezier(0.25, 0, 0.3, 1) normal;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin-block: 0 0.25em;
margin-inline: 0;
font-weight: 900;
line-height: 1.2;
}
p {
margin-block: 0 2.4ex;
margin-inline: 0;
}
a,
input {
&:focus {
position: relative;
outline: 0.2em solid var(--color-tertiary-light);
outline-offset: 0.2em;
}
}
a {
color: var(--color-primary-light);
text-underline-offset: 0.1em;
&:hover {
color: var(--color-primary);
text-decoration: none;
}
}
figure {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 0.5rem;
position: relative;
opacity: 0;
transform: translate3d(15%, 0, 0);
margin-block: 0 3.4ex;
margin-inline: 1.4rem 0;
padding-block: 30vmin;
padding-inline: 5vmin;
pointer-events: none;
border-radius: 1rem;
background: rgba(gray, 0.15);
box-shadow: 0 0 1rem rgba(gray, 0.1);
transition: all 500ms cubic-bezier(0.25, 0, 0.3, 1);
&.show {
transform: translate3d(0, 0, 0);
opacity: 1;
pointer-events: auto;
}
@media (prefers-reduced-motion: reduce) {
transform: translate3d(0, 0, 0);
}
> input[role="switch"] {
position: absolute;
top: 1rem;
right: 1rem;
}
}
input[role="switch"] {
--switch-spacing: 0.5ch;
display: inline-flex;
align-items: center;
justify-content: flex-end;
inline-size: 8ch;
block-size: 4ch;
opacity: 0.7;
cursor: pointer;
appearance: none;
border-radius: 100em;
box-shadow: 0 0 0.2em gray;
&:before,
&:after {
transition: all 250ms ease-out;
@media (prefers-reduced-motion: reduce) {
transition-duration: 0.01ms;
}
}
&:before {
content: "OG";
padding-inline: 1ch;
}
&:after {
content: "✖️";
display: grid;
place-items: center;
position: absolute;
top: 50%;
bottom: 0;
left: var(--switch-spacing);
transform: translate3d(0, -50%, 0) rotate(0deg);
inline-size: 3ch;
block-size: 3ch;
color: var(--color-bg);
border-radius: inherit;
background-color: var(--color-text);
box-shadow: 0 0 0.2em gray;
}
&:checked {
justify-content: flex-start;
opacity: 1;
background-color: #acd373;
&:before {
color: var(--color-bg);
}
&:after {
content: "✔️";
transform: translate3d(calc(100% + var(--switch-spacing) * 2), -50%, 0)
rotate(360deg);
}
}
}
svg {
inline-size: 1em;
block-size: 1em;
fill: currentcolor;
}
h2 {
margin-block-end: 1rem;
margin-inline-start: -0.25rem;
padding-inline-start: 1.25rem;
font-size: 0.8rem;
font-weight: 400;
color: var(--color-main-timeline-year);
border-inline-start: 0.4rem solid;
}
h3 {
display: inline-block;
position: relative;
padding-block: 0.4rem;
padding-inline: 1.4rem 0.8rem;
border-block-start: 1px solid var(--color-main-timeline-border);
&:after {
content: "";
position: absolute;
top: 0;
right: 0;
transform: translatey(-50%) rotate(45deg);
inline-size: 0.4rem;
block-size: 0.4rem;
border: 1px solid var(--color-main-timeline-border);
background-color: var(--color-main-timeline-diamond);
}
}
h1,
h2,
h3,
h4,
h5,
h6,
p {
animation: slidein 1s cubic-bezier(0.5, -0.5, 0.1, 1.5) normal;
@media (prefers-reduced-motion: reduce) {
animation: fadein 1s cubic-bezier(0.5, -0.5, 0.1, 1.5) normal;
}
}
@keyframes slidein {
from {
opacity: 0;
transform: translateY(50%);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes fadein {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
const figures = document.querySelectorAll("figure");
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
entry.target.classList.toggle("show", entry.isIntersecting);
});
},
{
threshold: 0.5
}
);
const lastCardObserver = new IntersectionObserver((entries) => {
const lastCard = entries[0];
if (!lastCard.isIntersecting) return;
lastCardObserver.observe(document.querySelector("figure:last-child"));
});
lastCardObserver.observe(document.querySelector("figure:last-child"));
figures.forEach((figure) => {
observer.observe(figure);
});
const scrollContainer = document.querySelector("main");
Also see: Tab Triggers