For a regular HTML image, set the CSS opacity property on the <img> element. Use a value from 0 to 1: 0 is visually invisible, values between 0 and 1 are translucent, and 1 is fully opaque.
<img class="faded-image" src="photo.png" alt="A description of the image">
.faded-image {
opacity: 0.5;
}
This changes the rendered image, allowing whatever is behind it to show through. The right technique depends on whether you want to fade the entire image, only a background color, or use a decorative background image.
Choose the technique that matches the result
| What you need | Use | What becomes transparent | Important caveat |
|---|---|---|---|
| Fade an image in the document | opacity on <img> |
The complete rendered image | The image remains in the layout and can still be interactive at zero opacity |
| Make only a panel color translucent | background-color with an alpha value |
The background color | Text and other foreground content stay opaque |
| Use artwork as decoration | background-image on a container |
The background artwork, according to the container styling | Background images do not provide image information to assistive technology |
The MDN opacity reference defines the property as setting an element’s opacity. An alpha-bearing color follows the CSS alpha-value rules.
Fade a normal HTML image
Basic example
Keep meaningful content as an <img> and add a class that controls its visual opacity.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitches#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Transparent image</title>
<style>
.faded-image {
opacity: 0.5;
}
</style>
</head>
<body>
<img class="faded-image" src="photo.png" alt="A mountain lake at sunrise">
</body>
</html>
Change 0.5 to any value between 0 and 1. A value such as 0.2 produces a very faint image; 0.8 leaves it mostly solid. The CSS property changes how the browser composites the element; it does not rewrite the PNG, JPEG or WebP file.
Apply it to one image or a group
A class is safer than styling every image globally. Use a shared class for a gallery, or an ID when one image needs a one-off rule.
.gallery img {
opacity: 0.65;
}
#watermark {
opacity: 0.25;
}
If a stylesheet rule is not taking effect, inspect the element in developer tools and check whether a more specific selector or an inline style declaration wins. Keep the rule in the stylesheet when possible so the effect is easy to adjust.
Understand what opacity affects
Opacity applies to the whole element
Although the opacity property is not inherited in the usual CSS sense, the browser renders the element and its contents together with the specified transparency. If you put text, icons or buttons inside a wrapper and lower that wrapper’s opacity, those descendants also appear translucent.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
.card {
opacity: 0.6;
}
/* The heading, paragraph and button inside .card also look faded. */
To fade only an image while leaving nearby text readable, put the opacity class on the <img>, not on the parent that contains the text.
Rank #2
Zero opacity is visual, not removal
opacity: 0 makes an element invisible to sighted users, but it stays in the DOM. It may still receive pointer events and, when focusable, keyboard focus. Do not use zero opacity as a substitute for removing an item, disabling a control or hiding content from assistive technology. Use the appropriate HTML state or CSS visibility/display behavior for that separate requirement.
Opacity creates a stacking context
An opacity value other than 1 creates a new stacking context. In practical terms, the element’s layering can behave differently relative to neighboring elements. If a translucent item appears behind or in front of something unexpectedly, inspect position, z-index and the stacking contexts created by ancestor elements.
Make a background color translucent without fading text
If the goal is a translucent panel, overlay or badge, use an alpha-bearing background-color rather than lowering the opacity of the container.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →.notice {
background-color: rgb(0 0 0 / 40%);
color: white;
padding: 1rem;
}
.notice strong,
.notice a {
opacity: 1;
}
The 40% alpha controls only the black background color. The text remains rendered at full opacity. You can use another color and alpha value, for example rgb(255 255 255 / 70%), when a light overlay is needed.
Use a CSS background image for decoration
For artwork that is purely decorative, apply background-image to a container and control the visual treatment with a pseudo-element or an overlay layer.
Rank #3
.hero {
position: relative;
isolation: isolate;
background-image: url("hero.jpg");
background-size: cover;
background-position: center;
}
.hero::before {
content: "";
position: absolute;
inset: 0;
background: rgb(0 0 0 / 35%);
z-index: -1;
}
Use a semantic <img> instead when the picture communicates information. The MDN background-image reference notes that browsers do not provide special information about background images to assistive technology. A background image therefore should not be the only representation of meaningful content.
Preserve accessibility while changing appearance
Write useful alternative text
Meaningful images should remain HTML <img> elements with an appropriate alt value. The MDN <img> reference describes alt as a text replacement for the image’s content. Describe the purpose or information conveyed, not merely that it is a “picture.”
For a decorative image, an empty alt="" can indicate that no alternative text is needed, provided the image is not carrying information users need.
Check contrast after fading
Opacity can reduce the contrast of text placed over an image or of text inside a translucent wrapper. MDN describes current WCAG guidance as at least 4.5:1 for normal text and 3:1 for larger text; it defines large text as at least 24px, or bold text at least 18.66px. These ratios concern text contrast, not a required opacity value. Test the final foreground/background combination rather than assuming a particular percentage is accessible.
Common patterns
Fade an image on hover
.thumbnail {
opacity: 0.7;
transition: opacity 160ms ease;
}
.thumbnail:hover,
.thumbnail:focus-visible {
opacity: 1;
}
Keep a visible keyboard focus state when the image is a link or otherwise focusable. The transition is optional; remove it when motion is not appropriate for your interface.
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Combine a transparent image with a solid fallback
.logo-box {
background-color: #123047;
padding: 1rem;
}
.logo-box img {
opacity: 0.9;
}
A background color gives the transparent edges of a logo a predictable surface. Choose a color that maintains the required contrast for any adjacent text.
Troubleshoot an image that does not look transparent
The image looks unchanged
- Confirm the selector matches the actual element and that the stylesheet is loaded.
- Check the computed
opacityvalue in developer tools; a later or more specific rule may override it. - Make sure the background behind the image is different enough to reveal the effect. Transparency over a solid white background can look nearly opaque.
The text beside the image is faded too
You probably set opacity on a wrapper. Move the rule to the <img> itself, or replace wrapper opacity with an alpha background-color when only the panel should be translucent.
The transparent image still captures clicks
That is expected at opacity: 0. The element remains present and can receive pointer input. Remove it from the interaction model or disable the control instead of relying on visual opacity.
Layering changed after adding opacity
Because a non-1 opacity creates a stacking context, inspect the element and its ancestors. Adjust the relevant z-index and positioning relationships rather than adding arbitrary large numbers.
The background artwork is missing for screen-reader users
Background images are not announced as image content. If the artwork conveys information, replace the background-only implementation with a semantic <img> and suitable alternative text.
Best Value
Test the result before shipping
- Open the page at the narrowest and widest layouts you support.
- Try at least three values, such as
0.25,0.5and0.8, against the real background. - Use keyboard navigation to verify that an invisible or translucent image does not create an unexpected focus stop.
- Check text contrast in the final composition, including text over photographs and overlays.
- Inspect the accessibility tree or screen reader output when deciding between
<img>andbackground-image.
Or skip the browser setup
If you need a rendered website image rather than CSS source changes, ScreenshotNeo provides a GET-based screenshot API and an MCP server for AI agents. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its options include transparent backgrounds, full-page capture, element selection, custom CSS and JavaScript, waits, device presets, PDF output and bulk capture.
Read the parameter details in the ScreenshotNeo documentation. The following calls are runnable; replace the access key and target URL.
cURL
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
Python
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
An MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for the free ScreenshotNeo plan.
Frequently asked questions
Does CSS opacity make the original PNG or JPEG file transparent?
No. It changes only the browser’s rendered appearance. To distribute a file with transparent pixels, edit or export the asset in an image editor; CSS opacity does not alter the source bytes.
Recommended Free Tools
Can an image be partly transparent while its link remains usable?
Yes. Opacity changes appearance, not the element’s existence or hit area. Make sure the reduced contrast still communicates that the image is interactive, and provide a clear focus style for keyboard users.
Frequently Asked Questions
Does CSS opacity make the original PNG or JPEG file transparent?
No. It changes only the browser’s rendered appearance; it does not alter the source image file.
Can an image be partly transparent while its link remains usable?
Yes. Opacity changes appearance, not the element’s existence or hit area. Preserve clear focus and sufficient contrast.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Free tools Windows power users keep installed
One-click scans. No signup required.

