Contents
Manipulating CSS transparency
By using the opacity
property, you can define a custom CSS transparency level for an element:
The level of opacity or transparency in CSS applies to the whole element, including its text and other content.
Syntax requirements
To define CSS transparency for an element, follow the syntax example below:
opacity: alpha;
The alpha level is a unitless number in the range from 0.0
(full CSS transparency) to 1.0
(full CSS opacity). 1.0
is also the default value of this property.
- Easy to use with a learn-by-doing approach
- Offers quality content
- Gamified in-browser coding experience
- The price matches the quality
- Suitable for learners ranging from beginner to advanced
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
- A wide range of learning programs
- University-level courses
- Easy to navigate
- Verified certificates
- Free learning track available
- University-level courses
- Suitable for enterprises
- Verified certificates of completion
CSS transparency: alternatives
Another way to change the opacity for an element is using the filter property. In the example below, you can see how filtering can be used to set various levels of CSS background color opacity:
div {
background-color: #41caf4;
padding: 15px;
}
div.first {
opacity: 0.2;
filter: alpha(opacity=20); /* For IE8 and earlier */
}
div.second {
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}
div.third {
opacity: 0.8;
filter: alpha(opacity=80); /* For IE8 and earlier */
}
You can also define the color you want to use in RGBA or HSLA values. The A in the acronyms stand for the alpha channel which is defined as the fourth value. See how it affects the CSS background color opacity in the example below:
div {
background: rgb(80, 180, 90);
padding: 10px;
}
div.firstly {
background: rgba(80, 180, 90, 0.2);
}
div.secondly {
background: rgba(80, 180, 90, 0.4);
}
div.thirdly {
background: rgba(80, 180, 90, 0.8);
}
You can change transparency using JavaScript as well:
function LearnFunction(z) {
// Return the selected option's text
var opacityL = z.options[z.selectedIndex].text;
var ell = document.getElementById("p1");
if (ell.style.opacityL !== undefined) {
ell.style.opacityL = opacityL;
} else {
alert("This example is unsupported!");
}
}