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

              
                <p>
  <span aria-hidden="true"><span class="dropcap">L</span>orem</span>
  <span class="visually-hidden">Lorem</span>
  ipsum dolor sit amet consectetur adipisicing elit. Asperiores iste
  voluptatibus facere, nam exercitationem, itaque dicta repellat, tempore
  modi corporis quasi sit aut assumenda earum pariatur. Ipsam recusandae
  asperiores dicta sint, nisi modi maxime vitae quibusdam aliquid accusamus,
  odit ex, quae necessitatibus provident. Blanditiis, saepe!
</p>
<script>
  (async function() {
    if (CSS["paintWorklet"] === undefined) {
      await import("https://unpkg.com/css-paint-polyfill");
    }
    CSS.paintWorklet.addModule('https://codepen.io/georgedoescode/pen/71d39ba0fb594def3f2f23519175f5bb.js');
    document.documentElement.style.setProperty('--dropcap-seed', Math.random() * 1000)
  })();
</script>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 1.25rem;
  line-height: 1.5;
  padding: 1.5rem;
  color: #3c3852;
}

p {
  max-width: 52ch;
}

.dropcap {
  float: left;
  font-size: 2em;
  line-height: 1;
  padding: 0.5em;
  margin-top: 0.15em;
  margin-right: 0.3em;
  background: #7257fa;
  color: #fff;
  border-radius: 0.375rem;
  font-weight: 700;
  background-image: paint(dropCap);
}

.visually-hidden {
  border: 0;
  clip: rect(0 0 0 0);
  height: auto;
  margin: 0;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  white-space: nowrap;
}

              
            
!

JS

              
                // source: https://github.com/bryc/code/blob/master/jshash/PRNGs.md
function mulberry32(a) {
  return function () {
    a |= 0;
    a = (a + 0x6d2b79f5) | 0;
    var t = Math.imul(a ^ (a >>> 15), 1 | a);
    t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
  };
}

const pointInRect = ({ x1, y1, x2, y2 }, { x, y }) =>
  x > x1 && x < x2 && y > y1 && y < y2;

function circleIntersect(x0, y0, r0, x1, y1, r1) {
  return Math.hypot(x0 - x1, y0 - y1) <= r0 + r1;
}

class DropCap {
  static get inputProperties() {
    return ["--dropcap-seed"];
  }

  paint(ctx, geometry, props) {
    const seed = props.get("--dropcap-seed").toString().trim();

    const random = mulberry32(seed);

    const colors = ["#352970", "#FFD53D", "#F25C54", "#48CB8A", "#F25C54"];

    const center = {
      x: geometry.width / 2,
      y: geometry.height / 2
    };

    // Estimate the bounding rect of the dropcap's letter (this could be much nicer!)
    const letterBoundingRect = {
      x1: geometry.width / 2 - 20,
      y1: geometry.height / 2 - 20,
      x2: geometry.height / 2 + 20,
      y2: geometry.height / 2 + 20
    };

    const circles = [];

    for (let i = 0; i < 32; i++) {
      let x;
      let y;
      let radius;

      // Try and plot a circle that does not intersect the dropcap's letter, or any other circle. Again, this could be much cleaner!
      for (let j = 0; j < 30; j++) {
        x = random() * geometry.width;
        y = random() * geometry.height;
        radius = 0.25 + random() * 4;

        let overlapsWithOtherCircles = false;

        for (let i = 0; i < circles.length; i++) {
          var dx = x - circles[i].x;
          var dy = y - circles[i].y;
          var distance = Math.sqrt(dx * dx + dy * dy);

          if (distance < radius * 2 + circles[i].radius) {
            overlapsWithOtherCircles = true;
          }
        }

        if (
          !overlapsWithOtherCircles &&
          !pointInRect(letterBoundingRect, { x, y })
        ) {
          break;
        }
      }

      if (!x || !y) continue;

      circles.push({
        x,
        y,
        radius
      });

      ctx.fillStyle = colors[~~(random() * colors.length)];
      ctx.beginPath();
      ctx.arc(x, y, radius, 0, 2 * Math.PI);
      ctx.fill();
    }
  }
}

if (typeof registerPaint !== "undefined") {
  registerPaint("dropCap", DropCap);
}

              
            
!
999px

Console