Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <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>
              
            
!

CSS

              
                * {
  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;
  }
}

              
            
!

JS

              
                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);
})();

              
            
!
999px

Console