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

              
                <main>
  <div></div>
</main>
<aside>
  <div class="scrubber-container">
    <label for="scrubber">Sides</label>
    <input id="scrubber" type="range" min="3" max="60" value="40" step="1" />
    <output for="scrubber"><b>40</b></output>
  </div>
</aside>
              
            
!

CSS

              
                main div {
  margin: 5vmin auto;
  width: 70vmin;
  height: 70vmin;
  position: relative;
  --center: 50%;
  --radius: 50%;
  box-sizing: border-box;
}
main div::before {
  position: absolute;
  inset: 0;
  border: 0.5vmin dashed hsl(176 100% 64% / 40%);
  content: "";
}
main div::after {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(135deg, hsl(196 100% 64%), hsl(176 100% 64%));
  clip-path: var(--clipped);
}
p {
  border-radius: 50%;
  font-size: 0.5rem;
  font-size: system-ui, sans-serif;
}
main {
  flex: 1;
}

body {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  background: linear-gradient(45deg, hsl(344 100% 50%), hsl(234 100% 60%));
  /*
  background: conic-gradient(from 90deg at 50% 30vmin, hsl(334 100% 60%), hsl(284 100% 60%), hsl(244 100% 60%), hsl(44 100% 60%)); */
}
aside {
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  left: 0;
  right: 0;
  padding: 0.5rem 1rem 0;
  background: hsl(223 100% 3% / 87%);
  backdrop-filter: blur(8px);
  font-family: system-ui, sans-serif;
  border-top: 0.5vmin solid hsl(343 100% 60%);
}
.scrubbable .scrubber-container {
  opacity: 1;
}
label {
  padding-right: 0.5rem;
}
.scrubber-container {
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 400ms ease-out;
}
output {
  font-family: monospace;
  overflow-y: auto;
  padding: 1rem 0.5rem 1rem;
}

              
            
!

JS

              
                const div = document.querySelector("div");
const output = document.querySelector("output");
const minSides = 3;

const supportsCssMath = window?.CSS?.supports("width: calc(sin(0deg) * 1vw)");

if (supportsCssMath) {
  div.classList.add("css-math-supported");
  finalPoints = generateViaCss();
  setupInteraction();
} else {
  document.querySelector("aside").textContent =
    "CSS Trig Functions are not supported in this browser. Please try the latest version of Safari, Firefox, Edge, or Chrome.";
}

function generateViaCss() {
  let points = [];

  for (let i = minSides; i <= 60; i++) {
    points.push(generateNSides(i));
  }

  return points;
}

function generateNSides(n) {
  let points = [];

  for (let i = 0; i < n; i++) {
    points.push(
      `calc(var(--center) + (cos(${
        (i / n) * 360
      }deg) * var(--radius))) calc(var(--center) + (sin(${
        (i / n) * 360
      }deg) * var(--radius)))`
    );
  }

  return `polygon(evenodd, ${points.join(",")})`;
}

function setupInteraction() {
  scrubber.setAttribute("max", finalPoints.length + minSides - 1);
  //scrubber.setAttribute("value", finalPoints.length);

  const pathLength = finalPoints.length;

  document.body.classList.add("scrubbable");

  scrubber.addEventListener("input", updateOutput);

  function updateOutput() {
    const step = scrubber.value;
    div.style.setProperty(
      "--clipped",
      finalPoints[parseInt(step, 10) - minSides]
    );

    document.querySelectorAll("output");
    output.textContent = step;
  }

  updateOutput();
}

              
            
!
999px

Console