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 id="card-container"></div>

<!-- CARD TEMPLATE -->
<template id="card-template">
  <div class="card">
    <h1></h1>
    <p class="description"></p>
    <img />
  </div>
</template>
              
            
!

CSS

              
                /* https://www.joshwcomeau.com/shadow-palette/ */
:root {
  --shadow-color: 51deg 100% 29%;
  --shadow-elevation-low:
    0.3px 0.5px 0.7px hsl(var(--shadow-color) / 0.34),
    0.4px 0.8px 1px -1.2px hsl(var(--shadow-color) / 0.34),
    1px 2px 2.5px -2.5px hsl(var(--shadow-color) / 0.34);
  --shadow-elevation-medium:
    0.3px 0.5px 0.7px hsl(var(--shadow-color) / 0.36),
    0.8px 1.6px 2px -0.8px hsl(var(--shadow-color) / 0.36),
    2.1px 4.1px 5.2px -1.7px hsl(var(--shadow-color) / 0.36),
    5px 10px 12.6px -2.5px hsl(var(--shadow-color) / 0.36);
  --shadow-elevation-high:
    0.3px 0.5px 0.7px hsl(var(--shadow-color) / 0.34),
    1.5px 2.9px 3.7px -0.4px hsl(var(--shadow-color) / 0.34),
    2.7px 5.4px 6.8px -0.7px hsl(var(--shadow-color) / 0.34),
    4.5px 8.9px 11.2px -1.1px hsl(var(--shadow-color) / 0.34),
    7.1px 14.3px 18px -1.4px hsl(var(--shadow-color) / 0.34),
    11.2px 22.3px 28.1px -1.8px hsl(var(--shadow-color) / 0.34),
    17px 33.9px 42.7px -2.1px hsl(var(--shadow-color) / 0.34),
    25px 50px 62.9px -2.5px hsl(var(--shadow-color) / 0.34);
}

body {
  align-items: center;
  background-color: gold;
  display: flex;
  font-family: 'Barlow', sans-serif;
  height: 100vh;
  justify-content: center;
  margin: 0; 
}

#card-container {
  display: flex;
}

.card {
  background-color: white;
  border-radius: 4px;
  box-shadow: var(--shadow-elevation-medium);
  margin: 16px;
  padding: 16px;
}

.card h1 {
  font-size: 24px;
  margin: 0 0 4px 0;
}

.card p {
  font-size: 16px;
  margin: 0 0 16px 0;
}
              
            
!

JS

              
                const cloneTemplate = (id) => {
  let template = document.getElementById(id);
  let clone = template.content.cloneNode(true);
  return clone;
};

const createCard = (data) => {
  let cardTemplate = cloneTemplate('card-template');
  let card = cardTemplate.querySelector('.card');
  
  card.querySelector('h1').innerHTML = data.title;
  card.querySelector('.description').innerHTML = data.description;
  card.querySelector('img').src = data.imagePath;
	
  return card;
}

// This is an additional method to loop over our data
const createCards = (data) => {
  let cardContainer = document.getElementById('card-container');
  
  data.forEach(function (item) {
    let card = createCard(item);
    cardContainer.appendChild(card);
  });
}

// You can continue to add more data here to create more cards
let data = [
  {
    "title": "An Example",
    "description": "This is just some example data.",
    "imagePath": "https://picsum.photos/id/237/300/200"
  },
  {
    "title": "A Second Example",
    "description": "This is some more example data.",
    "imagePath": "https://picsum.photos/id/14/300/200"
  }
]

createCards(data);
              
            
!
999px

Console