Skip to main content

CSS Image Opacity

The opacity property sets how transparent an element is.

The opacity property takes a value from 0.0 to 1.0:

  • 0.0 — the element is completely transparent
  • 0.5 — the element is 50% transparent
  • 1.0 — the default; the element is fully visible

Tip: See the CSS Image Filters chapter to learn how to use the filter property to add visual effects like opacity, blur, and saturation to images.

Example

Set the opacity of an image to 0.5 to make it 50% transparent.

Prompt
Create a page showing three images of a forest side by side, each with a different CSS opacity value: 0.2, 0.5, and 1.0. Label each image with its opacity value below it.
Output: complete HTML page

Image Text Positioning

You can use CSS positioning to place text over an image at different locations.

Top Left

Position text at the top-left corner of an image.

Prompt
Create a page with a wide landscape image inside a container with position relative. Place white text "Top Left" at the top-left corner of the image using absolute positioning.
Output: complete HTML page

Top Right

Position text at the top-right corner of an image.

Prompt
Create a page with a wide landscape image inside a container with position relative. Place white text "Top Right" at the top-right corner of the image using absolute positioning.
Output: complete HTML page

Bottom Left

Position text at the bottom-left corner of an image.

Prompt
Create a page with a wide landscape image inside a container with position relative. Place white text "Bottom Left" at the bottom-left corner of the image using absolute positioning.
Output: complete HTML page

Bottom Right

Position text at the bottom-right corner of an image.

Prompt
Create a page with a wide landscape image inside a container with position relative. Place white text "Bottom Right" at the bottom-right corner of the image using absolute positioning.
Output: complete HTML page

Centered

Position text at the center of an image.

Prompt
Create a page with a wide landscape image inside a container with position relative. Place white text "Centered" in the exact center of the image using absolute positioning and transform translate.
Output: complete HTML page