Categories
Bootstrap HTML

Bootstrap 5 — Lists and Images

Bootstrap 5 is in alpha when this is written and it’s subject to change.

Bootstrap is a popular UI library for any JavaScript apps.

In this article, we’ll look at how to style lists and images with Bootstrap 5.

Lists

Bootstrap 5 removes the default list-style and left margin of list items.

This only applies to immediate children list items.

The class has to be added to nested lists.

For example, we can wire:

`<ul class="list-unstyled">  
  <li>Lorem ipsum dolor sit amet</li>  
  <li>`Duis id nunc dignissim`</li>  
  <li>Nulla volutpat aliquam velit  
    <ul>  
      <li>Phasellus iaculis neque</li>  
      <li>` Suspendisse potenti. Aliquam erat volutpat.`</li>  
    </ul>  
  </li>  
  <li>`Pellentesque habitant morbi tristique senectus`</li>  
  <li>Aenean sit amet erat nunc</li>  
  <li>Eget porttitor lorem</li>  
</ul>`

to add a nested list.

We added the list-unstyled class to add an unstyled list.

Inline

We can remove a list’s bullets and apply some light margin with the combination of the .list-inline and .list-inline-item classes:

`<ul class="list-inline">  
  <li class="list-inline-item">`Lorem ipsum dolor sit amet, consectetur adipiscing elit.`</li>  
  <li class="list-inline-item">`Pellentesque quis nunc ultricies enim ullamcorper pretium at cursus tellus.`</li>  
  <li class="list-inline-item">` Ut convallis quis lacus in volutpat. Pellentesque volutpat dui et enim mattis`</li>  
</ul>`

We add the classes to make the items display inline with margins.

Description List Alignment

To make a list with description, we can use the dl , dt , and dd tags with the width styles.

For example, we can write:

`<dl class="row">  
  <dt class="col-sm-3">Description lists</dt>  
  <dd class="col-sm-9">A description list is perfect for defining terms.</dd>  
  
  <dt class="col-sm-3">Euismod</dt>  
  <dd class="col-sm-9">  
    <p>`Lorem ipsum dolor sit amet, consectetur adipiscing elit.`</p>  
    <p>`ellentesque quis nunc ultricies enim ullamcorper pretium at cursus tellus. Curabitur sit amet leo arcu. Integer vitae tincidunt odio. Duis id nunc dignissim.`</p>  
  </dd>  
  
  <dt class="col-sm-3">`Maecenas imperdiet sapien augue, ac malesuada metus ultrices et.`</dt>  
  <dd class="col-sm-9">`Aliquam erat volutpat. Quisque rutrum commodo felis imperdiet fermentum. Integer hendrerit dictum augue dapibus semper. In ac nisi consectetur`.</dd>  
  
  <dt class="col-sm-3 text-truncate">Truncated term is truncated</dt>  
  <dd class="col-sm-9">`Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.`</dd>  
  
  <dt class="col-sm-3">Nesting</dt>  
  <dd class="col-sm-9">  
    <dl class="row">  
      <dt class="col-sm-4">Nested definition list</dt>  
      <dd class="col-sm-8">`Aenean dolor augue, vulputate non mattis eu, lacinia viverra ex.`</dd>  
    </dl>  
  </dd>  
</dl>`

We have the list with the dt and dd tags with the column classes to set the width of them.

Images

We can add responsive images with the img element and the .img-fluid class.

For example, we can write:

`<img src="`http://placekitten.com/200/200`" class="img-fluid" alt="cat">`

Image Thumbnails

To add thumbnails, we use the .img-thumbnail class:

`<img src="`http://placekitten.com/200/200`" class="img-thumbnail" alt="cat">`

Aligning Images

We can align images with the float-left or float-right classes:

<img src="http://placekitten.com/200/200" class="rounded float-left" alt="cat">  
<img src="http://placekitten.com/200/200" class="rounded float-right" alt="cat">

To make it aligned centered horizontally, we can write:

`<img src="`http://placekitten.com/200/200`" class="rounded mx-auto d-block" alt="cat">`

We used the mx-auto class to make the image centered.

Also, we can use the text-center class to do the same thing:

<div class="text-center">  
  <img src="http://placekitten.com/200/200" class="rounded" alt="cat">  
</div>

Picture

The picture element can be used to specify multiple sources of images.

So we can write:

`​<picture>  
  <img src="`http://placekitten.com/200/200`" class="img-fluid img-thumbnail" alt="cat 1">  
  <img src="`http://placekitten.com/201/201`" class="img-fluid img-thumbnail" alt="cat 2">  
