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="container" data-wrap>
</div>
<menu aria-label="controls">
<li>
<button data-toggleslant aria-label="toggle slant"></button>
</li>
<li>
<button data-togglelight aria-label="toggle lightmode"></button>
</li>
</menu>
<!-- logo for <use /> in cards -->
<div class="logo">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<symbol id="logo" viewBox="0 0 180 180">
<defs><path id="crest-feather" d="M70 70H20a30 30 0 0 0 30 30h20a10 10 0 0 1 9.22 6.13A40 40 0 0 1 110 110a40 40 0 0 0-40-40z"></path></defs>
<path fill="#19F" d="M70 140a40 40 0 0 1 80 0z" class="top-beak"></path> <use xlink:href="#crest-feather" fill="#ED0" class="crest crest__gold"></use> <use xlink:href="#crest-feather" fill="#6C6" transform="rotate(30 110 110)" class="crest crest__green"></use> <use xlink:href="#crest-feather" fill="#19F" transform="rotate(60 110 110)" class="crest crest__blue"></use> <use xlink:href="#crest-feather" fill="#F69" transform="rotate(90 110 110)" class="crest crest__pink"></use> <path fill="#F69" d="M30 170h80v-60a39.8 39.8 0 0 0-5.25-19.81A80 80 0 0 0 30 170z" class="head"></path> <circle fill="#FFF" cx="87.5" cy="127.25" r="7.5" class="eye"></circle> <path fill="#ED0" d="M120 140a10 10 0 0 1-10-10v40a30 30 0 0 0 30-30z" class="top-beak"></path>
</svg>
</symbol>
</defs>
</div>
:root {
--bgc: #202124;
--fgc: #fff;
--t: 20s;
--r: 12deg;
font-family: Inter, sans-serif;
background: var(--bgc);
color: var(--fgc);
}
.light {
--fgc: #000;
--bgc: #fff;
}
.slantback {
--r: -12deg;
}
/*
svg {
overflow: visible;
}
svg path {
stroke: var(--bgc);
stroke-width: 8px;
}*/
.container {
position: absolute;
top: 50%;
left: 50%;
width: 100%;
height: 80vmin;
background: var(--bgc);
transform: translate(-50%, -50%);
overflow: hidden;
&::after,
&::before {
content: '';
position: absolute;
transition: transform 500ms cubic-bezier(.3,.7,0,1);
}
&::after {
z-index: 2;
top: -20vmin;
right: -10%;
bottom: -20vmin;
width: 60%;
background: var(--bgc);
box-shadow: 0 0 5rem var(--bgc);
transform: rotate(var(--r));
transform-origin: 0 50%;
}
&::before {
z-index: 5;
top: 50%;
height: 75vmin;
left: 50%;
width: 3px;
background: var(--fgc);
border-radius: 2px;
transform: translate(-50%, -50%) rotate(var(--r));
}
}
.color {
text-decoration: none;
z-index: 1;
width: 30vmin;
--bg: var(--fgc);
background: var(--bg);
color: var(--bgc);
display: flex;
flex-direction: column;
padding: 0.5vmin 1vmin 1.25vmin;
//border-radius: 4px;
border: 1px solid var(--fgc);
perspective: 600px;
// animation
position: absolute;
top: 50%;
right: 0;
transform: translateY(-50%) translateX(100%);
animation: var(--t) gotToLeft cubic-bezier(0, 1, 0.6, 1);
animation-fill-mode: forwards;
animation-count: 1;
// glow
&::before {
opacity: .5;
position: absolute;
content: '';
inset: 0;
//background: var(--color);
box-shadow: 0 0 3rem var(--color);
//filter: blur(3rem);
animation: var(--t) fadeOut cubic-bezier(0, 1, 0.6, 1);
}
&::after {
content: '';
position: absolute;
inset: 0;
background: var(--color);
background: var(--bgc);
transform: scale(1);
animation: var(--t) fade cubic-bezier(0, 1, 0.6, 1);
}
}
@keyframes fadeOut {
0%, 17% {
opacity: .5;
}
20%, 100% {
opacity: 0;
transform: scale(1);
}
}
.color--top {
// top clone of the card
// (for the right part of the animation)
background: transparent;
color: transparent;
z-index: 4;
border-color: transparent;
--bg: transparent;
box-shadow: none;
pointer-events: none;
&::before {
display: none;
}
&::after {
display: none;
}
}
@keyframes fade {
0%, 17% {
opacity: 0;
}
33%, 100% {
opacity: 1;
transform: scale(1.05);
}
}
@keyframes gotToLeft {
90%, 100% {
right: 100%;
transform: translateY(-50%) translateX(-3rem) scale(.75);
//transform: translateY(-50%) translateX(50%) translateZ(50vmin) rotateY(-100deg);
}
}
.color__bottom,
.color__top {
background: var(--bg);
padding: 0.3em;
}
.color__bottom {
padding-bottom: 0.2em;
}
.color__top {
order: 1;
display: flex;
justify-content: space-between;
}
.color__brand {
font-weight: 300;
font-size: 2.1vmin;
}
.color__logo {
height: 2.2vmin;
width: 2.2vmin;
transform: scale(1.1) translateY(-10%);
}
.color--top .color__logo {
opacity: 0;
}
.color__bottom {
order: 3;
}
.color__swatch {
order: 2;
aspect-ratio: 1;
background: var(--color);
//animation: var(--t) top cubic-bezier(0, 1, 0.6, 1);
}
@keyframes top {
0%, 5% {
transform: scale(1.2);
}
15%, 100% {
transform: scale(1);
}
}
.color--top .color__swatch {
animation: var(--t) op cubic-bezier(0, 1, 0.6, 1);
//box-shadow: 0 0 3em var(--color);
}
@keyframes op {
/*0% {
transform: translateX(15%) scaleY(2) scaleX(1.5) rotateY(-55deg);
}
5% {
transform: translateX(15%) scaleY(1.05) scaleX(1.2) rotateY(-45deg);
}*/
0% {
transform: translateX(50%) translateZ(50vmin) rotateY(-100deg);
}
11% {
opacity: 1;
transform: scale(0.955);
}
13%, 100% {
opacity: 0;
transform: scale(1);
}
}
.color__name,
.color__value {
display: block;
height: 1.2em;
line-height: 1.2;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
animation: var(--t) swipe cubic-bezier(0, 1, 0.6, 1);
}
@keyframes swipe {
0%, 5% {
opacity: 0;
transform: scale(1.1) translateX(25%);
}
12.5%, 100% {
opacity: 1;
transform: scale(1);
}
}
.color__value {
font-weight: 700;
font-size: 3.5vmin;
animation-delay: 75ms;
}
.color__name {
margin-top: -0.2em;
font-size: 2.1vmin;
font-weight: 300;
}
.slantback {
.color__value {
animation-delay: 0ms;
}
.color__name {
animation-delay: 75ms;
}
}
.logo {
display: none;
}
menu {
display: flex;
position: absolute;
bottom: 0;
right: 0;
}
button {
padding: 2.5vmin;
font-size: 3vmin;
line-height: 1;
background: transparent;
border: none;
color: var(--fgc);
&::after {
content: '☼';
}
&[aria-pressed]::after {
content: '🌑'
}
&[data-toggleslant] {
margin-right: -2vmin;
&::after {
content: "\\";
}
&[aria-pressed]::after {
content: '/'
}
}
}
menu, li {
list-style: none;
}
let allTheColors = [];
let animationDuration = 1400; //ms
const createCard = (
color = '#0022ff',
name = 'Toxic Blue'
) => {
const $wrap = document.createElement('a');
$wrap.setAttribute('href', `https://parrot.color.pizza/color/${color.substring(1)}/%E2%9D%A4`);
$wrap.setAttribute('target', '_blank');
const $head = document.createElement('header');
const $color = document.createElement('div');
const $upperPart = document.createElement('div');
const $colorName = document.createElement('h2');
const $colorValue = document.createElement('var');
$colorName.classList.add('color__name');
$colorValue.classList.add('color__value');
$colorValue.textContent = color;
$colorName.textContent = name;
const logo = `<strong class="color__brand">Color Parrot</strong><svg class="color__logo" viewBox="0 0 180 180"><use href="#logo" /></svg>`;
// too lazy to google the namespaced createElement :(
$upperPart.innerHTML = logo;
$wrap.classList.add('color');
$head.classList.add('color__bottom');
$upperPart.classList.add('color__top');
$color.classList.add('color__swatch');
$head.appendChild($colorValue);
$head.appendChild($colorName);
[$head, $color, $upperPart].forEach($el => $wrap.appendChild($el));
$wrap.style.setProperty('--color', color);
return $wrap;
}
const $wrap = document.querySelector('[data-wrap]');
const addRandomCard = colorList => {
const l = colorList.length;
const index = Math.floor(Math.random() * colorList.length);
const {name, hex} = colorList[index];
const $card = createCard(hex, name);
const $cardTop = $card.cloneNode(true);
$cardTop.classList.add('color--top');
$wrap.appendChild(
$card
);
$wrap.appendChild(
$cardTop
);
setTimeout(() => {
$card.remove();
$cardTop.remove();
}, 20100);
}
fetch('https://api.color.pizza/v1/?goodnamesonly=true')
.then(d => d.json())
.then(data => {
allTheColors = data;
setInterval(() =>
addRandomCard(data.colors),
animationDuration
);
});
const $btn = document.querySelector('[data-togglelight]');
$btn.addEventListener('click', () => {
document.documentElement.classList.toggle('light');
$btn.toggleAttribute('aria-pressed');
});
const $btnSlnt = document.querySelector('[data-toggleslant]');
$btnSlnt.addEventListener('click', () => {
document.documentElement.classList.toggle('slantback');
$btnSlnt.toggleAttribute('aria-pressed');
});
Also see: Tab Triggers