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

              
                <div id="particles">
</div>
              
            
!

CSS

              
                #particles {
  width: 100vw;
  height: 100vh;
  position: absolute;
  background-color: #333;
  position: relative;
  overflow: hidden;
}

.particle {
  background-color: #fff;
  width: 5px;
  height: 5px;
  position: absolute;
}
              
            
!

JS

              
                // DOM/CSS-only particle system
// try 1000, or 10000 and watch performance tank
const PARTICLE_COUNT = 1000;

const container = document.getElementById('particles');

// spawn particles
for(let i = 0; i < PARTICLE_COUNT; i++) {
  
  // create a particle
  let p = document.createElement('div');
  p.classList.add('particle');
  
  // set its initial position + speed
  p.userData = {} || p.userData;
  p.userData.vel = [Math.random()-.5, Math.random()-.5]; // random x/y velocity
  p.userData.pos = [window.innerWidth / 2, window.innerHeight / 2]; // start in the center
  
  // add it to the dom
  container.append(p);
}

// animation loop
const loop = (time) => {
  
  // loop over all particles
  for(let i = 0; i < container.children.length; i++) {

    // some shorthand local vars we'll use a lot
    let c = container.children[i];
    let d = c.userData;
    
    // skip children that aren't particles
    if(!c.classList.contains('particle')) continue;
    
    // update particle position
    d.pos[0] = d.pos[0] + d.vel[0];
    d.pos[1] = d.pos[1] + d.vel[1];
    
    // wrap around the browser window's width
    if(d.pos[0] >= window.innerWidth) d.pos[0] = 0;
    if(d.pos[0] < 0) d.pos[0] = window.innerWidth;
    // and its height
    if(d.pos[1] >= window.innerHeight) d.pos[1] = 0.
    if(d.pos[1] < 0) d.pos[1] = window.innerHeight;
    
    // update css transform with our new location
    c.style.transform = `translate3d(${d.pos[0]}px, ${d.pos[1]}px, 0px)`;
  }
  window.requestAnimationFrame(loop);
}

// make rocket go now
window.requestAnimationFrame(loop);
              
            
!
999px

Console