10

Putting any value other than HEX (#ffffff) gives a console error. But I was wondering if user wanted no color and transparent instead.

I know the below syntax not going to work anyway. But is there any way that can achieve transparent value.

<input type='color' value='transparent'/>
Hamza Dhamiya
  • 1,269
  • 1
  • 10
  • 17

2 Answers2

2

I don't think it's currently possible to set a transparent value using a native HTML color input:

Note: Setting the value to anything that isn't a valid, fully-opaque, RGB color in hexadecimal notation will result in the value being set to #000000. In particular, you can't use CSS's standardized color names, or any CSS function syntax, to set the value.

This makes sense when you keep in mind that HTML and CSS are separate languages and specifications. In addition, colors with an alpha channel are not supported; specifying a color in 9-character hexadecimal notation (e.g. #009900aa) will also result in the color being set to #000000.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color#value

A potential solution could be using a library like Pickr.js.

Maggie Cody
  • 619
  • 1
  • 6
  • 14
-7

<div style="background-color:rgba(0, 0, 0, 0.5);">
   <div>
      Text added.
   </div>
</div>

Currently there is no direct transparent background support for HTML5. I would suggest CSS

link here: CSS Background Opacity

Community
  • 1
  • 1
niXful-Autistic
  • 217
  • 1
  • 6