Last Updated on July 18, 2021 by Roshan Parihar
In this tutorial, learn how to Make Background Color Transparent using CSS. The short answer is: use the CSS color rgba()
or apply the CSS opacity
property that creates a transparent behavior to the selected element.
After applying the effect to the element, the back part of the background is still slightly visible to the viewer. This can be useful when you want to add text to the container. Let’s find out with the examples given below.
How to Make Background Color Transparent Using CSS RGBA()
You can use CSS RGBA()
color code to give a transparent background color. If you want to make the text background visible to the visitors to display the back image, the effect is useful to add look and feel to the element.
See the example below to add a background with transparent color with CSS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<style> .main-div{ background-image: url(../../images/nature.jpg); background-attachment: scroll; padding: 20px; } .transparent-bg{ background: rgba(255, 165, 0, 0.73); padding: 20px; color: #fff; text-align: center; font-size: 26px; } </style> <div class="main-div"> <div class="transparent-bg"> Transparent Background </div> </div> |
Output
The above example using the transparent color background to display the image. The image is behind the background of the parent div and the background is an inner div. You can change the size of the above content as per your requirements.
Apply Transparency Using CSS Opacity Property
You can also use the CSS opacity
property to apply transparency to the background. Its value can be from 0 to 1 and you have to add a value above 0 and below 1 for a transparent effect. The below example contains the same example as given in the previous section above.
The below example actually does not create a transparent background color. It uses the opacity property to make the above div slightly visible to the users.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<style> .main-divopc{ background-image: url(../../wp-content/uploads/2018/10/best-ide-text-editor.jpg); background-attachment: scroll; padding: 20px; } .transparent-bgopc{ background: orange; padding: 20px; color: #fff; text-align: center; font-size: 26px; opacity: 0.6; } </style> <div class="main-divopc"> <div class="transparent-bgopc"> Transparent Background </div> </div> |
Output
The above example contains the background image to the parent div. It also contains the inner div with content and inner text. One more thing you have to note here that if you use the opacity property, the text is also slightly visible to the viewers.
Transparency Background Color on hover Effect Using CSS
In addition to above all methods, you can also make a transparent background color only on hover using the rgba()
CSS color. The example uses the same CSS and div content and applies the effect on hover to the div element. See the example given below to check the hover effect:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<style> .main-divhover{ background-image: url(../../wp-content/uploads/2018/05/stop-accidentally-publish-post-wordpress.jpg); background-attachment: scroll; padding: 20px; } .main-divhover:hover .transparent-bghover{ background: rgba(255, 165, 0, 0.73) !important; } .transparent-bghover{ background: orange; padding: 20px; color: #fff; text-align: center; font-size: 26px; } </style> <div class="main-divhover"> <div class="transparent-bghover"> Transparent Background </div> </div> |
Output
You can hover over the above example to see the transparent background effect. It uses the CSS RGBA()
color property that applies when someone hovers over the above content.
You may also like to read
- How to Create Image Hover Overlay Effect Using CSS.
- How to change background transparency Without Affecting Child
I hope you like this post on how to apply opacity to the background color using CSS.
Also, if you want to get the video form of our tutorials, you can subscribe to our YouTube Channel to learn more.
I am in fact glad to read this blog posts which contains plenty of valuable data, thanks for
providing such statistics.