Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ 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

Auto Save

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="placemat"></div>
<div class="bowl">
  <div class="text">alphabet<br />soup</div>
</div>
<button class="btn" id="add-noodles">add more noodles</button>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Gluten:wght@600&family=Space+Mono&display=swap");

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  --color-noodle: hsl(32 100% 75%);
  --color-soup: hsl(10 100% 34%);
  --color-placemat: hsla(0 100% 39% / 0.5);

  display: grid;
  grid-template-areas: "body";
  place-items: center;
  font-family: "Gluten", monospace;
  background: hsl(186deg 67% 74%);
}

body > * {
  grid-area: body;
}

.placemat {
  width: 90vmin;
  aspect-ratio: 5 / 4;
  background: white;
  background-image: linear-gradient(
      90deg,
      var(--color-placemat) 50%,
      transparent 0
    ),
    linear-gradient(var(--color-placemat) 50%, transparent 0);
  background-size: 4vmin 4vmin;
  border-radius: 0.5vmin;
  box-shadow: hsla(0 0% 0% / 0.1) 0 1vmin 1vmin -0.5vmin;
}

.bowl {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  grid-template-areas: "bowl";
  aspect-ratio: 1;
  width: 75vmin;
  font-size: 10vmin;
  text-transform: uppercase;
  background: var(--color-soup);
  color: var(--color-noodle);
  border-radius: 50%;
  border: 5vmin solid white;
  box-shadow: hsla(0 0% 0% / 0.05) 2vmin 2vmin 2vmin -2vmin,
    hsla(0 0% 0% / 0.05) -2vmin -2vmin 2vmin -2vmin, white 0 0 0 5vmin,
    hsla(0 0% 0% / 0.1) -5vmin -5vmin 10vmin 1vmin inset,
    hsla(0 0% 0% / 0.1) 5vmin 5vmin 10vmin 1vmin inset,
    hsl(0 0% 0% / 0.1) 0 0 0 0.5vmin inset,
    hsla(0 0% 0% / 0.07) 5vmin 5vmin 1vmin;
}

.bowl > * {
  grid-area: bowl;
}

.text {
  width: 100%;
  text-align: center;
}

.char {
  position: relative;
  letter-spacing: -0.1em;
  transform: scaleX(0.8);
}

.btn {
  --bg-color: hsl(60deg 95% 60%);
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  font-family: "Space Mono", monospace;
  background-color: var(--bg-color);
  border: 2px dashed black;
  border-radius: 0.125rem;
  cursor: pointer;
  transform: translateY(-1px);
  box-shadow: var(--bg-color) 0 0 0 2px, hsla(0 0% 0% / 0.2) 2px 2px 6px;
}

.btn:focus-visible {
  box-shadow: none;
  border-color: transparent;
  outline-offset: -4px;
}

.btn:active {
  transform: translateY(0);
  box-shadow: var(--bg-color) 0 0 0 2px, hsla(0 0% 0% / 0.2) 2px 2px 4px;
}

              
            
!

JS

              
                const bowl = document.querySelector(".bowl");
const text = document.querySelector(".text");
const addNoodlesBtn = document.getElementById("add-noodles");
const chars = new SplitText(text, { type: "chars", charsClass: "char" });
const alphabet = "abcdefghijklmnopqrstuvwxyz";

gsap.defaults({ overwrite: true });

function getRandomInt(val) {
  return Math.ceil(Math.random() * val) * (Math.round(Math.random()) ? 1 : -1);
}

function addLetter() {
  const el = document.createElement("div");
  const char = alphabet[Math.floor(Math.random() * alphabet.length)];
  const pos = 40;
  const translate = 30;
  const rotate = 60;

  el.innerText = char;
  el.classList.add("char");
  el.style.top = `${getRandomInt(pos)}%`;
  el.style.left = `${getRandomInt(pos)}%`;

  bowl.appendChild(el);
  gsap.to(el, {
    xPercent: () => getRandomInt(translate),
    yPercent: () => getRandomInt(translate),
    rotation: () => getRandomInt(rotate),
    ease: "expo.out",
    duration: 2
  });
}

function moveChars(obj) {
  const { event, deltaX, deltaY } = obj;
  const el = event.target;
  const r = el.getBoundingClientRect();
  const y = event.clientY - (r.top + Math.floor(r.height / 2));
  const t = 5;

  gsap.to(obj.event.target, {
    xPercent: `+=${deltaX * t}`,
    yPercent: `+=${deltaY * t}`,
    rotation: `-=${deltaX * t * Math.sign(y)}`,
    duration: 3,
    ease: "expo.out"
  });
}

Observer.create({
  target: bowl,
  onMove: (self) => self.event.target.matches(".char") && moveChars(self)
});

gsap.to(".char", {
  xPercent: () => getRandomInt(10),
  yPercent: () => getRandomInt(10),
  rotation: () => getRandomInt(20),
  duration: 5
});

addNoodlesBtn.addEventListener("click", addLetter);

              
            
!
999px

Console