Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
accessibility

How to Change Image Opacity with HTML and CSS

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

HTML places an image on the page; CSS controls how transparent it looks. Add a class to the <img> element and set that class’s opacity to a number from 0 (invisible) to 1 (fully opaque), or use an equivalent percentage.

The basic method

Put the image in your HTML and apply a class. Then set opacity in CSS:

<img class="photo" src="photo.jpg" alt="Description of the photo">
.photo {
  opacity: 0.6;
}

The image remains in the document and keeps its layout space, but only 60% of its rendered pixels are opaque. The page behind it shows through the remaining 40%.

Opacity values and percentages

  • opacity: 1 or opacity: 100% leaves the image fully opaque.
  • opacity: 0.5 or opacity: 50% makes it half transparent.
  • opacity: 0 or opacity: 0% makes it invisible.

Values between zero and one are translucent. CSS also accepts percentages from 0% through 100%. A value outside the useful range is clamped to the nearest endpoint, so it is clearer and less error-prone to write a value in that range.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Make an image fade on hover

Use a normal opacity for the resting state, a transition for smooth movement, and a lower value for :hover:

.photo {
  opacity: 1;
  transition: opacity 200ms ease;
}

.photo:hover {
  opacity: 0.5;
}

The transition duration is 200 milliseconds in this example. Change it to suit the design, but avoid making an important control so subtle that users miss the state change.

Support keyboard and touch users

A hover-only change is unavailable on many touch devices and can be difficult to discover with a keyboard. If the fade communicates information or reveals a control, provide an equivalent focus or activated state:

.photo {
  opacity: 1;
  transition: opacity 200ms ease;
}

.photo:hover,
.photo:focus-visible {
  opacity: 0.5;
}

This works when the image itself is focusable, such as an image inside a link. For a plain decorative image, put the focus styles on the interactive parent instead:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.image-link {
  display: inline-block;
}

.image-link img {
  opacity: 1;
  transition: opacity 200ms ease;
}

.image-link:hover img,
.image-link:focus-visible img {
  opacity: 0.5;
}

Do not make essential information available only through hover. Touch users should get the same information through the normal page content or an explicit control.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Respect reduced-motion preferences

A fade is motion, even though it does not move the image across the page. You can remove the transition for visitors who request less motion:

@media (prefers-reduced-motion: reduce) {
  .photo {
    transition: none;
  }
}

The opacity state still changes; only the animated interpolation is removed.

Fade the image without fading text or controls

The opacity property applies to the entire element and all of its descendants. If you put an image and a caption inside one container and lower the container’s opacity, the caption fades too. A value below one also creates a new stacking context, which can change how that element’s z-index interacts with neighboring elements.

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

When only a background should be translucent while text stays fully readable, use an alpha color on the background instead of lowering the parent’s opacity:

.card {
  background: rgb(0 0 0 / 40%);
  /* Legacy-compatible form: */
  /* background: rgba(0, 0, 0, 0.4); */
}

Here the background color is composited at 40% opacity, while text and child controls retain their own opacity. This is the appropriate pattern for a translucent panel, overlay, or caption background.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Complete examples you can paste into a page

Static translucent image

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    .photo {
      max-width: 100%;
      opacity: 0.65;
    }
  </style>
</head>
<body>
  <img class="photo" src="photo.jpg" alt="A mountain at sunset">
</body>
</html>

Hover and keyboard fade

<style>
  .photo-link {
    display: inline-block;
  }

  .photo-link img {
    display: block;
    opacity: 1;
    transition: opacity 200ms ease;
  }

  .photo-link:hover img,
  .photo-link:focus-visible img {
    opacity: 0.5;
  }

  @media (prefers-reduced-motion: reduce) {
    .photo-link img {
      transition: none;
    }
  }
</style>

<a class="photo-link" href="/gallery">
  <img src="photo.jpg" alt="Open the photo gallery">
</a>

Reusable values with a custom property

:root {
  --image-opacity: 0.72;
}

.photo {
  opacity: var(--image-opacity);
}

A custom property is useful when a design system has one approved image treatment. Keep the final value between zero and one (or use a percentage) so the intent is obvious during code review.

What opacity changes—and what it does not

Layout and sizing

Opacity changes painting, not layout. An invisible image still has its intrinsic or CSS-defined dimensions, affects surrounding flow, and can reserve space. Use display: none or another layout technique only when you genuinely want the element removed from layout; do not use opacity as a substitute.

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

Pointer and keyboard interaction

