Progress Bar Interview Questions
Common interview questions about building progress bars. Here are the questions and answers.
Progress Bar Interview Questions
Here are common interview questions about building progress bars.
Q1: Build a progress bar that fills from 0 to 100% with a button.
let progress = 0; function fill() { const interval = setInterval(() => { progress += 1; bar.style.width = progress + "%"; if (progress >= 100) clearInterval(interval); }, 50); }
Q2: How would you animate the progress bar smoothly?
Use CSS transition: transition: width 0.3s ease. Or requestAnimationFrame for custom curves.
Q3: How would you handle a file upload progress bar?
Use XMLHttpRequest's progress event: (e.loaded / e.total) * 100. Note: fetch does not support upload progress.
Q4: Build a circular progress bar.
Use SVG with stroke-dasharray and stroke-dashoffset. Calculate offset = circumference - (percent/100 * circumference).
Q5: How would you show an indeterminate progress (unknown total)?
Use a striped or pulsing animation with CSS. No percentage, just a visual indicator that something is happening.
Q6: How would you change the color based on progress?
function getColor(p) { if (p < 33) return "#ff4444"; if (p < 66) return "#ffaa00"; return "#44aa44"; }
Q7: How would you make the progress bar accessible?
Add role="progressbar", aria-valuenow, aria-valuemin="0", aria-valuemax="100". Announce changes with aria-live for screen readers.
Q8: How would you handle progress above 100% or below 0%?
Clamp: percent = Math.max(0, Math.min(100, percent)).
The Takeaway
Progress bar interview questions: fill with button (setInterval), smooth animation (CSS transition), file upload (XHR progress), circular (SVG), indeterminate (striped animation), color based on progress, accessibility (ARIA), and clamping 0-100.
Use setInterval to increment progress: const interval = setInterval(() => { progress += 1; bar.style.width = progress + '%'; if (progress >= 100) clearInterval(interval); }, 50). Use CSS transition for smooth animation.
Use XMLHttpRequest (not fetch). Listen for xhr.upload 'progress' event: if (e.lengthComputable) { const percent = (e.loaded / e.total) * 100; setProgress(percent); }. fetch does not support upload progress events.
Add role='progressbar', aria-valuenow (current value), aria-valuemin='0', aria-valuemax='100'. Use aria-live='polite' to announce changes for screen readers. This makes the progress bar usable with assistive technology.
Use a striped or pulsing CSS animation without a specific percentage. The animation shows that something is happening, but the total is unknown. This is common for loading states where the server response time is unpredictable.
Clamp the value: percent = Math.max(0, Math.min(100, percent)). This ensures the progress bar never overflows or goes negative. Always clamp before setting the width.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

