Pen Settings



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


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.


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.


                <button id="loader">Show New Post</button>

<section class="news-wrapper" id="news" aria-live="polite">
  <article class="news">
    <h2 class="news__title" id="title"></h2>
    <img class="news__artwork" id="artwork" src="" alt="" />
    <p class="news__content" id="content"></p>


                .news-wrapper {
  /* 1. Grid Layout */
  display: grid;
  grid-template: "content" 100% / auto;
  &::after {
    /* 3. Indicator Styles */
    content: "";
    margin: 3rem auto;
    width: 4rem;
    height: 4rem;
    display: block;
    grid-area: content;
    align-self: center;
    justify-self: center;
    border: .5rem solid blue;
    border-left-color: transparent;
    border-radius: 50%;
	  opacity: 0;
	  transition: opacity;
	  pointer-events: none;
    animation: loading-circle 1s ease-in-out infinite;
  &[aria-busy="true"] {
    .news {
      opacity: 0.2;
    &::after {
      opacity: 1;

.news {
  /* 2. Grid Positioning */
  grid-area: content;
  transition: opacity .1s;

@keyframes loading-circle {
  to {
    transform: rotate(360deg);

// Generic styles
html {
  background-color: #424242;

button {
  display: block;
  margin: 2rem auto;
  padding: 1rem 2rem 0.8rem;
  border: 0;
  border-radius: .5rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #fff;
  background: #00838F;
  box-shadow: 0 .25rem .5rem -.25rem #263238;
  &:focus {
    background: #0097A7;

.news-wrapper {
  margin: 2rem auto;
  padding: 1rem;
  width: 40rem;
  max-width: calc(100vw - 4rem);
  background-color: #eee;
  box-shadow: 0 .25rem .33rem 0 #263238;

.news__title {
  margin: 1rem 0;
  font-size: 2rem;

.news__artwork {
  width: 100%;
  height: auto;
  display: block;

.news__content {
  margin: 1rem 0;
  font-size: 1.5rem;


                const posts = [
    id: 1,
    title: 'A Good Article',
    artworkId: 38,
    content: 'This post will give you lots of information.'
    id: 2,
    title: 'Urgent Headline!',
    artworkId: 87,
    content: 'If you don’t read this now, you’ll miss out!'
    id: 3,
    title: 'Breaking News',
    artworkId: 67,
    content: 'No other outlet is reporting about this…'
    id: 4,
    title: 'Pleasant Article',
    artworkId: 11,
    content: 'This news is positive and won’t bum you out.'

const loader = document.getElementById('loader')
const news = document.getElementById('news')
const title = document.getElementById('title')
const artwork = document.getElementById('artwork')
const content = document.getElementById('content')

const loadContent = p => {
  title.innerHTML = p.title
  artwork.setAttribute('src', `${p.artworkId}/500/200`)
  content.innerHTML = p.content


loader.addEventListener('click', e => {
  news.setAttribute('aria-busy', true)
  setTimeout(() => {
    let currentId = parseInt(news.dataset.postId, 10)
    let differentPosts = posts.filter(p => !== currentId)
    console.log(currentId, differentPosts)
    loadContent(differentPosts[Math.floor(Math.random() * differentPosts.length)])
    news.setAttribute('aria-busy', false)
  }, 1500)