Introduction to CSS Image Opacity
The CSS Image Opacity is defined as one of the property for achieving the image quality of lacking the transparency achieved this by using inserting the pseudo-elements with the regular opacity from the exact sizes of the elements behind from the screen; meanwhile, the opacity level will vary from the positioning of the image in the web page screen. Whatever we have assigned the values in the opacity property in css that range will be the prescription of the application; among these image attributes are not changed the opacity level ranges from 0.0 to 1.0.
Syntax and Parameters
The CSS codes are written with the html page using a style tag; we can follow some rules and syntax for customized web pages more attractiveness. We use image format data types in most of the web applications; the image format has its own attributes called opacity with user-specified values.
<html>
<head>
<style>
.first
{
opacity:values; // value ranges from 0.0 to 1.0
}
--some css style codes with user specification values---
</style>
<body>
<img src=" " alt=" " width="" height="">
---some html codes-----
</body>
</html>
We have written the above code that has the basic syntax for using the image with the opacity transparency in the web pages. The opacity value here is the parameter for the css style attributes.
How does Image Opacity work in CSS?
In the CSS style codes, we used a lot of attributes, properties with default values it will be both texts, numbers, special characters, etc. using these types of values, we can enable the particular property of their css attributes for making the presentation with more attractiveness. We can use the image element attributes in the html codes; it’s one of the default html tags, ID, or Some built-in classes. When we use css opacity in html image tag-based elements <img src> is one of the default and most widely used in the html codes for inserting the image has more opacity with different ranges and presentation of the css styles also it helps the elements in the CSS Style codes.The <img> mostly used in the <body> tag of the html because <style> also declare and initialized the opacity attribute values most probably used in the <head> web pages.
The opacity is used for describing the objects, that is, whatever things images, videos, animations, etc., it should be fully visible in the web screen, no latency, transparency. On the single web page, the opaque(opacity) element has optimized the values of 1 and other full transparent elements it has an opacity that controls the values. If the value is said to be 0 opacity, the image or video animations, whatever the object is totally invisible in the web page screens, but the value is occupied with the physical space on the web page. If the element invisible states in the screen, we can use the opacity property as well as the visible property is enabled in CSS. We know that the opacity property assigns the values in two different ways; the first way is we already mentioned earlier the opacity property attribute element had initialized the value with ranges.
But in a second way, we can also specify the alpha channels values with RGBA format(Red, Green, Blue, Alpha) declaration of the background colors we also change the R, G, and B values with our customized format it specified the transparent background of any colors. It also specifies how we can have performed the non-transparent child elements inside the transparent element; normally, the opacity values of the parent element will be described to its child elements; however, we are using the transparent background with the child elements to be opaque while keeping their transparent containers.
Examples of CSS Image Opacity
Below are the examples of CSS Image Opacity:
Example #1
Code:
<!DOCTYPE html>
<html>
<head>
<title>Welcome To My Domain</title>
<style>
.first > div {
display: inline-block;
height: 70px;
width: 70px;
background: green;
}
div.second {
opacity: 0;
}
div.third {
opacity: 0.1;
}
div.four {
opacity: 0.2;
}
div.five {
opacity: 0.3;
}
div.six {
opacity: 0.4;
}
div.seven {
opacity: 0.5;
}
div.eight {
opacity: 0.6;
}
div.nine {
opacity: 0.7;
}
div.ten {
opacity: 0.8;
}
div.eleven {
opacity: 0.9;
}
div.twelve {
opacity: 1;
}
</style>
</head>
<body>
<div class="first">
<h3>Have a Nice day</h3>
<div class="second">Welcome</div>
<div class="third">Welcome</div>
<div class="four">Welcome</div>
<div class="five">Welcome</div>
<div class="six">Welcome</div>
<div class="seven">Welcome</div>
<div class="eight">Welcome</div>
<div class="nine">Welcome</div>
<div class="ten">Welcome</div>
<div class="eleven">Welcome</div>
<div class="twelve">Welcome</div>
</div>
<div class="first">
<h3>Welcome Users</h3>
<div class="second">
Have a nice Day
<p>Gud day</p>
</div>
<div class="second">
Welcome
<p>Welcome</p>
</div>
<div class="opacity80">
Gud day
<p>Welcome</p>
</div>
<div class="opacity70">
Gud day
<p>Welcome</p>
</div>
<div class="opacity60">
Gud day
<p>Welcome</p>
</div>
<div class="opacity50">
Gud day
<p>Welcome</p>
</div>
<div class="opacity40">
Gud day
<p>Welcome</p>
</div>
<div class="opacity30">
Gud day
<p>Welcome</p>
</div>
<div class="opacity20">
Gud day
<p>Welcome</p>
</div>
<div class="opacity10">
Gud day
<p>Welcome</p>
</div>
<div class="opacity0">
Gud day
<p>Welcome</p>
</div>
<p><small>Welcome <code>To</code> My Domain</small></p>
</div>
</body>
</html>
Output:
Example #2
Code:
<html>
<head>
<style>
.img
{
opacity:0.8;
filter: alpha(opacity=1);
background-color: red;
padding: 11px;
}
</style>
<body>
<img src="first.jpg" alt="transparent images " width="180" height="179">
</body>
</html>
Output:
Example #3
Code:
<!DOCTYPE html>
<html>
<head>
<style>
#first {
background-color: pink;
}
</style>
</head>
<body>
<h1>Welcome To My Domain</h1>
<p id="first">We can choose the Opacity value in the given scroll box</p>
<select onchange="demo(this);" size="5">
<option>0.2
<option>0.3
<option>0.4
<option>0.7
<option selected="selected">1
</select>
<script>
function demo(i) {
var a = i.options[i.selectedIndex].text;
var b = document.getElementById("first");
if (b.style.a !== undefined) {
b.style.a = a;
} else {
alert("Browser is not compatable!");
}
}
</script>
</body>
</html>
Output:
In the above three examples, we have used opacity values in three different scenarios and the final examples. If the user supports the browser from the mentioned opacity values based on the requirements, it may vary in web applications.
Conclusion
The image opacity property is used to criticize the image attributes in both html and CSS using opacity property with number and alpha based characters. It also placed on the web pages with the correct positions because it also checks and does not affect the other contents like images and animations.
Recommended Articles
This is a guide to CSS Image Opacity. Here we discuss How does Image Opacity work in CSS and Examples, along with the codes and outputs. You may also have a look at the following articles to learn more –