HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
  • Insights
  • Verify Certificate
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials
HTML5ANDCSS3 logoHTML5ANDCSS3Tools and Tutorials

HTML5andCSS3.org helps developers learn modern frontend skills with practical tutorials, production-ready snippets, and fast web tools built for everyday coding.

Quick Links

  • About Us
  • Contact Us
  • Privacy Policy
  • Copyright
  • Disclaimer

Top Tools

  • Try It Editor
  • JSON Formatter
  • CSS Minifier
  • HTML Minifier
  • Base64 Encoder / Decoder

Contact

  • business@html5andcss3.org
Newsletter

Learn at your own pace, practice with useful tools, and build websites you're proud of.

© 2011-2026 html5andcss3.org. All rights reserved.

How to Use

CSS Tutorial

CSS Introduction

What is CSSCSS SyntaxHow to Add CSSCSS Comments

CSS Foundations

Cascade & InheritanceCSS SpecificityCSS UnitsBox SizingCSS VariablesCSS Math Functions

CSS Selectors

CSS Element SelectorCSS Class SelectorCSS ID SelectorCSS Universal SelectorCSS Group SelectorCSS CombinatorsCSS Attribute SelectorsCSS Pseudo ClassesCSS Pseudo Elements

CSS Colors and Backgrounds

CSS ColorsCSS HEX ColorsCSS RGB ColorsModern ColorsCSS Background ColorCSS Background ImageLayered Backgrounds

CSS Text & Fonts

CSS Text ColorCSS Text AlignmentCSS Text DecorationCSS Font FamilyCSS Font SizeWeb Fonts & TypographyText Wrapping

CSS Box Model

CSS MarginCSS PaddingCSS BorderCSS OutlineCSS Width and Height

CSS Layout

Normal FlowCSS DisplayCSS PositionAnchor PositioningCSS FloatCSS OverflowCSS Z-indexIntrinsic SizingAspect Ratio & Object FitMulti-column Layout

CSS Flexbox

Flex ContainerFlex DirectionJustify ContentAlign ItemsFlex WrapFlex Item Sizing

CSS Grid

CSS Grid ContainerCSS Grid ColumnsCSS Grid RowsCSS Grid GapCSS Grid Layout ExampleGrid PlacementGrid AreasCSS Subgrid

CSS Lists, Tables & Forms

CSS ListsCSS TablesCSS Form StylingCSS Input Fields

CSS Effects

CSS ShadowsCSS GradientsCSS FiltersCSS OpacityClipping & MaskingBlending & BackdropScroll Snap

CSS Animations & Transitions

CSS TransformCSS 2D TransformCSS 3D TransformCSS TransitionsEntry & Exit TransitionsCSS AnimationsScroll AnimationsView TransitionsMotion Paths

CSS Responsive Design

CSS Media QueriesResponsive LayoutMobile First DesignContainer QueriesPreference Media QueriesFeature Queries

Modern CSS Authoring

Cascade LayersNesting & ScopeLogical PropertiesGenerated Content

CSS Accessibility

Accessible CSSCSS ThemingModern Form StylingCSS User Interface

CSS Output & Performance

Print StylesCSS PerformanceCSS ArchitectureDebugging CSS

CSS Reference

CSS At-rulesCSS FunctionsCSS Tutorial PDF

CSS Projects

Responsive CSS Project
  1. Home
  2. /
  3. Tutorials
  4. /
  5. CSS Tutorial
  6. /
  7. CSS Opacity

CSS Effects

CSS Opacity

The CSS Opacity property is used to control the transparency level of an element.

Opacity determines how visible or transparent an element appears on a webpage. The supporting concepts are explained in CSS Colors and Blending & Backdrop.

The opacity value ranges from:

  • 0 -> Completely transparent (invisible)
  • 1 -> Fully visible (default)

Opacity is commonly used for:

  • Image hover effects
  • Overlays
  • Background effects
  • Modern UI designs
  • Fade animations

Syntax

Opacity Syntax

css

selector {
    opacity: value;
}

Opacity Example

css

img {
    opacity: 0.5;
}

Makes the image 50% transparent.

Attributes

ValueDescriptionExample
0Completely transparentopacity: 0;
0.25Mostly transparentopacity: 0.25;
0.5Semi-transparentopacity: 0.5;
0.75Slightly transparentopacity: 0.75;
1Fully visibleopacity: 1;

Example

CSS Opacity Complete Example

html

<!DOCTYPE html>
<html>
<head>
    <title>CSS Opacity Example</title>
    <style>
        .box {
            width: 250px;
            padding: 20px;
            background-color: #007acc;
            color: white;
            opacity: 0.7;
            margin-bottom: 20px;
        }
        img {
            width: 250px;
            opacity: 0.5;
            transition: opacity 0.3s ease;
        }
        img:hover {
            opacity: 1;
        }
    </style>
</head>
<body>
    <div class="box">
        This box has 70% opacity.
    </div>
    <img src="https://ik.imagekit.io/html5andcss3/frontend-media/html_example.webp" alt="Opacity Example">
</body>
</html>

Browser Support

Feature
Chrome
Edge
Firefox
Safari
opacity11212

Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8.

Notes

  • Opacity affects the entire element, including its content.
  • Child elements inherit the parent's opacity effect.
  • Values must be between 0 and 1.
  • Frequently used with hover effects and overlays.

Common Opacity Levels

Common Opacity Levels

css

opacity: 0.2;
opacity: 0.5;
opacity: 0.8;
opacity: 1;

Hover Effect Example

Hover Effect Example

css

img {
    opacity: 0.6;
}
img:hover {
    opacity: 1;
}

Creates a popular image-hover effect.

Opacity vs RGBA

RGBA Background Transparency

css

background-color: rgba(0, 122, 204, 0.5);

Only the background becomes transparent.

Element Opacity

css

opacity: 0.5;

The entire element becomes transparent.

Conclusion

The CSS Opacity property provides a simple way to create transparency effects for elements and images. By adjusting visibility levels, you can build modern interfaces, interactive hover effects, and visually appealing overlays with minimal code.

PreviousCSS FiltersNextClipping & Masking