[フレーム]

CSS Tutorial

CSS HOME CSS Introduction CSS Syntax CSS Selectors CSS How To CSS Comments CSS Errors CSS Colors CSS Backgrounds CSS Borders CSS Margins CSS Padding CSS Height/Width CSS Box Model CSS Outline CSS Text CSS Fonts CSS Icons CSS Links CSS Lists CSS Tables CSS Display CSS Max-width CSS Position CSS Z-index CSS Overflow CSS Float CSS Inline-block CSS Align CSS Combinators CSS Pseudo-classes CSS Pseudo-elements CSS Opacity CSS Navigation Bars CSS Dropdowns CSS Image Gallery CSS Image Sprites CSS Attr Selectors CSS Forms CSS Counters CSS Website Layout CSS Units CSS Specificity CSS !important CSS Math Functions CSS Performance CSS Accessibility

CSS Advanced

CSS Rounded Corners CSS Border Images CSS Backgrounds CSS Colors CSS Color Keywords CSS Gradients CSS Shadows CSS Text Effects CSS Web Fonts CSS 2D Transforms CSS 3D Transforms CSS Transitions CSS Animations CSS Tooltips CSS Image Styling CSS Image Centering CSS Image Filters CSS Image Shapes CSS object-fit CSS object-position CSS Masking CSS Buttons CSS Pagination CSS Multiple Columns CSS User Interface CSS Variables CSS @property CSS Box Sizing CSS Media Queries CSS MQ Examples

CSS Flexbox

Flexbox Intro Flex Container Flex Items Flex Responsive

CSS Grid

Grid Intro Grid Columns/Rows Grid Lines Grid Container Grid Item CSS @supports

CSS Responsive

RWD Intro RWD Viewport RWD Grid View RWD Media Queries RWD Images RWD Videos RWD Frameworks RWD Templates

CSS SASS

SASS Tutorial

CSS Examples

CSS Templates CSS Examples CSS Editor CSS Snippets CSS Quiz CSS Exercises CSS Website CSS Syllabus CSS Study Plan CSS Interview Prep CSS Bootcamp CSS Certificate

CSS References

CSS Reference CSS Selectors CSS Combinators CSS Pseudo-classes CSS Pseudo-elements CSS At-rules CSS Functions CSS Reference Aural CSS Web Safe Fonts CSS Animatable CSS Units CSS PX-EM Converter CSS Colors CSS Color Values CSS Default Values CSS Browser Support

CSS Opacity


CSS Image Opacity

The opacity property specifies the opacity/transparency of an element.

The opacity property can take a value from 0.0 - 1.0:

  • 0.0 - The element will be completely transparent
  • 0.5 - The element will be 50% transparent
  • 1.0 - Default. The element will be fully opaque
Forest

opacity 0.2

Forest

opacity 0.5

Forest

opacity 1.0
(default)

Example

img {
opacity: 0.5;
}
Try it Yourself »

Opacity and :hover

The opacity property is often used with :hover to change the opacity on mouse-over:

Northern Lights
Mountains
Italy

Example

img {
opacity: 0.5;
}

img:hover {
opacity: 1.0;
}
Try it Yourself »

Reversed Hover Effect

Here is an example of reversed hover effect:

Northern Lights
Mountains
Italy

Example

img:hover {
opacity: 0.5;
}
Try it Yourself »


Transparent Boxes

When using the opacity property to add transparency to the background of an element, all child elements inherit the same transparency. This can make the text inside a transparent element hard to read:

opacity 1

opacity 0.6

opacity 0.3

opacity 0.1

Example

div {
opacity: 0.3;
}
Try it Yourself »

Transparency using background-color

To NOT apply the transparency to child elements, you can use the background-color property with an RGBA value.

RGBA color values are an extension of RGB color values with an alpha channel - which specifies the opacity for a color.

An RGBA color value is specified with: rgba(red, green, blue, alpha). Where the alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque).

Tip: You will learn more about RGBA Colors in our CSS Colors Chapter.

The following example sets the opacity for the background color and not the text:

100% opacity

60% opacity

30% opacity

10% opacity

Example

div {
background: rgba(4, 170, 109, 0.3) /* Green background with 30% opacity */
}
Try it Yourself »

Text in Transparent Box

This is some text that is placed in the transparent box.

Example

<html>
<head>
<style>
div.background {
background: url(klematis.jpg) repeat;
border: 2px solid black;
}

div.transbox {
margin: 30px;
background-color: rgba(255, 255, 255, 0.6);
border: 1px solid black;
}

div.transbox p {
margin: 5%;
font-weight: bold;
color: #000000;
}
</style>
</head>
<body>

<div class="background">
<div class="transbox">
<p>This is some text that is placed in the transparent box.</p>
</div>
</div>

</body>
</html>
Try it Yourself »

Example explained

  • Create a <div> element (class="background") with a background image, and a border.
  • Create another <div> (class="transbox") inside the first <div>.
  • The <div class="transbox"> have a 0.6 transparent background color, and a border.
  • Inside the transparent <div>, we add some text inside a <p> element.


CSS Property

Property Description
opacity Sets the opacity level for an element

Track your progress - it's free!
×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

FORUM ABOUT ACADEMY
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

AltStyle によって変換されたページ (->オリジナル) /