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

              
                <img    sizes="(max-width: 320px) 320px, 
               (max-width: 640px) 640px, 
                                  1280px" 
     
       srcset="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/small.png  320w,
               https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/medium.png 640w,
               https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/large.png 1280w" 
       
          src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/large.png">
<hr>
<ol>
  <li>The browser will look at device width,</li>
  <li>work out which media condition in the sizes list is the first one to be true,</li>
  <li>look at the slot size given to that media query,</li>
  <li>load the image referenced in the srcset list that has the same size as the slot</li>
  <li>if there isn't one, the first image that is bigger than the chosen slot size.</li>
</ol>               
<hr>               
<ul>
  <li>Test this in Codepens Debug View, with Dev Tools Network tab open. Resize the viewport to 300px, then hit reload. Now scale the viewport larger to see the larger resolution images load. Scaling smaler again won't have an effect, as larger images are already loaded (<a href="https://twitter.com/kino_auge/status/1343196960392704000">watch screenrecording</a>).</li>
  <li>⚠ For the slot width, you may provide an absolute length (px, em) or a length relative to the viewport (vw), but <strong>not percentages.</strong> </li>
  <li><a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Multimedia_and_embedding/Responsive_images#Resolution_switching_Different_sizes">MDN: Responsive images</a></li>
  <li><a href="https://web.dev/use-srcset-to-automatically-choose-the-right-image/">Web.dev: Use srcset to automatically choose the right image size</a></li>
</ul>
              
            
!

CSS

              
                body {
  font-family:system-ui;
}
a {
  color: unset;
}
li {
  margin-bottom: .5em;
}
img {
  max-width: 100%;
}

              
            
!

JS

              
                
              
            
!
999px

Console