HTML Image Opacity
The image opacity is to create an image that fades in or out over time. This can be used to create a smooth transition between two images or to create an animation.
Image opacity can also utilize to create a ghost image. This image is barely visible and is utilized for decorative purposes.
Also, image opacity can utilize to create a negative image. This image is the opposite of a standard image and can be used for special effects.
HTML Image Opacity
Opacity is an effect of an image that specifies how opaque or transparent an image is. An image with an opacity level of 0
is completely transparent, while an image with an opacity level of 1
is completely opaque.
Opacity can be specified using either a numeric value between 0
and 1
or a percentage value between 0%
and 100%
.
When an image has an opacity level of less than 1
, the image will be partially transparent, allowing the background to show through. This can create various exciting effects, such as layering images on each other or making an image appear to fade into the background.
The HTML image opacity
property is used to control the opacity of an image on a web page. This can be useful for creating effects such as making an image fade into the background or appear layered on top of another image.
Let’s see an example; say you want to make an image 50%
opaque, you would set the opacity
to 0.5
; furthermore, you can also set the opacity
using the rgba()
color value.
img {
opacity: 0.5;
}
You can also combine the opacity property with the hover
pseudo-class to create images that fade with it or off when the mouse is over them. For example, you could set the opacity
of an image to 0.5
on hover
like this:
img:hover {
opacity: 0.5;
}
This would make the image appear semi-transparent, with the background visible behind it.
<!DOCTYPE html>
<html>
<head>
<style>
div.bg {
background: url(Please add image link here) repeat;
border: 2px solid black;
}
div.ax {
margin: 35px;
background-color: #ffffff;
border: 1px solid black;
opacity: 0.6;
}
div.ax p {
margin: 10%;
font-weight: bold;
color: #000000;
}
</style>
</head>
<body>
<div class="bg">
<div class="ax">
<p>There is some text that is present in this transparent box.</p>
</div>
</div>
</body>
</html>
Conclusion
The opacity of an image in HTML can be controlled using the opacity
property. This property can be set to 0
and 1
, where 0
is completely transparent, and one is completely opaque.
So, if you wanted to make an image 50%
opaque, you could use the rgba()
color value with an opacity of 0.5
.
Zeeshan is a detail oriented software engineer that helps companies and individuals make their lives and easier with software solutions.
LinkedIn