Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <canvas class="canvasElm"></canvas>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  border: 0;
}

html {
  box-sizing: border-box;
  font-size: 62.5%; /* reseting base font-size to 10px */
  scroll-behavior: smooth;
}
*,
*:before,
*:after {
  box-sizing: inherit;
}

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

body {
  font-size: 1.6em; /* base font size is 16px */
  line-height: 1.4;
  font-family: -apple-system, sans-serif, BlinkMacSystemFont, "Segoe UI",
    Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
    "Segoe UI Symbol";
  background-color: white;
  color: rgba(0, 0, 0, 0.9);
  min-height: 100vh;
  /* mobile viewport bug fix */
  min-height: -webkit-fill-available;
}

/* ———————————————————————— */

.canvasElm {
  box-shadow: 0 0 40px 1px rgba(0, 0, 0, 0.1);
  background: #222222;
  position: absolute;
  top: 0;
  left: 0;
}

.titles {
  position: absolute;
  top: 24px;
  left: 24px;
  color: rgba(255, 255, 255, 1);
  max-width: 240px;
  line-height: 1.2;
  z-index: 2;
  pointer-events: none;
}
.titles h1 {
  font-size: 24px;
  margin-bottom: 8px;
}
.titles h3 {
  font-size: 16px;
  font-weight: 400;
  opacity: 0.6;
}

              
            
!

JS

              
                let canvasElm = document.querySelector(".canvasElm");

canvasElm.width = window.innerWidth;
canvasElm.height = window.innerHeight;

let colors = [
  "109,176,238",
  "109,238,230",
  "150,238,109",
  "174,109,238",
  "235,238,109",
  "238,109,109",
  "238,109,225",
  "238,186,109"
];

function randomBetween(min, max) {
  return Math.random() * (max - min) + min;
}

let ctx = canvasElm.getContext("2d");

class Particle {
  constructor(x, y, dx, dy, size, color, colorOpacity) {
    this.x = x;
    this.y = y;
    this.dx = dx;
    this.dy = dy;
    this.size = size;
    this.color = color;
    this.colorOpacity = colorOpacity;
    this.growVal = 0.01;
    this.opacityVar = 0.01 / 2;
  }

  draw() {
    ctx.beginPath();
    ctx.fillStyle = `rgba(${this.color}, ${this.colorOpacity})`;
    ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2);
    ctx.fill();

    this.update();
  }

  update() {
    // Flash colors based on opacity
    this.colorOpacity += this.opacityVar;
    if (this.colorOpacity >= 1 || this.colorOpacity <= 0.05) {
      this.opacityVar *= -1;
    }

    // Grow and shrink circles
    this.size += this.growVal;
    if (this.size >= maxCircleSize / 2 || this.size <= 0.1) {
      this.growVal *= -1;
    }
  }
}

let particlesArray = [];
let maxCircleSize = 8;

// Generate circles
function generateCirclesArray(circleSize) {
  // Draw a rows & columns of circles with spaces in between (space in size of 1 circle)
  for (let i = 0; i < canvasElm.height / circleSize / 4; i++) {
    // Top to bottom
    for (let j = 0; j < canvasElm.width / circleSize / 4; j++) {
      // Left to right
      particlesArray.push(
        new Particle(
          circleSize + circleSize * j * 4, // X
          circleSize + circleSize * i * 4, // Y
          0,
          0, // dx, dy
          randomBetween(0.5, circleSize / 2), // Size
          colors[Math.floor(Math.random() * colors.length)], // Color
          Math.random() * 1 // Opacity
        )
      );
    }
  }
}
generateCirclesArray(maxCircleSize);

// Resize canvas on window resize
window.addEventListener("resize", () => {
  canvasElm.height = window.innerHeight;
  canvasElm.width = window.innerWidth;
});

function animate() {
  ctx.clearRect(0, 0, canvasElm.width, canvasElm.height);

  for (let i = 0; i < particlesArray.length; i++) {
    particlesArray[i].draw();
  }
  requestAnimationFrame(animate);
}
animate();

              
            
!
999px

Console