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="content">
<div class="wrapper">
<p>
<strong>
altBud is a little character who feels sad when they see images without alt tags! They respect your motion preferences too.
</strong>
</p>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Excepturi
aspernatur quis nam consequuntur iste doloremque blanditiis, ad quos
repellendus dolores, quae ab perspiciatis, totam non pariatur nobis illo
aperiam cumque. Perferendis nisi explicabo voluptate maxime, tempora
aliquam hic est minima. Cum sapiente fuga similique cupiditate veniam,
vel porro eaque voluptatibus corporis neque deserunt ex id explicabo
dolores in, corrupti repellendus dicta ut nulla beatae rerum perferendis
quo. Sunt, voluptas voluptatem!
</p>
<img src="https://images.unsplash.com/photo-1546238232-20216dec9f72?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=2807&q=80" alt="A group of happy puppies" />
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi modi
sit maxime ducimus eum, laudantium voluptate nobis sed itaque corporis
fugiat ullam ipsa. Animi, quidem!
</p>
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Impedit
doloribus repellendus ipsa facilis velit temporibus. Reiciendis
voluptatum laboriosam aliquid possimus nihil eum molestias voluptatibus
sed ad porro dolor fuga excepturi, perferendis fugiat odio alias ab
explicabo nulla provident ratione corrupti voluptas! Quidem, consectetur
officiis necessitatibus reiciendis nesciunt saepe animi modi maiores
voluptates id perspiciatis at ipsum facere impedit voluptatem enim porro
excepturi atque sint rem eos blanditiis cumque quas quisquam. Quae eos
repellat at beatae esse porro qui molestias repellendus.
</p>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Velit,
adipisci alias autem id saepe amet excepturi, laborum perferendis, cum
suscipit ipsa pariatur maxime optio? Non a quas iure magni
reprehenderit. Architecto earum eius veritatis praesentium, facilis
iste! Eos repudiandae ipsam et, quas quibusdam nemo repellendus hic
delectus quisquam vel, sed corrupti necessitatibus accusantium adipisci
ad? Maiores nobis corporis ipsum. Repudiandae dolorem voluptate expedita
ipsum deserunt eveniet suscipit, odit eligendi exercitationem quod
itaque molestias ullam illum nobis, molestiae enim at hic.
</p>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nesciunt
repellendus tenetur numquam possimus unde neque praesentium aliquam.
Vero aspernatur nobis recusandae illo et quis totam vitae, accusantium
rerum a molestiae aliquid laboriosam debitis corporis neque in voluptas
necessitatibus doloribus? Laborum officiis sapiente quos quis libero
modi nostrum. Sunt officiis atque culpa neque reiciendis omnis
accusantium cumque ea voluptate! Aspernatur officia deserunt pariatur
nesciunt dignissimos id! Ducimus, pariatur provident magnam et amet
alias quia mollitia a earum id explicabo consectetur ut sapiente ipsam
dolor magni cupiditate quae architecto aliquam dignissimos. Aspernatur.
</p>
<img src="https://images.unsplash.com/photo-1531928351158-2f736078e0a1?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80" alt="" />
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Perspiciatis
unde temporibus iste. Voluptatem doloremque ipsum a beatae, dolorem est
saepe nesciunt ratione velit nostrum? Earum excepturi illum natus autem
temporibus ab maiores! Architecto ducimus dolore modi suscipit eveniet
facilis quia aperiam neque?
</p>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eius, vel
soluta officia, possimus at repudiandae atque quidem maiores quae
tempora voluptatem! Cum, tempore ex. Perspiciatis harum blanditiis
adipisci atque dignissimos in facilis saepe, nam alias aperiam!
Similique ut ratione ducimus possimus voluptatum provident quos at error
culpa! Cum corrupti, accusamus, odit quasi odio ipsum quidem, quia id
unde quisquam fugiat?
</p>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Amet
repellendus blanditiis nam praesentium inventore temporibus
reprehenderit iste ex aliquam ipsum! Voluptas enim laborum est facere
itaque corrupti voluptatum aspernatur, eum ex, aut quasi iste quisquam?
Vel quisquam rerum eius quia.
</p>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Excepturi
aspernatur quis nam consequuntur iste doloremque blanditiis, ad quos
repellendus dolores, quae ab perspiciatis, totam non pariatur nobis illo
aperiam cumque. Perferendis nisi explicabo voluptate maxime, tempora
aliquam hic est minima. Cum sapiente fuga similique cupiditate veniam,
vel porro eaque voluptatibus corporis neque deserunt ex id explicabo
dolores in, corrupti repellendus dicta ut nulla beatae rerum perferendis
quo. Sunt, voluptas voluptatem!
</p>
<img src="https://images.unsplash.com/photo-1568043210943-0e8aac4b9734?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1950&q=80" alt="A sleepy cat" />
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Commodi modi
sit maxime ducimus eum, laudantium voluptate nobis sed itaque corporis
fugiat ullam ipsa. Animi, quidem!
</p>
<p>
Lorem ipsum dolor, sit amet consectetur adipisicing elit. Impedit
doloribus repellendus ipsa facilis velit temporibus. Reiciendis
voluptatum laboriosam aliquid possimus nihil eum molestias voluptatibus
sed ad porro dolor fuga excepturi, perferendis fugiat odio alias ab
explicabo nulla provident ratione corrupti voluptas! Quidem, consectetur
officiis necessitatibus reiciendis nesciunt saepe animi modi maiores
voluptates id perspiciatis at ipsum facere impedit voluptatem enim porro
excepturi atque sint rem eos blanditiis cumque quas quisquam. Quae eos
repellat at beatae esse porro qui molestias repellendus.
</p>
<p>
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Velit,
adipisci alias autem id saepe amet excepturi, laborum perferendis, cum
suscipit ipsa pariatur maxime optio? Non a quas iure magni
reprehenderit. Architecto earum eius veritatis praesentium, facilis
iste! Eos repudiandae ipsam et, quas quibusdam nemo repellendus hic
delectus quisquam vel, sed corrupti necessitatibus accusantium adipisci
ad? Maiores nobis corporis ipsum. Repudiandae dolorem voluptate expedita
ipsum deserunt eveniet suscipit, odit eligendi exercitationem quod
itaque molestias ullam illum nobis, molestiae enim at hic.
</p>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Nesciunt
repellendus tenetur numquam possimus unde neque praesentium aliquam.
Vero aspernatur nobis recusandae illo et quis totam vitae, accusantium
rerum a molestiae aliquid laboriosam debitis corporis neque in voluptas
necessitatibus doloribus? Laborum officiis sapiente quos quis libero
modi nostrum. Sunt officiis atque culpa neque reiciendis omnis
accusantium cumque ea voluptate! Aspernatur officia deserunt pariatur
nesciunt dignissimos id! Ducimus, pariatur provident magnam et amet
alias quia mollitia a earum id explicabo consectetur ut sapiente ipsam
dolor magni cupiditate quae architecto aliquam dignissimos. Aspernatur.
</p>
<img src="https://images.unsplash.com/photo-1545231160-9f9a3ed14696?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1567&q=80" alt="" />
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Perspiciatis
unde temporibus iste. Voluptatem doloremque ipsum a beatae, dolorem est
saepe nesciunt ratione velit nostrum? Earum excepturi illum natus autem
temporibus ab maiores! Architecto ducimus dolore modi suscipit eveniet
facilis quia aperiam neque?
</p>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eius, vel
soluta officia, possimus at repudiandae atque quidem maiores quae
tempora voluptatem! Cum, tempore ex. Perspiciatis harum blanditiis
adipisci atque dignissimos in facilis saepe, nam alias aperiam!
Similique ut ratione ducimus possimus voluptatum provident quos at error
culpa! Cum corrupti, accusamus, odit quasi odio ipsum quidem, quia id
unde quisquam fugiat?
</p>
</div>
<!-- AltBud character -->
<svg id="altBud" viewBox="0 0 100 100" aria-labelledby="altBudTitle altBudDesc" role="img">
<!-- Title -->
<title id="altBudTitle">AltBud</title>
<!-- Description -->
<desc id="altBudDesc">
AltBud is a (generally) happy little character who hangs out on webpages
and finds images without alt tags.
</desc>
<!-- Body outline -->
<path id="altBudBody" d="M 15 100
C 0 20 100 20 85 100" fill="#e0aaff" stroke="#10002b" stroke-width="2" transform="translate(0, 2)" />
<!-- Body clip -->
<mask id="bodyClip">
<path d="M 15 100
C 0 20 100 20 85 100" fill="#fff" stroke="#10002b" stroke-width="2" transform="translate(0, 2)" />
</mask>
<!-- Texture -->
<g id="altBudTexture" mask="url(#bodyClip)">
<circle cx="30" cy="40" r="16" fill="#c77dff"></circle>
<circle cx="80" cy="43" r="16" fill="#9d4edd"></circle>
<circle cx="30" cy="90" r="20" fill="#c77dff"></circle>
<circle cx="80" cy="105" r="24" fill="#9d4edd"></circle>
</g>
<!-- Eyes Normal -->
<g id="altBudEyesNormal" transform="translate(0, -5)">
<!-- Eye left -->
<g id="altBudEyeLeft">
<!-- Outer -->
<circle id="altBudEyeOuterLeft" cx="36" cy="75" r="6.5" fill="#fff" stroke="#10002b" stroke-width="1.5" />
<!-- Inner -->
<circle id="altBudEyeInnerLeft" cx="33" cy="75" r="3.5" fill="#10002b" />
</g>
<!-- Eye right -->
<g id="altBudEyeRight">
<!-- Outer-->
<circle id="altBudEyeOuterRight" cx="64" cy="75" r="6.5" fill="#fff" stroke="#10002b" stroke-width="1.5" />
<!-- Inner -->
<circle id="altBudEyeInnerRight" cx="61" cy="75" r="3.5" fill="#10002b" />
</g>
</g>
<!-- Hair -->
<g id="altBudHair">
<line x1="50" y1="42" x2="50" y2="34" stroke="#10002b" stroke-width="1.5" stroke-linecap="round"></line>
<line x1="50" y1="42" x2="58" y2="34" stroke="#10002b" stroke-width="1.5" stroke-linecap="round"></line>
<line x1="50" y1="42" x2="42" y2="32" stroke="#10002b" stroke-width="1.5" stroke-linecap="round"></line>
</g>
<!-- Mouth -->
<path id="altBudMouth" d="M 44 85
A 5 4 0 0 0 56 85
" stroke="#10002b" stroke-width="1.5" fill="transparent" stroke-linecap="round" />
</svg>
</div>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
height: 100%;
}
@font-face {
font-family: "Blokk";
src: url(./BLOKKNeue-Regular.woff2);
}
p:first-of-type {
font-size: 2rem;
letter-spacing: -0.05em;
}
body {
font-family: system-ui, sans-serif;
line-height: 1.5;
font-size: 1.25rem;
color: #10002b;
-webkit-font-smoothing: antialiased;
}
.wrapper {
max-width: 600px;
margin: 0 auto;
}
#altBud {
position: fixed;
bottom: 0;
right: 1rem;
width: 140px;
height: 140px;
transition: transform 300ms ease;
transform-origin: 100% 100%;
transform: translateY(8px);
}
.content {
margin: 0 auto;
padding: 3rem 1.5rem;
height: 100%;
overflow-y: scroll;
}
p + p {
margin-top: 1.5rem;
}
img {
max-width: 100%;
margin: 3rem 0;
}
g,
ellipse {
transform-box: fill-box;
transform-origin: center;
}
#altBudHair line {
animation: hair 3000ms linear infinite;
transform-origin: 50% 50%;
}
#altBudHair line:nth-of-type(2) {
animation-delay: 250ms;
}
#altBudHair line:nth-of-type(2) {
animation: hair2 5000ms ease infinite;
animation-delay: 100ms;
}
@keyframes hair {
0% {
transform: rotate(-4deg);
}
50% {
transform: rotate(4deg);
}
100% {
transform: rotate(-4deg);
}
}
@keyframes hair2 {
0% {
transform: rotate(6deg);
}
50% {
transform: rotate(-6deg);
}
100% {
transform: rotate(6deg);
}
}
#altBudBody {
transition: fill 500ms ease;
}
#altBudTexture > * {
transition: fill 500ms ease;
}
@media (prefers-reduced-motion: reduce) {
#altBudHair > * {
animation: none !important;
}
* {
transition: none !important;
}
}
import intersectionObserver from "https://cdn.skypack.dev/intersection-observer@0.11.0";
const altBud = {
root: document.getElementById("altBud"),
eyeLeft: document.getElementById("altBudEyeLeft"),
eyeInnerLeft: document.getElementById("altBudEyeInnerLeft"),
eyeInnerRight: document.getElementById("altBudEyeInnerRight"),
eyeRight: document.getElementById("altBudEyeRight"),
mouth: document.getElementById("altBudMouth"),
arm: document.getElementById("altBudArm"),
body: document.getElementById("altBudBody"),
texture: document.getElementById("altBudTexture")
};
const prefersReducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const allImages = document.querySelectorAll("img");
let activeWatchImg = null;
let isAngry = false;
const imgObserver = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
if (entry.isIntersecting) {
activeWatchImg = entry.target;
} else {
if (activeWatchImg === entry.target) {
activeWatchImg = null;
}
}
}
},
{
threshold: 0
}
);
for (const img of allImages) {
imgObserver.observe(img);
}
function rotateEye(target, eye) {
const targetBounds = target.getBoundingClientRect();
let { x: eyeX, y: eyeY } = eye.getBoundingClientRect();
const targetX = targetBounds.x + targetBounds.width / 2;
const targetY = targetBounds.y + targetBounds.height / 2;
const angle = Math.atan2(targetY - eyeY, targetX - eyeX) - Math.PI;
eye.style.transform = `rotate(${angle}rad)`;
}
function toggleAngry(angry) {
if (angry) {
altBud.eyeInnerLeft.setAttribute("cx", 36);
altBud.eyeInnerRight.setAttribute("cx", 64);
altBud.mouth.setAttribute("d", "M 44 87 A 5 4 0 0 1 56 87");
altBud.body.setAttribute("fill", "#e01e37");
const spots = altBud.texture.querySelectorAll("circle");
spots[0].setAttribute("fill", "#bd1f36");
spots[1].setAttribute("fill", "#c71f37");
spots[2].setAttribute("fill", "#85182a");
spots[3].setAttribute("fill", "#c71f37");
if (!prefersReducedMotion) {
altBud.root.style.transform = `rotate(-4deg) translateY(8px)`;
setTimeout(() => {
altBud.root.style.transform = `rotate(4deg) translateY(8px)`;
setTimeout(() => {
altBud.root.style.transform = `rotate(0deg) translateY(8px)`;
}, 125);
}, 125);
}
} else {
altBud.eyeInnerLeft.setAttribute("cx", 33);
altBud.eyeInnerRight.setAttribute("cx", 61);
altBud.mouth.setAttribute("d", "M 44 85 A 5 4 0 0 0 56 85");
altBud.body.setAttribute("fill", "#e0aaff");
const spots = altBud.texture.querySelectorAll("circle");
spots[0].setAttribute("fill", "#c77dff");
spots[1].setAttribute("fill", "#9d4edd");
spots[2].setAttribute("fill", "#c77dff");
spots[3].setAttribute("fill", "#9d4edd");
}
}
(function animLoop() {
if (activeWatchImg) {
rotateEye(activeWatchImg, altBud.eyeLeft);
rotateEye(activeWatchImg, altBud.eyeRight);
if (activeWatchImg.alt.length === 0 && !isAngry) {
toggleAngry(true);
isAngry = true;
} else {
if (activeWatchImg.alt.length !== 0 && isAngry) {
toggleAngry(false);
isAngry = false;
}
}
}
requestAnimationFrame(animLoop);
})();
Also see: Tab Triggers