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 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>
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;
}
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);
};
Also see: Tab Triggers