Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Direct answer: For an image in HTML, set the CSS opacity property on its <img> element. Use a value from 0 (visually invisible) through 1 (fully opaque), such as 0.5 for a 50% fade. Lower opacity lets whatever is behind the image show through. See the MDN opacity reference for the property definition.

The basic HTML and CSS

Give the image a class, then style that class. Keep meaningful alternative text in the HTML.

<img class='faded-image' src='photo.png' alt='A mountain at sunrise'>
.faded-image {
  opacity: 0.5;
}

The browser still lays out the image at its normal size. Only its rendered appearance changes. The content behind it becomes visible through the image as the value decreases.

Opacity values at a glance

Value Visual result Typical use
0 Completely transparent visually Temporary visual hiding, when interaction is handled separately
0.25 Very faint image Subtle watermark effect
0.5 Half-strength image Faded artwork or overlay
0.75 Slightly translucent Softening an image without losing much detail
1 Fully opaque; the initial value Normal display

Values between zero and one are valid fractional opacity values. If you need a different strength, change the number rather than editing the image file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Make an image fade on hover

Put the normal opacity on the image and change it in a :hover rule. A transition makes the change gradual.

.gallery-image {
  opacity: 1;
  transition: opacity 180ms ease;
}

.gallery-image:hover {
  opacity: 0.6;
}
<img class='gallery-image' src='product.jpg' alt='Blue travel backpack'>

The transition affects the visual property only. It does not remove the image from the document or change its alternative text.

Make a background translucent without fading text

If the image is inside a card or banner and you want the background color to become translucent while headings and body text remain solid, do not lower opacity on the parent. Use an alpha-bearing color instead. The MDN background-color reference documents this property.

.notice {
  background-color: rgb(0 0 0 / 40%);
  color: white;
  padding: 1rem;
}
<section class='notice'>
  <h2>Scheduled maintenance</h2>
  <p>The service will be unavailable at 02:00 UTC.</p>
</section>

Here, only the black background is 40% opaque. The text remains at its declared color and opacity. An alpha value controls the transparency of a color; it is a different operation from applying opacity to the entire element. The MDN alpha-value reference covers the alpha component.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand what opacity affects

It fades the element and everything it renders

Opacity is applied to the rendered element as a whole. Although the property is not inherited in the normal CSS sense, a parent rendered at opacity: 0.5 makes its descendants appear at half strength too. That includes text, icons, borders and nested images.

.card {
  opacity: 0.5;
}

With that rule, a heading inside .card also looks translucent. To keep the heading readable, move the image into its own element and apply opacity only to that image, or use an alpha background color.

Zero opacity is not removal

An element at opacity: 0 is invisible to sighted users but remains in the DOM. It can still receive pointer events and, if it is focusable, keyboard focus. Do not use zero opacity as a substitute for disabling a button, removing a link, or taking content out of the accessibility and interaction model. The MDN opacity documentation describes this behavior.

Non-one opacity creates a stacking context

An opacity value other than 1 creates a new stacking context. In practical terms, changing opacity can alter how that element and its descendants layer against neighboring elements. If a translucent image unexpectedly appears above or below another object, inspect position, z-index and the stacking contexts of both elements rather than adding arbitrary large z-index values.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a CSS background image when the artwork is decorative

For a purely decorative texture or hero backdrop, apply background-image to a container.

.hero {
  min-height: 20rem;
  background-image: url('hero.jpg');
  background-size: cover;
  background-position: center;
}

A background image is not announced as image content by browsers to assistive technology. MDN states that browsers provide no special information about background images to assistive technology in its background-image reference. Therefore, use this technique only when the artwork is decorative and the surrounding HTML already conveys the purpose of the section.

If the image communicates information, use a semantic <img> and an appropriate alt value. The MDN <img> reference describes alt as the text replacement for the image’s content.

Layer a translucent image behind readable content

A common design is a text panel over a faded photo. Keep the photo and the text in separate layers so only the photo is translucent.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.feature {
  position: relative;
  isolation: isolate;
  color: white;
  padding: 3rem 2rem;
  overflow: hidden;
}

.feature::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url('feature.jpg') center / cover no-repeat;
  opacity: 0.35;
  z-index: -1;
}
<section class='feature'>
  <h2>Plan your next trip</h2>
  <p>Compare routes and save your favorites.</p>
</section>

The pseudo-element carries the background and its opacity, while the section’s text remains fully opaque. The isolation declaration keeps the negative stacking layer contained within the section.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • 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

Keep text contrast readable

