Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <img src="https://picsum.photos/id/75/200/200" class="center" alt="grap">
<img src="https://picsum.photos/id/102/200/200" class="vertical" alt="raspberry">
<img src="https://picsum.photos/id/248/200/200" class="horizontal" alt="cactus">
<img src="https://picsum.photos/id/1080/200/200" class="random" alt="strawberry">
              
            
!

CSS

              
                img {
  --s: 200px; /* the size need to match the intrinsic image size for "center" and "random" */
  
  width: var(--s);
  height: var(--s); /* better than aspect-ratio in case the image has a height attribute */
  box-sizing: border-box;
  cursor: pointer;
  transition: .5s;
}
img.center {
  object-fit: none; /* this is doing the magic, not a common value but it allows to keep the intrinsice size of the replaced content */
  padding: calc(var(--s)/2);
  background: #88C425;
}
img.vertical {
  object-fit: cover; /* we can also use "none" here, it will give the same result */
  padding-block: calc(var(--s)/2);
  background: #F07818;
}
img.horizontal {
  object-fit: cover;
  padding-inline: calc(var(--s)/2);
  background: #AB3E5B;
}
/* you can use any combination of padding. 
  make sure the padding will cover all the area
  also make sure to correctly set object-position and object-fit to create the illusion of a fixed image
  I may write a small article for it
*/
img.random {
  object-position: top left;
  object-fit: none;
  padding: 0 var(--s) var(--s) 0;
  background: #0E2430;
}

img:hover {
  padding: 0;
}


body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: auto auto;
  place-content: center;
  gap: 30px;
  background: #C6E5D9;
}
              
            
!

JS

              
                
              
            
!
999px

Console