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.


                <h1>Select An Image to Resize 👇</h1>
  Once submitted, the image will be resized and displayed using only a
  few lines of JavaScript!

<form id="my-form" action="" method="post"r>
  <input type="file" name="photo" accept="image/*" required />
  <button type="submit">Resize Image</button>

<img id="img-preview" style="width:150px;">


                html {
  font-family: sans-serif;
  font-size: 15px;

body {
  padding: 0 1rem;
  max-width: 30rem;
  margin: 0 auto;

form {
  border: 1px solid #f5f5f5;
  padding: 1rem;

img {
  margin: 1rem 0;


                const form = document.querySelector('#my-form');

form.addEventListener('submit', async (e) => {
  // Get data URI of the selected image
  const formData = new FormData(e.currentTarget);
  const photoField = formData.get('photo');
  const dataUri = await dataUriFromFormField(photoField);
  const imgEl = document.createElement('img');
  imgEl.addEventListener('load', () => {
    const resizedDataUri = resizeImage(imgEl, 300);
    document.querySelector('#img-preview').src = resizedDataUri;
  imgEl.src = dataUri;

function dataUriFromFormField (field) {
  return new Promise((resolve) => {
    const reader = new FileReader();
    reader.addEventListener('load', () => {

function resizeImage (imgEl, wantedWidth) {
  const canvas = document.createElement('canvas');
  const ctx = canvas.getContext('2d');

  const aspect = imgEl.width / imgEl.height;

  canvas.width = wantedWidth;
  canvas.height = wantedWidth / aspect;

  ctx.drawImage(imgEl, 0, 0, canvas.width, canvas.height);
  return canvas.toDataURL();