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 id='preview'>
  <p class='inner-content'>
    Text generated by Cat Ipsum.
    Hey! you there, with the hands find empty spot in cupboard and sleep all day. You are a captive audience
    while
    sitting on the toilet, pet me play with twist ties good morning sunshine but leave dead animals as gifts
    check
    cat door for ambush 10 times before coming in for what the heck just happened, something feels fishy. Check
    cat
    door for ambush 10 times before coming in fall asleep on the washing machine. Put claws in the eye of the
    beholder groom yourself 4 hours - checked, have your beauty sleep 18 hours - checked, be fabulous for the
    rest
    of the day - checked. Cat sit like bread purr wack the mini furry mouse. Make muffins. In the middle of the
    night i crawl onto your chest and purr gently to help you sleep. Poop in the plant pot gnaw the corn cob,
    catto
    munch salmono peer out window, chatter at birds, lure them to mouth do not try to mix old food with new one
    to
    fool me!.

    I'm going to lap some water out of my master's cup meow chew foot, so stare at ceiling please stop looking
    at
    your phone and pet me so licks paws. Meow find something else more interesting, yet kitty pounce, trip,
    faceplant you didn't see that no you didn't definitely didn't lick, lick, lick, and preen away the
    embarrassment. Lick the plastic bag eat from dog's food put toy mouse in food bowl run out of litter box at
    full
    speed kitty scratches couch bad kitty massacre a bird in the living room and then look like the cutest and
    most
    innocent animal on the planet howl on top of tall thing but waffles. Toy mouse squeak roll over eat my own
    ears
    and catty ipsum but if it fits i sits dream about hunting birds. Stuff and things mew. I shredded your
    linens
    for you. Mew give me some of your food give me some of your food give me some of your food meh, i don't want
    it
    step on your keyboard while you're gaming and then turn in a circle . Look at dog hiiiiiisssss i could pee
    on
    this if i had the energy. Lick arm hair ask to go outside and ask to come inside and ask to go outside and
    ask
    to come inside 𝕄𝔼𝕆𝕎 poop on grasses. Destroy couch cat snacks sit in a box for hours run off
    table
    persian cat jump eat fish so mew mew catch small lizards, bring them into house, then unable to find them on
    carpet sugar, my siamese, stalks me (in a good way), day and night . Russian blue. Stinky cat drool at four
    in
    the morning wake up owner meeeeeeooww scratch at legs and beg for food then cry and yowl until they wake up
    at
    two pm jump on window and sleep while observing the bootyful cat next door that u really like but who
    already
    has a boyfriend end up making babies with her and let her move in but lie on your belly and purr when you
    are
    asleep sit on human.

    Poop on couch. Have my breakfast spaghetti yarn dismember a mouse and then regurgitate parts of it on the
    family
    room floor yet cats go for world domination lick the other cats kitty pounce, trip, faceplant you didn't see
    that no you didn't definitely didn't lick, lick, lick, and preen away the embarrassment, meow meow pee in
    shoe
    and sweet beast. Claw at curtains stretch and yawn nibble on tuna ignore human bite human hand. My slave
    human
    didn't give me any food so i pooped on the floor jump on counter removed by human jump on counter again
    removed
    by human meow before jumping on counter this time to let the human know am coming back. Fight an alligator
    and
    win leave hair on owner's clothes or poop in litter box, scratch the walls cat walks in keyboard and play
    with
    twist ties the door is opening! how exciting oh, it's you, meh. Knock dish off table head butt cant eat out
    of
    my own dish grab pompom in mouth and put in water dish so i'm bored inside, let me out i'm lonely outside,
    let
    me in i can't make up my mind whether to go in or out, guess i'll just stand partway in and partway out,
    contemplating the universe for half an hour how dare you nudge me with your foot?!?! leap into the air in
    greatest offense! but pee in human's bed until he cleans the litter box. Push your water glass on the floor.
    Run
    in circles bury the poop bury it deep, for grab pompom in mouth and put in water dish. Cat mojo chew
    master's
    slippers. Meowzer. Break lamps and curl up into a ball howl on top of tall thing take a big fluffing crap
    sit and stare bite the neighbor's bratty kid.

  </p>
</div>
<div id="form-container">
  <div id="form">
    <div id='size-inputs'>
      <h2>Sizes</h2>
      <div>
        <label for="scrollbar-width">Scrollbar Width (px)</label>
        <input id="scrollbar-width" name="scrollbar-width" type="number" min="0" step="10" value="20" />
      </div>
      <div>
        <label for="scrollbar-height">Scrollbar Height (px)</label>
        <input id="scrollbar-height" name="scrollbar-height" type="number" min="0" step="10" value="20" />
      </div>
      <div>
        <label for="scrollbar-border-radius">Border Radius (px)</label>
        <input id="scrollbar-border-radius" name="scrollbar-border-radius" type="number" min="0" step="2" value="8" />
      </div>
      <h2>Colors</h2>
    </div>
    <div id="color-inputs">
      <div>
        <label for="scrollbar-thumb-color">Thumb</label>
        <button id="thumb-color-picker" title="thumb-color-picker" />
      </div>
      <div>
        <label for="scrollbar-track-color">Track</label>
        <button id="track-color-picker" title="track-color-picker" />
      </div>
      <div>
        <label for="scrollbar-corner-color">Corner</label>
        <button id="corner-color-picker" title="corner-color-picker" />
      </div>
    </div>
    <div id="export-button-container">
      <button id='export-css'>Export CSS</button>
      <p id='export-css-hint'></p>
    </div>
  </div>

