How can I change the color of a progress bar value in HTML?
Asked Answered
C

5

16

progress {
  border: none;
  width: 400px;
  height: 60px;
  background: crimson;
}

progress {
  color: lightblue;
}

progress::-webkit-progress-value {
  background: lightblue;
}

progress::-moz-progress-bar {
  background: lightcolor;
}
<div>
  <progress min="0" max="100" value="63" />
</div>

I have tried nearly everything, but the value color of the progress bar remains the same. The only browser that is responsive to a change is IE. Firefox allows to change background color only. Chrome doesn't show anything at all. Can you spot what is wrong with my code?

Cay answered 4/8, 2017 at 13:20 Comment(9)
css-tricks.com/html5-progress-elementCioban
By default this is styled by the OS/browser, but you can override it with ie. -webkit-appearance (see css-tricks.com/html5-progress-element/#article-header-id-4)Twine
typo in -moz-progress-bar? lighcolor=lightblue? But works for me in Firefox. jsfiddle.net/t0znpjhtPalmapalmaceous
You want to replace default background of progress (gray color by default), yes?Hodman
@VadimOvchinnikov no, I want to change the color of progress bar valueCay
@Cay background: lightblue; works in Chrome. Do you agree with this?Hodman
@VadimOvchinnikov well it works in IE and now in Firefox as well. As for Chrome it shows nothing literally - blank screen...Cay
@Cay Does RenzoCC's answer work for you?Hodman
@VadimOvchinnikov I still got issues with Chrome though but other browsers seem to work fine nowCay
B
30

progress {
  border: none;
  width: 400px;
  height: 60px;
  background: crimson;
}

progress {
  color: lightblue;
}

progress::-moz-progress-bar {
  background: lightblue;
}

progress::-webkit-progress-value {
  background: red;
}

progress::-webkit-progress-bar {
  background: blue;
}
It will work on webkit browser, like this example

<div>
  <progress min="0" max="100" value="63" />
</div>
Brisson answered 4/8, 2017 at 13:29 Comment(4)
why have you color property in another CSS rule, it can be put in first one also, right?Merit
why is there twice "progress::-webkit-progress-value {}"?Lifetime
it is not necessary to have "progress:-webkist-progress-value" twice, the answer has been updatedBrisson
it is showing different color in chrome and firefoxPoppy
A
5

Instead of making your own progress bar, you can simply use the accent-color variable instead of color or background.

progress {
  width: 400px;
  height: 60px;
}

.colored {
  accent-color: red;
}
<div>
  <p>Default: <progress min="0" max="100" value="63" /></p>
  <p>Colored: <progress class="colored" min="0" max="100" value="63" /></p>
</div>
Aruwimi answered 13/4, 2023 at 17:7 Comment(1)
A much better and cleaner solution than the one marked as answer. Tested on Chrome, Mozilla ad EdgeMop
M
0
progress {
  width: 400px;
  height: 60px;
}

.colored {
  accent-color: red;
}
Mure answered 28/6 at 15:2 Comment(0)
D
-1

it's pretty limited as to what you can dom but this this must do the trick

progress {
   -webkit-appearance: none;
}
progress::-webkit-progress-bar-value {
  -webkit-appearance: none;
  background: orangered;
}
Densmore answered 6/10, 2018 at 13:3 Comment(1)
::-webkit-progress-bar-value is invalidTalipes
D
-3

use this

accent-color:"#fff

Demy answered 25/11, 2022 at 12:22 Comment(1)
A code-only answer is not high quality. While this code may be useful, you can improve it by saying why it works, how it works, when it should be used, and what its limitations are. Please edit your answer to include explanation and link to relevant documentation.Philine

© 2022 - 2024 — McMap. All rights reserved.