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.
mixin avatar(name, status)
.avatar(class=((status ? "status " + status : "")))
img(src=`https://api.dicebear.com/9.x/bottts-neutral/svg?seed=${name}&rotate=350&backgroundType=solid,gradientLinear&backgroundRotation=360,10,20,30,280,270,180,190,200,320,310,300,290,330,340,350,210,220,230,250,260,240,170,160,150,140,130,120,110,100,90,80,70,60,50,40,0&randomizeIds=true`)
main
form.dark
h1 <span>CSS</span> MASK <span>&</span> TRIGONOMETRY
h2 for avatar status indicators
#app
.resizer
+avatar("inky", "offline")
+avatar("blinky", "online")
+avatar("pinky", "idle")
+avatar("clyde", "dnd")
+avatar("Pacman", "")
.bg
#controls
.field#angle
label
code --status-angle
em 125deg
.range
input(type="range",min=0,max=360,value=125)
.field#size
label
code --status-size
em 20px
.range
input(type="range",min=5,max=50,value=20)
.field#offset
label
code --status-offset
em 0px
.range
input(type="range",min=-20,max=20,value=0)
.field#gap
label
code --status-gap
em 0px
.range
input(type="range",min=0,max=20,value=5)
.field#unit
label
| unit
.group
label px
input.toggle.dual(type="checkbox")
label %
p demonstrating the indicators stick to the circumference of the avatar, without any explicit <code>h/w/x/y</code> values being set.
// social icons
a.social-icon.codepen(href="https://codepen.io/simeydotme" title="view my codepens")
| Made by Simey
a.social-icon.twitter(href="https://twitter.com/simeydotme")
svg(viewBox="0 0 24 24")
path(stroke="none" d="M0 0h24v24H0z" fill="none")
path(d="M22 4.01c-1 .49 -1.98 .689 -3 .99c-1.121 -1.265 -2.783 -1.335 -4.38 -.737s-2.643 2.06 -2.62 3.737v1c-3.245 .083 -6.135 -1.395 -8 -4c0 0 -4.182 7.433 4 11c-1.872 1.247 -3.739 2.088 -6 2c3.308 1.803 6.913 2.423 10.034 1.517c3.58 -1.04 6.522 -3.723 7.651 -7.742a13.84 13.84 0 0 0 .497 -3.753c-.002 -.249 1.51 -2.772 1.818 -4.013z")
a.social-icon.github(href="https://github.com/simeydotme")
svg(viewBox="0 0 24 24")
path(stroke="none" d="M0 0h24v24H0z" fill="none")
path(d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5")
:root {
/* demo vars for controlling */
--status-size: 20px; /* size of the status */
--status-gap: 5px; /* size of the gap around the status */
--status-offset: 0px; /* how far from the circumference to offset the status */
--status-angle: 120deg; /* where on the edge we want the status */
}
.avatar {
/* necessary vars for calculating position/size */
--d: calc(var(--status-size) + (var(--status-gap) * 2)); /* diameter of the mask */
--r: calc((100% / 2) + var(--status-offset)); /* distance from edge of avatar */
--x: calc(var(--r) * cos(var(--status-angle) - 90deg) + (100% / 2)); /* x coord of status/mask */
--y: calc(var(--r) * sin(var(--status-angle) - 90deg) + (100% / 2)); /* y coord of status/mask */
/* colors */
--color-offline: slategrey;
--color-online: rgb(0, 255, 135);
--color-idle: rgb(255, 185, 51);
--color-dnd: rgb(255, 40, 80);
position: relative;
&.status {
&::after {
content: "";
aspect-ratio: 1;
background: var(--color-offline);
border-radius: 100%;
position: absolute;
width: var(--status-size);
top: calc(var(--y) - (var(--status-size)/2));
left: calc(var(--x) - (var(--status-size)/2));
}
& > * {
/* create the cutout mask around the image,
it's just a radial gradient positioned at the same place as the
psuedo-element ::after */
mask-image: radial-gradient(var(--d) var(--d) at var(--x) var(--y), transparent calc(50% - 0.5px), black calc(50% + 0.5px));
}
&.online&::after {
background-color: var(--color-online);
}
&.idle&::after {
background-color: var(--color-idle);
}
&.dnd&::after {
background-color: var(--color-dnd);
}
/*
these next styles are just extra, not needed if you
just want the color circles
*/
&.idle&::after {
/* extra mask for idle 'moon' effect */
mask-image: radial-gradient(90% 100% at 90% 30%, transparent calc(50% - 0.5px), black calc(50% + 0.5px));
}
&.dnd&::before {
/* this is all a bit extra for the 'dnd' style */
content: "";
position: absolute;
top: calc(var(--y) );
left: calc(var(--x) );
width: calc(var(--status-size) * 0.8);
translate: -50% -50%;
rotate: -9deg;
aspect-ratio: 4/1;
border-radius: 100vmax;
background: hsl(349deg, 90%, 80% );
background: color-mix(in oklch, var(--color-dnd), white 50%);
z-index: 1;
}
}
}
/** demo specific css */
.avatar {
height: 100%;
aspect-ratio: 1;
flex-shrink: 0;
z-index: 1;
& img {
display: block;
width: 100%;
aspect-ratio: 1;
object-fit: cover;
border-radius: 100%;
filter: grayscale(0.9);
transition: all 0.5s ease;
}
}
#app {
display: flex;
place-content: center;
align-items: center;
}
.resizer {
display: flex;
position: relative;
gap: 20px;
padding: 20px;
place-content: center;
align-items: center;
overflow: hidden;
height: 120px;
resize: vertical;
&:hover img {
filter: grayscale(0);
}
}
.bg {
position: absolute;
inset: 0;
opacity: 0;
background: repeating-linear-gradient(45deg, transparent 0px , hsla(var(--h),var(--s),66%,0.66) 0px 10px, transparent 10px 20px ) 20%;
transition: all 5s ease;
}
.resizer:hover .bg {
opacity: 1;
transition-duration: 500ms;
}
html, body, main {
height: 100%;
}
form {
padding-block: 2em;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: max-content max-content 2fr 1fr;
place-items: center;
height: 100%;
}
#controls {
display: flex;
flex-wrap: wrap;
place-content: center;
gap: 1em;
}
.field {
text-align: center;
margin: 0!important;
& label {
width: 100%;
display: flex;
gap: 0.5em;
align-items: center;
justify-content: center;
}
& em {
font-size: 0.875em;
text-transform: lowercase;
color: rgb(0, 255, 135);
&::before {
content: " ( ";
}
&::after {
content: " )";
}
}
& code {
background: none;
color: var(--fg);
}
& .range input {
width: 100%;
}
}
h1,h2 {
margin:0;
text-shadow: 0 1px 1px color-mix(in oklch, var(--bg), black);
}
h2 {
font-weight: 200;
font-style: italic;
color: color-mix(in oklch, var(--fg) 60%, var(--bg));
}
h1 span {
font-style: italic;
color: color-mix(in oklch, var(--fg) 60%, var(--bg));
}
body {
font-family: 'Asap Condensed', sans-serif;
font-weight: 400;
}
h1, h2 {
font-family: 'Amaranth', sans-serif;
}
code, pre {
font-family: 'Kode mono', monospace;
}
code {
display: inline-block;
padding-inline: 0.4em;
border-radius: 0.2em;
background: color-mix(in oklch, var(--bg) 85%, black);
color: color-mix(in oklch, var(--fg) 60%, var(--tint));
font-size: 0.875em;
}
/*
javascript just for demo the values changing from slider
not needed in final solution
*/
const appEl = document.querySelector("#app");
let unit = 'px';
const inputs = [
{ id: "size", property: "--status-size" },
{ id: "angle", property: "--status-angle", suffix: "deg" },
{ id: "offset", property: "--status-offset" },
{ id: "gap", property: "--status-gap" }
];
inputs.forEach(({ id, property, suffix }) => {
const inputEl = document.querySelector(`#${id} input`);
const labelEl = document.querySelector(`#${id} label`);
inputEl.addEventListener("input", (e) => {
const value = e.target.value;
appEl.style.setProperty(property, value + (suffix ?? unit));
labelEl.querySelector("em").innerText = value + (suffix ?? unit);
});
});
const unitEl = document.querySelector("#unit input");
const unitLabel = document.querySelector("#unit label");
unitEl.addEventListener("input", (e) => {
unit = e.target.checked ? "%" : "px";
inputs.forEach(({ id }) => {
const inputEl = document.querySelector(`#${id} input`);
inputEl.dispatchEvent(new Event("input", { bubbles: true }));
});
});
Also see: Tab Triggers