When text itself is faded, check the contrast against the final background. MDN describes current WCAG guidance as a minimum contrast ratio of 4.5:1 for ordinary text and 3:1 for larger text; it defines large text as at least 24px, or bold text at least 18.66px. These ratios apply to text contrast, not to the numeric image-opacity setting. Test the actual combination users will see, especially when a translucent image changes the background behind the text.

Common problems and fixes

The image disappears

  • Cause: The value is 0, or a later rule overrides your intended value.
  • Fix: Set a visible test value such as 0.5, inspect the element in browser developer tools, and check which declaration wins. Confirm that the image file itself loaded and that no parent has opacity: 0.

The heading and buttons are faded too

  • Cause: Opacity was placed on a wrapper that contains the foreground content.
  • Fix: Move the opacity declaration to the <img> or a dedicated pseudo-element. If only a color needs translucency, use rgb(... / alpha) on background-color.

The invisible image still captures clicks or focus

  • Cause: opacity: 0 changes appearance, not interaction behavior.
  • Fix: Disable the control or remove it from the interactive flow using the appropriate HTML state. Do not rely on opacity alone.

The background image is missing for screen-reader users

  • Cause: Important information was implemented only as a CSS background.
  • Fix: Represent meaningful content with a semantic <img> and useful alt text. Reserve CSS backgrounds for decoration.

The fade looks different over different pages

  • Cause: Opacity reveals whatever is behind the element, so a light page and a dark page produce different results.
  • Fix: Give the image a known background or place it over a controlled color. For a consistent wash, use a separate translucent overlay layer rather than depending on an unknown page background.

The image is translucent but the text fails contrast

  • Cause: The revealed artwork changes the effective text background.
  • Fix: Increase text contrast, darken or lighten the overlay, reduce the image opacity, or move the text to a solid panel. Check the final rendered state against the applicable contrast ratios.

Testing checklist

  1. Open the page at the smallest viewport you support and verify that the image remains visible at the chosen value.
  2. Inspect the element and confirm the intended selector is winning in the cascade.
  3. Check whether any parent has an opacity value that unintentionally fades descendants.
  4. Tab through the page. An invisible element should not unexpectedly receive focus or intercept input.
  5. Use a screen reader or accessibility tree inspection to confirm that meaningful images still have suitable alt text.
  6. Check text contrast over the actual image, not just over a solid-color mockup.
  7. Test hover and keyboard states separately if the transparency changes interactively; keyboard users need an equivalent visible state.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a rendered capture of a page after its HTML and CSS are applied, ScreenshotNeo can return a PNG, JPEG, WebP or PDF from one request. It is separate from the CSS technique above: your page still controls the opacity, while ScreenshotNeo captures the result.

For a one-call capture, create an API key and run:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo documentation for all request parameters. The equivalent Python request is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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)

In 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}`);
const data = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', data));

ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks and 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 MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients.

For transparency work, useful options include a full-page capture with lazy images loaded, a CSS-selector element capture, dark mode, custom viewport and retina scale, transparent background, custom CSS or JavaScript, click-before-capture, selector hiding, waits for a selector or network idle, custom headers and cookies, geolocation and timezone, caching with a chosen TTL, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, and a usage API. Every feature is included on every plan.

Plan Included screenshots Price
Free 1,000 per month No card required
Starter 3,000 $5

Paid plans start at $5 for 3,000 screenshots, while the free plan includes 1,000 each month with no card. If you want to capture your transparent-image result without maintaining a browser automation setup, sign up for the free plan.

FAQ

Can I apply opacity directly inside background-image?

No. opacity is a property of the element, not a modifier inside the url() value. Put the background on a separate pseudo-element or layer and set opacity on that layer, or use an alpha-bearing background color when a color wash is sufficient.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why does a screenshot show a different fade than my browser preview?

Opacity reveals the pixels behind the image. A different viewport, page background, color scheme, loaded font, consent banner or other overlay changes those pixels. Capture the same URL and viewport after the page has finished loading, and inspect the screenshot service’s verdict headers when diagnosing a failed or incomplete render.

Frequently Asked Questions

Can I apply opacity directly inside background-image?

No. opacity belongs to the element, not to the url() value. Put the background on a separate pseudo-element or layer and set opacity there, or use an alpha-bearing background color.

Why can a screenshot show a different fade from my browser preview?

Opacity reveals whatever is behind the image. A different viewport, background, color scheme, loaded asset or overlay changes the result, so capture the same URL and viewport after loading completes.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.