cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <button class="btn js-btn">Give me a random Chuck Norris joke</button>
<main class="main js-main"></main>
<p class="loading js-loading">Loading…</p>
            
          
!
            
              * {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

.btn {
  margin: 1rem;
  width: calc(100vw - 2rem);
  height: 3rem;
  font: inherit;
  background-color: #AD1457;
  color: #fff;
  border: 0;
  border-radius: 4px;
}

.main {
  padding: 0 3rem;
  width: calc(100vw - 2rem);
  margin: 0 1rem;
  height: calc(100vh - 6rem);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px #AD1457;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 2rem;
  font-style: italic;
  font-weight: 300;
  color: #444;
  text-align: center;
}

.loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: none;
  justify-content: center;
  align-items: center;
  color: #fff;
  background: rgba(0,0,0,.9);
  font-size: 2rem;
  font-style: italic;
  font-weight: 300;
}

.loading--active {
  display: flex;
}
            
          
!
            
              // DOM references
const btn = document.querySelector('.js-btn');
const main = document.querySelector('.js-main');
const loading = document.querySelector('.js-loading');

const getRandomJoke = async () => {
  
  // show loading screen
  loading.classList.add('loading--active');
  
  try {
    const response = await fetch('https://api.icndb.com/jokes/random/1');
    const joke = await response.json();
    
    // print a joke
    main.innerHTML = joke.value[0].joke;
  }
  catch(err) {
    // print an error
    main.textContent = `Error: ${err}`;
  }
  finally {
    // hide loading screen
    loading.classList.remove('loading--active');
  }
}


btn.addEventListener('click', getRandomJoke);
            
          
!
999px
Loading ..................

Console