HTML | DOM Style opacity Property
The Style opacity property in HTML DOM used to set opacity level for an element. Opacity level defines the transparency level where value 1 represents not transparent, 0.5 represents 50% transparency and 0 represents completely transparent.It also returns opacity level of an element.
Syntax:
- It returns the opacity property.
object.style.opacity
- It is used to set the opacity property.
object.style.opacity = "number|initial|inherit"
Property Values:
- number: It specifies the opacity value and it ranges form 0.0 to 1.0.
- intial: It sets the opacity property to its default value.
- inherit: This property is inherited from its parent element.
Return Value: It returns a string representing the opacity level of an element.
Example-1:
<!DOCTYPE html> <html> <head> <title>DOM Style opacity Property </title> </head> <body> <center> <h1 style="color:green;"> GeeksForGeeks </h1> <h2>DOM Style opacity Property </h2> <div id="gfg"> A Computer science portal for geeks</div> <button type="button" onclick="geeks()"> set Decoration </button> <script> function geeks() { document.getElementById("gfg").style.opacity = "0.3"; } </script> </center> </body> </html> |
Output:
- Before clicking on the button:

- After clicking on the button:

Example-2:
<!DOCTYPE html> <html> <head> <title>DOM Style opacity Property </title> <style> #gfg { width: 150px; height: 40px; background-color: green; } </style> </head> <body> <center> <h1 style="color:green;"> GeeksForGeeks </h1> <h2>DOM Style opacity Property </h2> <div id="gfg" style="color:white"> A Computer science portal for geeks</div> <button type="button" onclick="geeks()"> change opacity </button> <script> function geeks() { document.getElementById("gfg").style.opacity = "0"; } </script> </center> </body> </html> |
Output:
- Before clicking on the button:

- After clicking on the button:

Supported Browsers: The browser supported by DOM Style opacity property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Apple Safari
Recommended Posts:
- HTML | DOM Style right Property
- HTML | DOM Style top Property
- HTML | DOM Style animationDuration Property
- HTML | DOM Style borderBottomRightRadius Property
- HTML | DOM Style animationIterationCount Property
- HTML | DOM Style listStyle Property
- HTML | DOM Style quotes Property
- HTML | DOM Style animation Property
- HTML | DOM Style borderBottomLeftRadius Property
- HTML | DOM Style borderImage Property
- HTML | DOM Style borderColor Property
- HTML | DOM Style backgroundSize Property
- HTML | DOM Style borderBottomWidth Property
- HTML | DOM Style borderBottomStyle Property
- HTML | DOM Style order Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