Opacity does not disable hit testing. An image at opacity: 0 can still receive pointer input if it is interactive, and an invisible overlay can block clicks on content underneath. If an element should not be interactive, change its interaction behavior explicitly, for example by removing the link or using an appropriate state and focus management.

Layering

Because an opacity below one establishes a stacking context, descendants are composited together before the result is placed in the surrounding stack. If a badge, tooltip, or positioned child appears behind an element that used to be above it, inspect the parent’s opacity and the neighboring stacking contexts before changing arbitrary z-index values.

Accessibility and readability checks

Lowering the opacity of text, icons, or text placed over an image can reduce contrast. Keep meaningful text at full opacity where possible, then test the final composited colors against the actual background. MDN’s accessibility guidance cites WCAG contrast ratios of at least 4.5:1 for ordinary text and 3:1 for larger text; its definition of larger text is at least 18.66px when bold or 24px when not bold.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
  • Do not fade an image’s only text label until it becomes hard to read.
  • Use descriptive alt text for informative images; opacity does not change what assistive technology receives.
  • Keep keyboard focus visible even when a hover or focus state changes opacity.
  • Check the design in light and dark contexts, because the background showing through changes the perceived contrast.

Choosing the right technique

Goal Recommended CSS Result
Make the entire image translucent img { opacity: 0.6; } The image and its rendered descendants are composited at 60% opacity.
Fade on hover or focus :hover and :focus-visible with transition The image changes state when the user points to or focuses it.
Keep text opaque over a translucent panel background: rgb(0 0 0 / 40%); Only the background color is alpha-composited.
Hide an element and remove its layout space Use a deliberate layout or visibility strategy rather than opacity Opacity alone will not remove the element from flow or hit testing.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common problems

The image looks unchanged

  • Confirm the stylesheet is loaded and the selector matches the image’s class exactly.
  • Inspect the element in browser developer tools and check whether another rule overrides opacity.
  • Look for an inline style or a more specific selector. Fix the cascade rather than adding !important as a first resort.

The whole card, including text, is faded

You applied opacity to the card instead of the image. Move the declaration to the img selector, or use an alpha background color for the card.

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

The hover effect works with a mouse but not on a phone

Hover is not a reliable touch interaction. Keep the image readable by default and provide an explicit tap action or an equivalent focus/activated state.

A transparent image still blocks a button underneath

The element is still hit-testable. Remove the overlay from the interactive path or change its interaction state when it is not meant to receive input. Do not assume opacity: 0 means “not there.”

A tooltip or badge appears behind another layer

Check whether a parent has opacity below one, which creates a stacking context. Reorganize the positioned elements or apply the layering to a more appropriate wrapper.

The text fails contrast after the fade

Measure the final colors against the actual background and restore full opacity for meaningful text. Adjust the background, text color, or layout rather than relying on a barely visible label.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Testing and performance notes

Test the resting, hover, focus, and activated states at the actual image size. Check keyboard-only navigation, a touch device, zoomed text, and both color-scheme contexts used by your site. A simple opacity transition is generally inexpensive, but a page with many large, continuously animated images can still consume compositing and battery resources. Keep transitions short, avoid animating dozens of full-viewport images simultaneously, and honor prefers-reduced-motion.

Opacity does not change image download size. If bandwidth is the problem, use appropriately sized responsive images with srcset and sizes; use opacity only for the visual treatment.

Or skip the browser setup

If you need rendered screenshots of pages with this styling rather than a local browser workflow, ScreenshotNeo provides a website screenshot API and MCP server. It accepts a URL and returns PNG, JPEG, WebP, or PDF; its options include custom CSS and JavaScript, device presets, viewport and retina settings, full-page capture, element selection, waits, and dark mode. You can use those options to capture a page after applying the opacity rule in your own site.

One GET request is enough:

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

See the ScreenshotNeo documentation for authentication and the complete option list. Equivalent Python and Node.js requests are:

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://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

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 disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server supplies take_screenshot, get_page_info, and capture_pdf tools to Claude, Cursor, and other MCP clients.

The Free plan includes 1,000 shots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan, and yearly billing provides two months free. Create a free ScreenshotNeo account to try it without a card.

Frequently Asked Questions

Can I use a percentage instead of a decimal for image opacity?

Yes. CSS accepts percentages from 0% to 100%; choose the form that makes your design token easiest to read.

Why does an invisible image still take up room?

Opacity changes painting only. The element keeps its dimensions and layout participation until you use a separate layout or visibility technique.

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

Should I put opacity on a parent or on the image?

Put it on the image when only the image should fade. Put an alpha color on the background when child text and controls must remain fully opaque.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

Read next

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.