<commit_before>---
title: Background Opacity
---
## Background Opacity

The opacity property specifies the opacity/transparency of an element, that is, the degree to which the content behind the element is visible.

The opacity property can take a value from 0.0 - 1.0. The lower the value, the more the transparency:

Find more details <a href='https://www.w3schools.com/css/css_image_transparency.asp' target='_blank' rel='nofollow'>here</a>

You can choose up to what extent you want to make the element transparent.
You have to add the following CSS property to achieve the transparency levels.

**Fully Opaque**
```css
.class-name {
  opacity:1;
}

OR

.class-name {
  opacity:1.0;
}
```
**Translucent**
```css
.class-name {
  opacity:0.5;
}
Opacity value can be anything between 0 and 1;
```
**Transparent**
```css
.class-name {
  opacity:0;
}

OR

.class-name {
  opacity:0.0;
}
```
Alternatively you can use a transparent rgba value like this:
```css

.class-name{
  background-color: rgba(0,0,0,.5);
  }
 ```
The example above sets the background to be black with 50% opacity. The last value of an rgba value is the alpha value. An alpha value of 1 equals 100%, and 0.5 (.5 for short) equals 50%. We use this method to add transparency to an element without affecting the content inside.

#### Some Info
Using the rgba value is most preferable when the background has content like text compared to using the background-color property then going on to use the opacity property. First, it's shorter and second, it eliminates the problem of having the content's transparency change with that of its background, if it's something you do not want.

[A codepen example to show background opacity ranges](https://codepen.io/lvcoulter/full/dVrwmK/)


#### More Information:
For more information visit [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/opacity)
[Opacity CSS property at CSS-Tricks](https://css-tricks.com/almanac/properties/o/opacity/)

Browser support: <a href= 'https://caniuse.com/#search=opacity' target= '_blank' rel= 'nofollow'>caniuse</a>
<commit_msg>Adding Transparent Hover Effect code (#21179)<commit_after>---
title: Background Opacity
---
## Background Opacity

The opacity property specifies the opacity/transparency of an element, that is, the degree to which the content behind the element is visible.

The opacity property can take a value from 0.0 - 1.0. The lower the value, the more the transparency:

Find more details <a href='https://www.w3schools.com/css/css_image_transparency.asp' target='_blank' rel='nofollow'>here</a>

You can choose up to what extent you want to make the element transparent.
You have to add the following CSS property to achieve the transparency levels.

#### Fully Opaque
```css
.class-name {
  opacity:1;
}

OR

.class-name {
  opacity:1.0;
}
```

#### Translucent
```css
.class-name {
  opacity:0.5;
}
Opacity value can be anything between 0 and 1;
```

#### Transparent
```css
.class-name {
  opacity:0;
}

OR

.class-name {
  opacity:0.0;
}
```
Alternatively you can use a transparent rgba value like this:
```css

.class-name{
  background-color: rgba(0,0,0,.5);
  }
 ```
The example above sets the background to be black with 50% opacity. The last value of an rgba value is the alpha value. An alpha value of 1 equals 100%, and 0.5 (.5 for short) equals 50%. We use this method to add transparency to an element without affecting the content inside.


#### Transparent Hover Effect
The opacity property is often used together with the **:hover** selector to change the opacity on mouse-over:

```
img {
    opacity: 0.5;
    filter: alpha(opacity=50);
}

img:hover {
    opacity: 1.0;
    filter: alpha(opacity=100);
}
```

#### Some Info
Using the rgba value is most preferable when the background has content like text compared to using the background-color property then going on to use the opacity property. First, it's shorter and second, it eliminates the problem of having the content's transparency change with that of its background, if it's something you do not want.


[A codepen example to show background opacity ranges](https://codepen.io/lvcoulter/full/dVrwmK/)


#### More Information:
For more information visit [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/opacity)
[Opacity CSS property at CSS-Tricks](https://css-tricks.com/almanac/properties/o/opacity/)

Browser support: <a href= 'https://caniuse.com/#search=opacity' target= '_blank' rel= 'nofollow'>caniuse</a>

{'fraction_non_alphanumeric': 0.10942045200268516, 'fraction_numerical': 0.0165585142089953, 'mean_word_length': 4.246478873239437, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6977784', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1312, 'n_words': 555}