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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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 id="canvas" width="500" height="500"></canvas>

<script id="vertexShader" type="x-shader/x-vertex">
  #version 300 es

  in vec4 vertexPosition;

  void main() {
    gl_Position = vertexPosition;
  }
</script>

<script id="fragmentShader" type="x-shader/x-fragment">
  #version 300 es
  precision highp float;

  out vec4 fragColor;

  void main() {
    fragColor = vec4(1, 0, 0, 1);
  }
</script>
              
            
!

CSS

              
                body {
  text-align: center;
}
canvas {
  max-width: 100vw; 
  max-height: 100vh;
}
              
            
!

JS

              
                // Requires a WebGL2-compatible browser: https://caniuse.com/?search=webgl2
// Confirm your compatibility: https://get.webgl.org/webgl2/
// Older versions of Safari (iOS/MacOS) may need to enable WebGL2 under "Experimental Features"

// More WebGL2 demos: https://codepen.io/collection/aMoEeq

const gl = canvas.getContext("webgl2");
if (!gl) throw "WebGL2 not supported";

// Creating the two shaders is repetitive and will be refactored 
// into a createShader() function in the next demo:
const vs = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vs, vertexShader.textContent.trim());
gl.compileShader(vs);
if (!gl.getShaderParameter(vs, gl.COMPILE_STATUS)) {
  throw gl.getShaderInfoLog(vs);
}

const fs = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fs, fragmentShader.textContent.trim());
gl.compileShader(fs);
if (!gl.getShaderParameter(fs, gl.COMPILE_STATUS)) {
  throw gl.getShaderInfoLog(fs);
}

const program = gl.createProgram();
gl.attachShader(program, vs);
gl.attachShader(program, fs);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
  throw gl.getProgramInfoLog(program);
}
gl.useProgram(program);

const vertices = [
  [-1, -1, 0],
  [1, -1, 0],
  [1, 1, 0],
];
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices.flat()), gl.STATIC_DRAW);

const vertexPosition = gl.getAttribLocation(program, "vertexPosition");
gl.enableVertexAttribArray(vertexPosition);
gl.vertexAttribPointer(vertexPosition, 3, gl.FLOAT, false, 0, 0);

gl.drawArrays(gl.TRIANGLES, 0, vertices.length);
              
            
!
999px

Console