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

              
                <h1>Progress bar</h1>
<h2>Javascript using SetInterval to increment the element's width</h2>

<div class="meter cadetblue">
  <span data-progress="12" style="width:0;"></span>
</div>

<div class="meter">
  <span data-progress="35" style="width:0;"></span>
</div>

<div class="meter orange">
  <span data-progress="62" style="width:0;"></span>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Roboto')
  
html {
  background-color #efefef
  -webkit-box-sizing border-box
  -moz-box-sizing border-box
  box-sizing border-box
  font-family 'Roboto', sans-serif
  letter-spacing 0.05rem
  word-spacing 0.05rem
}

*, *:before,
*:after {
  -webkit-box-sizing inherit
  -moz-box-sizing inherit
  box-sizing inherit
}

.meter {
  background #ccc
  -webkit-border-radius 25px
  -moz-border-radius 25px
  border-radius 25px
  box-shadow inset 0 -1px 1px rgba(255,255,255,0.3)
  display block
  height 35px
  margin-bottom 10px
  padding 8px
  position relative
  
  > span {
    display block
    height 100%
    border-top-right-radius 8px
    border-bottom-right-radius 8px
    border-top-left-radius 20px
    border-bottom-left-radius 20px
    background-color rgb(43,194,83)
    background-image linear-gradient(to top, rgb(43,194,83) 37%, rgb(84,240,84) 69%)
    box-shadow inset 0 2px 9px rgba(255,255,255,0.3) inset 0 -2px 6px rgba(0,0,0,0.4)
    position relative
    overflow hidden
    transition width 2s ease-out
  }
}

.orange {
  > span {
    background-color orangered
    background-image linear-gradient(to bottom, orange, orangered)
  }
}

.red {
  > span {
    background-color #f0a3a3
    background-image linear-gradient(to bottom, #f0a3a3, #f42323)
  }
}

.cadetblue {
  >span {
    background-color cadetblue
    background-image linear-gradient(to bottom, aqua, dodgerblue)
  }
}
              
            
!

JS

              
                var bars = document.querySelectorAll('.meter > span');
console.clear();

setInterval(function(){
  bars.forEach(function(bar){
    var getWidth = parseFloat(bar.dataset.progress);
    
    for(var i = 0; i < getWidth; i++) {
      bar.style.width = i + '%';
    }
  });
}, 500);

              
            
!
999px

Console