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

              
                <div>
  <button id=makeCanvas>new canvas</button>
</div
              
            
!

CSS

              
                canvas {
  border: 1px solid green;
}
              
            
!

JS

              
                /**
* This example manages WebGL contexts so the browser limit is never reached.
* The limit is typically 16.
* 
* Creating a new canvas will set it's WebGL context active and disable all other contexts.
* Clicking a canvas will restore it's context and disable all others.
* 
* The loseContext API does not work in safari. The limit is still reached.
* Safari crashes after clicking around to restore context after the limit is reached.
*/

const canvasElements = [];
let activeCanvas = null;

function MakeCanvas() {
  this.canvas = document.body.appendChild(document.createElement('canvas'));
  this.gl = this.canvas.getContext('webgl');
  this.extension = this.gl.getExtension('WEBGL_lose_context');
  this.canvas.addEventListener('webglcontextlost', (e) => {
    e.preventDefault();
    console.log('context lost');
    this.canvas.style.border = '1px solid red';
  });
  this.canvas.addEventListener('webglcontextrestored', () => {
    console.log('context restored');
    this.canvas.style.border = '1px solid green';
  });
  this.canvas.addEventListener('click', () => {
    activeCanvas = this;
    disableContexts();
    if (this.gl.isContextLost()) {
      this.extension.restoreContext();
    }
  });
  return this;
}

function disableContexts() {
  canvasElements.forEach((canvasEl) => {
    if (canvasEl === activeCanvas) return;
    if (!canvasEl.gl.isContextLost()) {
      canvasEl.extension.loseContext();
    }
  });
}

function makeNewCanvasAndContext() {
  activeCanvas = new MakeCanvas();
  canvasElements.push(activeCanvas);
  disableContexts();
}

makeCanvas.addEventListener('click', makeNewCanvasAndContext);

makeNewCanvasAndContext();
makeNewCanvasAndContext();
makeNewCanvasAndContext();
              
            
!
999px

Console