HTML <progress> class Attribute

The class attribute on a <progress> tag assigns one or more classnames to the progress element. Classes are used to style elements. Classnames are defined in a stylesheet or in a local <style> element.

Example

#

A class attribute styling a <progress> element.

Loading files...
50%
<style>
  .progress-class {width: 200px;height: 20px;}
</style>

<div>Loading files... </div>
<progress class="progress-class" value="50" max="100"> 50% </progress>

Using class

The class attribute assigns one or more classnames to the <progress> tag.

Multiple classnames are separated by a space.

Classes (i.e. classnames) are used for styling the progress element.

JavaScript uses classes to access one or more elements by classname.

Tip:  class is a global attribute that can be applied to any HTML element.


Syntax

<progress class="classnames">

Values

#

Value Description
classnames One or more space-separated class names.

More Examples

A class attribute styling a <progress> element.
Clicking the button toggles a classname that changes the width.

Loading files...
50%
<style>
  .progress-sm { width: 100px;height: 20px; }
  .progress-lg { width: 200px; }
</style>

<div>Loading files... </div>
<progress id="myprogress" class="progress-sm" value="50" max="100"> 50% </progress>

<br />
<button onclick="toggle();">Toggle class</button>

<script>
  let toggle = () => {
    let element = document.getElementById("myprogress");
    element.classList.toggle("progress-lg");
  }
</script>

Code explanation

Two CSS classes are defined in the <style> element.

The class attribute in <progress> assigns one classname.

Repeatedly clicking the button adds and removes the second class, toggling the width of the <progress>.


Browser support

Here is when class support started for each browser:

Chrome
8.0 Dec 2010
Firefox
16.0 Oct 2012
IE/Edge
10.0 Sep 2012
Opera
11.0 Dec 2010
Safari
6.0 Jul 2012

You may also like

 Back to <progress>
Guides