</picture>`

We put the img elements in the picture tags.

And we’ve to add the img-* classes ion the img tag rather than the picture tag.

Conclusion

We can style lists and images with Bootstrap 5.

It comes with the classes for us to do so.

Categories
Bootstrap HTML

Bootstrap 5 — Form Fields

Bootstrap 5 is in alpha when this is written and it’s subject to change.

Bootstrap is a popular UI library for any JavaScript apps.

In this article, we’ll look at how to style form fields with Bootstrap 5.

Color Picker

We can add a color picker with the type attribute set to color .

For example, we can write:

<div class="mb-3">
  <label for="color-input" class="form-label">Color picker</label>
  <input type="color" class="form-control form-control-color" id="color-input" value="#563d7c" title="Choose your color">
</div>

to add a color picker to our app.

We add the .form-control and .form-control-color to add the Bootstrap styles for the color picker.

Datalists

Bootstrap 5 has styles for data lists.

A datalist lets us enter options and if there’s a match, we can select it.

To add one, we can write:

<div class="mb-3">
  <label for="exampleDataList" class="form-label">Fruit</label>
  <input class="form-control" list="datalistOptions" id="exampleDataList" placeholder="Type to search...">
  <datalist id="datalistOptions">
    <option value="apple">
    <option value="orange">
    <option value="lemon">
    <option value="pear">
    <option value="grape">
  </datalist>
</div>

to add a data list input with a datalist with a bunch of options that we can choose from.

Bootstrap 5 provides consistent styling with the form-control class.

Select

We can style select elements with Bootstrap.

To style it, we can use the .form-select class.

For example, we can write:

<select class="form-select">
  <option selected>select a fruit</option>
  <option value="1">apple</option>
  <option value="2">orange</option>
  <option value="3">grape</option>
</select>

to create a drop-down with Bootstrap styles.

Dropdown Sizing

The size of a dropdown can be changed with Bootstrap classes.

We can use the form-select-lg to make it large and form-select-sm to make it small.

For example, we can write:

<select class="form-select form-select-lg">
  <option selected>select a fruit</option>
  <option value="1">apple</option>
  <option value="2">orange</option>
  <option value="3">grape</option>
</select>

to make the dropdown large and:

<select class="form-select form-select-sm">
  <option selected>select a fruit</option>
  <option value="1">apple</option>
  <option value="2">orange</option>
  <option value="3">grape</option>
</select>

to make it small.

The multiple attribute is also supported by Bootstrap:

<select class="form-select" multiple>
  <option selected>select a fruit</option>
  <option value="1">apple</option>
  <option value="2">orange</option>
  <option value="3">grape</option>
</select>

The size attribute can be adjusted to only display the given number of items at once:

<select class="form-select" size='3' multiple>
  <option selected>select a fruit</option>
  <option value="1">apple</option>
  <option value="2">orange</option>
  <option value="3">grape</option>
</select>

Checkboxes

Bootstrap 5 provides classes to let us add consistent styles for checkboxes.

To do that, we can use the .form-check class that improves the layout and behavior of the element.

For example, we can write:

<div class="form-check">
  <input class="form-check-input" type="checkbox" value="" id="apple">
  <label class="form-check-label" for="apple">
    apple
  </label>
</div>
<div class="form-check">
  <input class="form-check-input" type="checkbox" value="" id="orange" checked>
  <label class="form-check-label" for="orange">
    orange
  </label>
</div>

to add the checkboxes.

We have a div with the .form-check class.

Inside it, we add the input with type checkbox to add the checkbox.

They’re styles with the .form-check-input class.

To add a label, we can add the .form-check-label class to add the text beside the checkbox.

Indeterminate

We can use JavaScript to set the :indeterminate pseudoclass to make an indeterminate checkbox.

For example, we can write:

<div class="form-check">
  <input class="form-check-input" type="checkbox" value="" id="flexCheckIndeterminate">
  <label class="form-check-label" for="flexCheckIndeterminate">
    Indeterminate checkbox
  </label>
</div>

in our HTML code and then add:

document.getElementById("flexCheckIndeterminate").indeterminate = true;

in our JavaScript to make an indeterminate checkbox.

Disabled

We can make a checkbox disabled with the disabled attribute.

For example, we can write:

<div class="form-check">
  <input class="form-check-input" type="checkbox" value="" id="apple" disabled>
  <label class="form-check-label" for="apple">
    apple
  </label>
</div>

<div class="form-check">
  <input class="form-check-input" type="checkbox" value="" id="orange" checked disabled>
  <label class="form-check-label" for="orange">
    orange
  </label>
</div>

We added 2 checkboxes with the disabled attribute to disable them.

checked makes it checked.

Conclusion

We can add datalists, color pickers, and checkboxes to our app.

Boottstrap 5 provides all the styles.

Categories
Bootstrap HTML

Bootstrap 5 — Spinners

Bootstrap 5 is in alpha when this is written and it’s subject to change.

Bootstrap is a popular UI library for any JavaScript apps.

In this article, we’ll look at how to add spinners with Bootstrap 5.

Spinners

Spinners lets us add the loading state of a component or page with Bootstrap spinners.

It doesn’t use JavaScript to implement it.

Border Spinner

We can add a border spinner with the spinner-border class:

<div class="spinner-border">  
  <span class="sr-only">Loading...</span>  
</div>

We added the spinner-border class and the span with the sr-only class for screen readers.

Colors

We can apply different colors to spinners.

For example, we can write:

<div class="spinner-border text-primary">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-border text-secondary">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-border text-success">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-border text-danger">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-border text-warning">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-border text-info">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-border text-light">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-border text-dark">  
  <span class="sr-only">Loading...</span>  
</div>

We add text-* classes to add the colors to the spinner.

Growing Spinner

We can add a growing spinner with the spinner-grow class.

For example, we can write:

<div class="spinner-grow">  
  <span class="sr-only">Loading...</span>  
</div>

We can also change the color with various classes:

<div class="spinner-grow text-primary">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-grow text-secondary">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-grow text-success">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-grow text-danger">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-grow text-warning">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-grow text-info">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-grow text-light">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-grow text-dark">  
  <span class="sr-only">Loading...</span>  
</div>

Alignment

We can change the alignment of the spinner.

For instance, we can add margins to them:

<div class="spinner-border m-5">  
  <span class="sr-only">Loading...</span>  
</div>

The placement can be set with the justify-content-* classes:

<div class="d-flex justify-content-center">  
  <div class="spinner-border">  
    <span class="sr-only">Loading...</span>  
  </div>  
</div>

We can also have floats:

<div class="clearfix">  
  <div class="spinner-border float-right">  
    <span class="sr-only">Loading...</span>  
  </div>  
</div>

float-right puts the spinner on the right.

We can also set text-align :

<div class="text-center">  
  <div class="spinner-border">  
    <span class="sr-only">Loading...</span>  
  </div>  
</div>

Size

We can change the size of the spinner.

We can add the spinner-border-sm or spinner-grow-sm classes to make a smaller spinner:

<div class="spinner-border spinner-border-sm">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-grow spinner-grow-sm">  
  <span class="sr-only">Loading...</span>  
</div>

We can also change the size:

<div class="spinner-border" style="width: 5rem; height: 5rem;">  
  <span class="sr-only">Loading...</span>  
</div>  
<div class="spinner-grow" style="width: 5rem; height: 5rem;">  
  <span class="sr-only">Loading...</span>  
</div>

Buttons

We can add spinners to buttons.

For example, we can write:

<button class="btn btn-primary" type="button" disabled>  
  <span class="spinner-border spinner-border-sm"></span>  
  <span class="sr-only">Loading...</span>  
</button>  
<button class="btn btn-primary" type="button" disabled>  
  <span class="spinner-border spinner-border-sm"></span>  
  Loading...  
</button>

We add the spinner so inside the button and it’ll be displayed.

Also, we can do the same with the growing spinner:

<button class="btn btn-primary" type="button" disabled>  
  <span class="spinner-grow spinner-grow-sm"></span>  
  <span class="sr-only">Loading...</span>  
</button>  
<button class="btn btn-primary" type="button" disabled>  
  <span class="spinner-grow spinner-grow-sm"></span>  
  Loading...  
</button>

Conclusion

We can add spinners to display loading progress.

It’s implemented with HTML and CSS only so JavaScript isn’t required.

Categories
Bootstrap HTML

Bootstrap 5 — Scrollspy

Bootstrap 5 is in alpha when this is written and it’s subject to change.

Bootstrap is a popular UI library for any JavaScript apps.

In this article, we’ll look at how to add scrollspys with Bootstrap 5.

Scrollspy

Scrollspy lets us highlight links given that the content container has the same ID assigned to it.

It must be used with a Bootstrap nav component or list group.

Scrollspy needs to be position: relative on the element, we’re spying on.

If we spy on anything other than the body, we’ve to set the overflow-y to scroll .

For example, we can write:

<nav id="navbar-example" class="navbar navbar-light bg-light px-3">
  <a class="navbar-brand" href="#">Navbar</a>
  <ul class="nav nav-pills">
    <li class="nav-item">
      <a class="nav-link" href="#foo">foo</a>
    </li>
    <li class="nav-item">
      <a class="nav-link" href="#bar">bar</a>
    </li>
    <li class="nav-item dropdown">
      <a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">Dropdown</a>
      <ul class="dropdown-menu dropdown-menu-right">
        <li><a class="dropdown-item" href="#one">one</a></li>
        <li><a class="dropdown-item" href="#two">two</a></li>
        <li>
          <hr class="dropdown-divider">
        </li>
        <li><a class="dropdown-item" href="#three">three</a></li>
      </ul>
    </li>
  </ul>
</nav>
<div data-spy="scroll" data-target="#navbar-example" data-offset="0" style='max-height: 100px; overflow: auto'>
  <h4 id="foo">@foo</h4>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci.
  </p>
  <h4 id="bar">@bar</h4>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci.
  </p>
  <h4 id="one">one</h4>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci.
  </p>
  <h4 id="two">two</h4>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci.
  </p>
  <h4 id="three">three</h4>
  <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci.
  </p>
</div>

We have a navbar with the content.

And we styled it as usual.

What we added is the href to the links and the IDs to the div.

If they match, then we can scroll to the item.

Also, we set the max-height to 100px and overflow to auto so that we see overflow content.

To add the scrollspy, we have the data-spy='scroll' attribute in our container div for the content.

With Nested Nav

We can use the scrollspy with nested navs.

For example, we can write:

<div class='row'>
  <div class='col-3'>
    <nav id="navbar-example" class="navbar navbar-light bg-light">
      <a class="navbar-brand" href="#">Navbar</a>
      <nav class="nav nav-pills flex-column">
        <a class="nav-link" href="#item-1">Item 1</a>
        <nav class="nav nav-pills flex-column">
          <a class="nav-link ml-3 my-1" href="#item-1-1">Item 1-1</a>
          <a class="nav-link ml-3 my-1" href="#item-1-2">Item 1-2</a>
        </nav>
        <a class="nav-link" href="#item-2">Item 2</a>
        <a class="nav-link" href="#item-3">Item 3</a>
        <nav class="nav nav-pills flex-column">
          <a class="nav-link ml-3 my-1" href="#item-3-1">Item 3-1</a>
          <a class="nav-link ml-3 my-1" href="#item-3-2">Item 3-2</a>
        </nav>
      </nav>
    </nav>
  </div>

<div data-spy="scroll" data-target="#navbar-example" data-offset="0" class='col-9' style='max-height: 300px; overflow-y: scroll'>
    <h4 id="item-1">Item 1</h4>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci. Sed iaculis diam sit amet massa pulvinar, dictum viverra felis interdum. </p>
    <h5 id="item-1-1">Item 1-1</h5>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci. Sed iaculis diam sit amet massa pulvinar, dictum viverra felis interdum. </p>
    <h5 id="item-1-2">Item 1-2</h5>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci. Sed iaculis diam sit amet massa pulvinar, dictum viverra felis interdum. </p>
    <h4 id="item-2">Item 2</h4>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci. Sed iaculis diam sit amet massa pulvinar, dictum viverra felis interdum. </p>
    <h4 id="item-3">Item 3</h4>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci. Sed iaculis diam sit amet massa pulvinar, dictum viverra felis interdum. </p>
    <h5 id="item-3-1">Item 3-1</h5>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci. Sed iaculis diam sit amet massa pulvinar, dictum viverra felis interdum. </p>
    <h5 id="item-3-2">Item 3-2</h5>
    <p>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent tempus turpis augue, aliquam egestas nunc semper sit amet. Vivamus vel euismod eros. Fusce aliquam vitae nisi quis suscipit. Nullam rutrum convallis dui, a pharetra nulla dapibus eget. In diam justo, finibus in commodo fermentum, maximus sit amet tellus. Vestibulum metus mi, tempus ut sapien at, vestibulum blandit orci. Sed iaculis diam sit amet massa pulvinar, dictum viverra felis interdum. </p>
  </div>
</div>

We have the nav that’s vertical.

Also, we have navs inside some of the navs.

Like the previous example, we have the data-spy='scroll' and the href in the navs matching the IDs of the divs.

overflow-y has to be set to scroll so that we scroll.

Conclusion

We can add scrollspys with the data-spy='scroll' attribute and set the overflow on the content we’re scrolling.

Categories
Bootstrap HTML

Bootstrap 5 — Progress Bar

Bootstrap 5 is in alpha when this is written and it’s subject to change.

Bootstrap is a popular UI library for any JavaScript apps.

In this article, we’ll look at how to add progress bars with Bootstrap 5.

Progress Bar

Bootstrap 5 comes with its own progress bar styles.

We can use them in our app.

To use it, we use the progress class as the wrapper to indicate the max value of the progress.

The progress-bar class indicates the progress so far.

It requires an inline style, utility class, or custom CSS to set the width.

For example, we can write:

<div class="progress">
  <div class="progress-bar"></div>
</div>
<div class="progress">
  <div class="progress-bar" style="width: 20%"></div>
</div>
<div class="progress">
  <div class="progress-bar" style="width: 40%"></div>
</div>
<div class="progress">
  <div class="progress-bar" style="width: 60%"></div>
</div>
<div class="progress">
  <div class="progress-bar" style="width: 80%"></div>
</div>
<div class="progress">
  <div class="progress-bar" style="width: 100%"></div>
</div>

We add progress bar with various amount of it filled with the progress and progress-bar classes.

The progress-bar display a bar for the progress. We set the width style to adjust how much of it is filled.

Alternatively, we can use the width utility classes to set the width.

For instance, we can write:

<div class="progress">
  <div class="progress-bar"></div>
</div>
<div class="progress">
  <div class="progress-bar w-25"></div>
</div>
<div class="progress">
  <div class="progress-bar w-50"></div>
</div>
<div class="progress">
  <div class="progress-bar w-75"></div>
</div>
<div class="progress">
  <div class="progress-bar w-100"></div>
</div>

We use the w-* classes to set the width of the progress bar.

Labels

We can add labels inside the progress bar.

For example, we can write:

<div class="progress">
  <div class="progress-bar"></div>
</div>
<div class="progress">
  <div class="progress-bar w-25">25%</div>
</div>
<div class="progress">
  <div class="progress-bar w-50">50%</div>
</div>
<div class="progress">
  <div class="progress-bar w-75">75%</div>
</div>
<div class="progress">
  <div class="progress-bar w-100">100%</div>
</div>

to display the progress with text inside the bar.

Height

We can set the height style on the element with the progress class.

For example, we can write:

<div class="progress" style="height: 20px;">
  <div class="progress-bar"></div>
</div>
<div class="progress" style="height: 20px;">
  <div class="progress-bar w-25">25%</div>
</div>
<div class="progress" style="height: 20px;">
  <div class="progress-bar w-50">50%</div>
</div>
<div class="progress" style="height: 20px;">
  <div class="progress-bar w-75">75%</div>
</div>
<div class="progress" style="height: 20px;">
  <div class="progress-bar w-100">100%</div>
</div>

Now the height of each bar is 20px high.

Backgrounds

We can use Bootstrap 5 classes to change the background styles.

For example, we can write:

<div class="progress">
  <div class="progress-bar bg-success"></div>
</div>
<div class="progress">
  <div class="progress-bar w-25 bg-info"></div>
</div>
<div class="progress">
  <div class="progress-bar w-50 bg-warning"></div>
</div>
<div class="progress">
  <div class="progress-bar w-75 bg-danger"></div>
</div>
<div class="progress">
  <div class="progress-bar w-100 bg-secondary"></div>
</div>

to change the styles.

Multiple Bars

We can have multiple bars within one progress bar container.

For example, we can write:

<div class="progress">
  <div class="progress-bar" style="width: 15%"></div>
  <div class="progress-bar bg-success" style="width: 35%"></div>
  <div class="progress-bar bg-info" style="width: 20%"></div>
</div>

We set the width style to set the bar of the width.

They’ll automatically be placed side by side.

Striped

Progress bars can have stripes.

To add them, we add the progress-bar-striped class:

<div class="progress">
  <div class="progress-bar progress-bar-striped" style="width: 10%"></div>
</div>

<div class="progress">
  <div class="progress-bar progress-bar-striped bg-success" style="width: 20%"></div>
</div>

<div class="progress">
  <div class="progress-bar progress-bar-striped bg-info" style="width: 40%"></div>
</div>

<div class="progress">
  <div class="progress-bar progress-bar-striped bg-warning" style="width: 60%" a></div>
</div>

<div class="progress">
  <div class="progress-bar progress-bar-striped bg-secondary" style="width: 80%" a></div>
</div>

<div class="progress">
  <div class="progress-bar progress-bar-striped bg-danger" style="width: 100%"></div>
</div>

We added progress bars with various styles.

They all have the progress-bar-striped class to add the stripes to the filled part of the progress bar.

Animated Stripes

The stripes can be animated.

For example, we can write:

<div class="progress">
  <div class="progress-bar progress-bar-striped progress-bar-animated" style="width: 75%"></div>
</div>

to animate the stripes with the progress-bar-animated and progress-bar-striped classes.

Conclusion

We can add progress bars with various lengths and styles.

They can also have labels inside it.