Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <div class="equalizer">
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
  <div class="equalizer-bar">
    <span></span>
  </div>
</div>
<div class="song-info">
  <marquee>Currently playing: Awesome song - WebDEasy ft. codepen.io - Duration: Endless - File: 404 not found</marquee>
</div>
<footer>
  <p class="brand">coded by <a href="https://webdeasy.de/?referer=cp-PrmKbO" target="_blank">WebDEasy</a></p>
</footer>
              
            
!

CSS

              
                body {
  font-family: arial, sans-serif;
  background-color: #000;
  width: 100%;
  height: calc(100vh - 4rem);
  margin: 0;
}

.equalizer {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 10rem;
  margin-top: 4rem;
}

.equalizer-bar {
  width: 1.8rem;
  margin: 0 3px;
  display: flex;
  flex-direction: column-reverse;
  
  span {
    display: block;
    height: 4px;
    border-radius: 2px;
    width: 100%;
    margin: 2px 0;
    background-color: #FFF;
    transition: .2s ease all;
    opacity: 1;
  }
  
  &:nth-child(1) span {
    background: #fc0127;
  }
  
  &:nth-child(2) span {
    background: #fb0275;
  }
  
  &:nth-child(3) span {
    background: #b50cd3;
  }
  
  &:nth-child(4) span {
    background: #6407e9;
  }
  
  &:nth-child(5) span {
    background: #2a06a9;
  }
  
  &:nth-child(6) span {
    background: #080ad7;
  }
  
  &:nth-child(7) span {
    background: #0265e2;
  }
  
  &:nth-child(8) span {
    background: #03fcfc;
  }
  
  &:nth-child(9) span {
    background: #02fe46;
  }
  
  &:nth-child(10) span {
    background: #05fb0f;
  }
  
  &:nth-child(11) span {
    background: #97f611;
  }
  
  &:nth-child(12) span {
    background: #f5e506;
  }
  
  &:nth-child(13) span {
    background: #d7a414;
  }
  
  &:nth-child(14) span {
    background: #fc6b02;
  }
  
  &:nth-child(15) span {
    background: #df1506;
  }
  
}

.song-info {
  color: #FFF;
  width: 25rem;
  font-style: italic;
  font-size: 12px;
  margin: .5rem auto;
}

footer {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  
  .brand {
    color: #FFF;
    text-align: center;
    margin: 0;
    padding: 10px 0;
    opacity: .4;
    transition: .4s ease all;
    
    &:hover {
      opacity: 1;
    }
    
    a {
      text-decoration: none;
      color: #000;
      background-color: #FFF;
      padding: 5px 10px;
      font-weight: 600;
    }
  } 
}
              
            
!

JS

              
                const MAX_BAR_HEIGHT = 18;

addBarSpans();

setInterval(() => {
  setRandomBars();
}, 200);

// Main programm (repeats)
function setRandomBars(maxBarHeight) {
  const bars = document.getElementsByClassName('equalizer-bar');
  
  for(let i = 0; i < bars.length; i++) {
     
    let spans = bars[i].getElementsByTagName('span');
    let activeSpanCount = getActiveSpans(spans);
    let newHeight = getRandomHeight(MAX_BAR_HEIGHT);
    
    for(let j = 0; j < spans.length; j++) {
      
      if(newHeight > activeSpanCount) {
        spans[j].style.opacity = '1';
      } else if(j > newHeight) {        
        spans[j].style.opacity = '0';
      }
      
      // set little opacity
      let upperSpan = MAX_BAR_HEIGHT - j;
      if(newHeight > MAX_BAR_HEIGHT-5 && upperSpan < 5) {
        spans[j].style.opacity = '0.' + upperSpan;
      }
      
    }
  }
}

// Returns the number of active spans
function getActiveSpans(spans) {
  let counter = 0;
   
  for(let i = 0; i < spans.length; i++) {
    if(spans[i].style.opacity > 0) counter++;
  }
  
  return counter;
}

// Returns a random number between 1 and 20
function getRandomHeight(maxBarHeight) {
  return Math.round(Math.random() * (maxBarHeight - 1)) + 1;
}

// Add the default spans
function addBarSpans() {
  const bars = document.getElementsByClassName('equalizer-bar');
  
  let html = '';
  for(let j = 0; j < MAX_BAR_HEIGHT; j++) {
    html += '<span></span>';
  }  
  
  for(let i = 0; i < bars.length; i++) {
    bars[i].innerHTML = html;
  }
}
              
            
!
999px

Console