Pen Settings



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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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.


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.


                <div class="gallery"></div>
<button class="load-users-button">Fetch a random user!</button>


                body {
  margin: 0;
  font-family: sans-serif;

.gallery {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  max-width: 40rem;
  margin: 0 auto;
  padding: 2rem 1rem 0;

.user {
  display: flex;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
  max-width: calc(50% - 1rem);
  margin-bottom: 2rem;
  padding: 2%;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .1);
  animation: fadeIn 200ms forwards;
  opacity: 0;

.user__avatar {
  width: 35%;
  margin-right: 4%;
  height: auto;
  border-radius: 50%;

.user__name {
  text-transform: capitalize;
  font-size: 1.25rem;
  text-overflow: ellipsis;
  overflow: hidden;

@media screen and (max-width: 650px) {
  .user__name {
    font-size: .875rem;

@keyframes fadeIn {
  to {
    opacity: 1;

button {
  display: block;
  margin: 0 auto 2rem;
  border: 0;
  padding: .75em 1.5em;
  font-family: sans-serif;
  font-size: inherit;
  color: #fff;
  border-radius: .2em;
  background: #7586e3;
  cursor: pointer;

button[disabled] {
  opacity: .5;
  pointer-events: none;


                const gallery = document.querySelector('.gallery');
const loadUserButton = document.querySelector('.load-users-button');

// Preload images
async function loadImage(imageUrl) {
  return new Promise((resolve, reject) => {
    const newImage = new Image();
    newImage.addEventListener('load', () => {
    newImage.src = imageUrl;

// Load user data with fetch
async function loadUserData() {
  const imgElement = document.createElement('img');
  const userRequest = await fetch('');
  const userData = (await userRequest.json()).results[0];
  const userImage = await loadImage(userData.picture.large);
  return {
    name: `${} ${}`,
    image: userImage

// Add user with received data
async function loadUser() {
  loadUserButton.setAttribute('disabled', true);

  const data = await loadUserData();
  const userEl = document.createElement('div');
  const userAvatarEl = document.createElement('img');
  const userNameEl = document.createElement('div');
  userAvatarEl.src = data.image;
  userNameEl.textContent =;

loadUserButton.addEventListener('click', loadUser);