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

              
                <div class="card-container">
  
  <div class="card">
    <div class="card-content">
      Some snazzy content
    </div>
    <div class="card-controls">
      <button class="card-control increase">Increase font</button>
      <button class="card-control decrease">Decrease font</button>
    </div>
  </div>
  
  <div class="card">
    <div class="card-content">
      🐌🪨🌱
    </div>
    <div class="card-controls">
      <button class="card-control increase">Increase font</button>
      <button class="card-control decrease">Decrease font</button>
    </div>
  </div>

  <div class="card">
    <div class="card-content">
      More content
    </div>
    <div class="card-controls">
      <button class="card-control increase">Increase font</button>
      <button class="card-control decrease">Decrease font</button>
    </div>
  </div>
  
</div>
              
            
!

CSS

              
                /* Hide card controls by default */
.card-controls {
  opacity: 0;
}
  
/* Show card controls when hovering on card, OR when card contains a focused element */
.card:hover .card-controls,
.card:focus-within .card-controls {
   opacity: 1;
}
  
/* Hover styles for the individual buttons */
.card-control:hover,
.card-control:focus {
  background: rgba(0 0 0 / 0.8);
  color: white;
}

/* 
 * Presentational styles!
 *
 * Nothing beyond this point changes between the examples, or 
 * affects the hover/focus styles covered in this blog post.
 */
.card-container {
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
  gap: 1rem;
}

.card {
  --card-font-size: 2rem;
  
  display: grid;
  grid-template-areas: "card";
  
  width: var(--card-size, 200px);
  height: var(--card-size, 200px);
  
  border: 1px dashed black;
  
  cursor: default;
}

.card-content {
  grid-area: card;
  place-self: center; 
  max-width: 100%;
  max-height: 100%;
  
  font-family: sans-serif;
  font-size: var(--card-font-size, 2rem);
  text-align: center;
  
  overflow: hidden;
}

.card-controls {
  grid-area: card;
  align-self: end;
  
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  height: 33%;
  border-top: 1px dashed black;
}
  
.card-control {
  background: rgba(255 255 255 / 0.95);
  font-size: 1.1rem;
  color: black;
  border: none;
  cursor: pointer;
}
    
.card-control + .card-control{
  border-left: 1px dashed black;
}

              
            
!

JS

              
                        const getFontSize = card => {
      const fontSize = getComputedStyle(card).getPropertyValue('--card-font-size') || '1rem'
      return parseFloat(fontSize)
    }

    const setFontSize = (card, fontSize) => {
      card.style.setProperty('--card-font-size', `${fontSize}rem`)
    }

    const scalingFactor = 1.1;

    const cards = document.querySelectorAll('.card')

    cards.forEach(card => {
      const increaseButton = card.querySelector('.card-control.increase')

      increaseButton.addEventListener('click', e => {
        const fontSize = getFontSize(card)
        setFontSize(card, fontSize * scalingFactor)
      })

      const decreaseButton = card.querySelector('.card-control.decrease')

      decreaseButton.addEventListener('click', e => {
        const fontSize = getFontSize(card)
        setFontSize(card, fontSize / scalingFactor)
      })
    })

              
            
!
999px

Console