Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change the default input format of the HTML color input in Chrome?

In Chrome 83, the color picker that appears upon clicking a <input type="color"> widget defaults to RGB input:

Chrome color picker using RGB input

The input format can be changed to HSL or HEX by clicking the two little arrows to the right of the letter "B".

Is there a way that I can change the default input format from RGB to HEX, or to only allow HEX input? HTML/CSS/JS would be ideal, but I'd be curious if there's even a Chrome setting to adjust this.

like image 292
jobo3208 Avatar asked Jul 20 '20 16:07

jobo3208


People also ask

How do I change the color of the default input color?

You have to use document. querySelector('input[type="color"]'). value = '#ffffff' for it to work.

Can I make the HTML color input only display hex?

You can't make it only display hex, but whatever mode the user chooses the value is stored as hex.

How do you change the background color of input field in HTML?

HTML, CSS and JavaScript To add background color to the form input, use the background-color property.


1 Answers

No, it is not possible (as of December 2020). You could implement and provide a color picker with JavaScript.

Each browser (or OS combination) will show a default color picker or the OS's color picker.

https://collectiveidea.com/blog/archives/2011/09/14/hsl-color-selector-using-html5-and-css shows a different approach: a range slider with a gradient as background. It does not work in all browsers, but it might fit your requirements.

.spectrum {
  display: block;
  width: 150px;
  height: 15px;
  margin: 0 0 -3px 7px;
  background: -webkit-linear-gradient(left, hsl(0, 100%, 50%), hsl(60, 100%, 50%), hsl(120, 100%, 50%), hsl(180, 100%, 50%), hsl(240, 100%, 50%), hsl(300, 100%, 50%) 100%);
}

input[type=range] {
  width: 161px;
  margin-top: -5px;
}
<span class="spectrum"></span>
<input type="range" min="0" max="300" step="1">
like image 96
knittl Avatar answered Oct 21 '22 16:10

knittl