</div>
              
            
!

CSS

              
                body {
  font-family: "PT Mono", monospace;
  display: flex;
  flex-direction: row;
  margin: auto;
  padding: 24px;
  color: white;
  background-color: #000000;
  height: 100%;
}

#form-container {
  width: 50%;
  min-width: 30%;
  display: flex;
  align-items: center;
  justify-items: center;
}

#form {
  display: flex;
  justify-items: center;
  flex-direction: column;
}

#color-inputs {
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

#color-inputs > div {
  display: grid;
  place-items: center;
  margin-block-end: 16px;
}

#preview {
  margin: auto;
  width: 300px;
  height: 400px;
  resize: both;
  overflow: auto;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid white;
  color: black;
  background: rgba(255, 255, 255, 0.8);
}

#preview::-webkit-scrollbar {
  width: var(--scrollbar-width, 20px);
  height: var(--scrollbar-height, 20px);
}

#preview::-webkit-scrollbar-track {
  background: var(--scrollbar-track-color, #a1a1aa);
}

#preview::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb-color, #3b82f6);
  border-radius: var(--scrollbar-border-radius, 8px);
}

#export-button-container {
  position: relative;
  display: grid;
  place-items: center;
  margin: 16px;
}

#export-button-container > button {
  padding: 12px;
  border-radius: 8px;
}

#export-css-hint {
  opacity: 0;
  color: skyblue;
  left: 70%;
  position: absolute;
  transition: 0.3s;
}

              
            
!

JS

              
                import("https://cdn.skypack.dev/copy-to-clipboard").then(
  (a) => (navigator.clipboard.writeText = a.default)
); // this is only required for users to be able to get the exported styles from the iframes in the article. If you are at the codepen or the main scrollbar playground, this is not necessary

const scrollbarDiv = document.getElementById("preview");
const heightInput = document.getElementById("scrollbar-height");
const widthInput = document.getElementById("scrollbar-width");
const borderRadiusInput = document.getElementById("scrollbar-border-radius");
const exportCSSButton = document.getElementById("export-css");
const exportCSSHint = document.getElementById("export-css-hint");

const sizePropertyArray = [
  {
    el: heightInput,
    property: "--scrollbar-height"
  },
  {
    el: widthInput,
    property: "--scrollbar-width"
  },
  {
    el: borderRadiusInput,
    property: "--scrollbar-border-radius"
  }
];

const setSizeFieldOnChange = (el, property) => {
  el.onchange = () => {
    scrollbarDiv.style.setProperty(property, `${el.value}px`);
  };
};

sizePropertyArray.forEach(({ el, property }) =>
  setSizeFieldOnChange(el, property)
);

// color

const bindColorPicker = (el, property, defaultColor) => {
  const pickr = Pickr.create({
    el,
    default: defaultColor,
    theme: "nano",
    swatches: [
      "rgba(244, 67, 54, 1)",
      "rgba(233, 30, 99, 0.95)",
      "rgba(156, 39, 176, 0.9)",
      "rgba(103, 58, 183, 0.85)",
      "rgba(63, 81, 181, 0.8)",
      "rgba(33, 150, 243, 0.75)",
      "rgba(3, 169, 244, 0.7)",
      "rgba(0, 188, 212, 0.7)",
      "rgba(0, 150, 136, 0.75)",
      "rgba(76, 175, 80, 0.8)",
      "rgba(139, 195, 74, 0.85)",
      "rgba(205, 220, 57, 0.9)",
      "rgba(255, 235, 59, 0.95)",
      "rgba(255, 193, 7, 1)"
    ],
    comparison: false,
    components: {
      preview: true,
      opacity: true,
      hue: true,
      interaction: {
        hex: true,
        rgba: true,
        hsla: true,
        hsva: true,
        cmyk: true,
        input: true,
        clear: true,
        save: true
      }
    }
  });

  pickr
    .on("change", (color, instance) => {
      scrollbarDiv.style.setProperty(property, color.toHEXA());
    })
    .on("save", () => {});
};

const colorsPropertyArray = [
  {
    el: "#thumb-color-picker",
    property: "--scrollbar-thumb-color",
    defaultColor: "#3B82F6"
  },
  {
    el: "#track-color-picker",
    property: "--scrollbar-track-color",
    defaultColor: "#A1A1AA"
  },
  {
    el: "#corner-color-picker",
    property: "--scrollbar-corner-color",
    defaultColor: "#FFFFFF"
  }
];

colorsPropertyArray.forEach(({ el, property, defaultColor }) =>
  bindColorPicker(el, property, defaultColor)
);

let defaultElementForStyling = "body"; // modify this for scrollbar styles to be applied to another element

exportCSSButton.onclick = async () => {
  let customProperties = scrollbarDiv.style.cssText;
  let exportedStyle = `${defaultElementForStyling} { ${customProperties} } `;
  const cssRules = Object.values(document.styleSheets[2].cssRules); // In Codepen, the user's styles are loaded last
  const scrollbarRules = cssRules.filter((rule) =>
    rule.cssText.includes("::-webkit-scrollbar")
  );
  scrollbarRules.forEach((rule) => {
    const modifiedRule = rule.cssText.replace(
      "#preview",
      defaultElementForStyling
    );
    exportedStyle += modifiedRule;
  });

  navigator.clipboard.writeText(exportedStyle);
  exportCSSHint.textContent = "Copied";
  exportCSSHint.style.opacity = 1;
  setTimeout(() => {
    exportCSSHint.style.opacity = 0;
  }, 1500);
};

              
            
!
999px

Console