CSS Image Opacity
The opacity property specifies the opacity/transparency of an element.
The opacity property can take a value from 0.0 - 1.0:
- 0.0 - The element will be completely transparent
- 0.5 - The element will be 50% transparent
- 1.0 - Default. The element will be fully opaque
Example
img {
opacity: 0.5;
}
Tip: Look at the CSS Image Filters chapter to learn how to use the filter property to add visual effects (like opacity, blur, saturation, etc.) to images.
Image Text Positioning
How to position text in an image:
Example
<div style="position:relative;text-align:center;">
<img alt="Cingue Terre" src="img_5terre_wide.jpg" style="width:100%;height:auto;opacity:0.3"/>
<div style="position:absolute;bottom:8px;left:16px;font-size:18px">Bottom Left</div>
<div style="position:absolute;top:8px;left:16px;font-size:18px">Top Left</div>
<div style="position:absolute;top:8px;right:16px;font-size:18px">Top Right</div>
<div style="position:absolute;bottom:8px;right:16px;font-size:18px">Bottom Right</div>
<div style="position:absolute;top:50%;left:50%;transform:translate(-50%, -50%);font-size:18px">Centered</div>
</div>