How to Build a Reading Progress Bar With CSS and JavaScript

// Reading Progress bar in Html, Css and Js
// Html Part
<div id="progress-bar"></div>

// Css Part
#progress-bar {
  	--scrollAmount: 0%;
	background-image: linear-gradient(to right, #4facfe 0%, #00f2fe 100%);
	width: var(--scrollAmount);
	height: 4px;
	position: fixed;
	top: 0;
	left: 0;
}
    
    
// JavaScript Part
let processScroll = () => {
    let docElem = document.documentElement,
    docBody = document.body,
    scrollTop = docElem['scrollTop'] || docBody['scrollTop'],  //browser support, docElem or docBody  // the heigth we are on currently starting from top 
    scrollBottom = (docElem['scrollHeight'] || docBody['scrollHeight']) - window.innerHeight, // the heigth of the entire content
    scrollPercent = scrollTop / scrollBottom *100 + '%';

    console.log(parseInt(scrollPercent) + '%'+ ' = ' + scrollTop + ' / ' + scrollBottom)

    document.getElementById('progress-bar').style.setProperty('--scrollAmount', scrollPercent)
}

document.addEventListener('scroll', processScroll)

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
JavaScript Progress Bar design how to set up a progress bar javscript set progressbar progress by js html interactive progress bar html and javascript build a progress bar with html css and javascript build a step progress bar with html css and javascript how to set progress html js how to make bar progress in javascirpt how to build bar progress js how to make progress bar in javascript javascript page progress bar how to add progress bar file download in js simple file download progress bar in js js progress bar for show how to make horizontal progress bar in css tutorial javascript tutorial js reading progress bar javascript progress bar code javscript progress bar javascript easy progress bar javascript progress bar with steps update progress bar javascript make a dynamic progress bar with css and javascript how to program a progress bar javascript step progress bar in javascript how to implement progress bar in js progress bar with javascript reading progress bar js deginer progress bar using html css js progress bar in html using javascript how to change progress bar js update progress bar javascript progress bar css javascript javascript html progress bar how to create progress bar in html using javascript how to make my own progress bar in javascript to fill in 3 seconds how to fill out a progress bar with javascript js show progress bar from backend method how to implement progress bar in javasctipt howto make a progress bar js and html javascript progress bar how to add js to progress bar in html Reading Progress Bar With CSS and JavaScript How to Build a Reading Progress Bar With CSS and JavaScript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source