Pen Settings



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


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


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.


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.


                <div id="genwrap">
  <img crossorigin="anonymous" id="original" />


                body {margin:0;font-size:0}
img {width:50%;display:inline-block}




  const sizes = [
      'big-low-quality': {
        'format': 'webp',
        'quality': .50,
        'size': 2
      'small': {
        'format': 'webp',
        'quality': .82,
        'size': 1
      'small-hd': {
        'format': 'jpeg',
        'quality': .85,
        'size': 1

function waitForImage(imgElem) {
  return new Promise(res => {
    if (imgElem.complete) {
      return res();
    imgElem.onload = () => res();
    imgElem.onerror = () => res();

const convertImage = async (original, format = 'webp', quality = .20, size = 1) => {

  const canvas = document.createElement('canvas');
  const ctx = canvas.getContext('2d');

  // Use the intrinsic size of image in CSS pixels for the canvas element
  canvas.width = original.naturalWidth *size;
  canvas.height = original.naturalHeight *size;

  // To use the custom size we'll have to specify the scale parameters
  // using the element's width and height properties - lets draw one
  // on top in the corner:
  ctx.scale(size, size);
  ctx.drawImage(original, 0, 0);

  return canvas.toDataURL(`image/${format}`, quality);

(async () => {
  const screenWidth = Math.round(window.innerWidth * .5);

  const image = document.getElementById('original')
  image.src = `${screenWidth}x${screenWidth}/`;
  await waitForImage(image);

  sizes.forEach((size)=> {
    const options = Object.entries(size)[0][1];
    convertImage(image, options.format, options.quality, options.size)
      .then(imageSrc => {
        const generated = document.createElement("img"); = Object.keys(size)[0];
        generated.src = imageSrc;