Transparent DIV SPAN for all browsers

To make an HTML element transparent. Just use these css elements in your css class.  filter, moz-opacity, opacity.

Internet Explorer uses filter and firefox uses moz-opacity.

.transparent
{
   filter:alpha(opacity=60); 
   -moz-opacity: 0.6; 
   opacity: 0.6; 
}

<div class="transparent">A transparent div.
</div>

The opacity value changes from 0 to 1.

17 Comments

  1. Cale says:

    excellent bit of info there it really helped to make transparent divs that work on both firefox and IE thankyou :)

  2. Hi, good short tutorial. What is the solution when I need the text within the DIV to be 100% opaque over, let’s say, a 60% transparency DIV? As far as I could see testing, the text gets faded in the same scale as the div even if I put a 100% opaque tag inside the DIV. Thanks.

  3. Peri says:

    Wow, it works, excellent!
    Do you mind if I share and translate this to another language on my blog?

    Many thanks :)

  4. Can says:

    You are very welcome indeed. :)

  5. Hebbarus says:

    Good stuff! Just what I was looking for. Works great!

  6. Johnny Russell says:

    What I do if I want to make a div with a transparent background but have text show up opaque is I make two divs with identical properties. Then, I take one div, put it behind the other, and make it transparent. Then, I put all of my content in the other div. Therefore, one div is used for content and is opaque; the other div is used for the background and is transparent. That’s just what I do. There may be a better way.

    Que te vaya bien.

  7. riri says:

    thanks, simple & easy, it’s works!

  8. Chris says:

    Great example. I’d only note that Firefox now simply supports “opacity”, so you don’t have to use “-moz-opacity” anymore.

  9. Streusel says:

    Works, but IE6 blocks “filter:alpha(opacity=60);” and shows a yellow bar so you manually have to enable it to get the visual effect… :(

    A tip to others: if you only want the bg transparent and not the contents, you better put a div just behind the div you are using where you apply a white semi-transparent background.

  10. lagreen says:

    it’s just what i need :) . thanx

  11. Jakov says:

    Thanks man! that I needed!!! Thanks again!

  12. jadeyaya says:

    Thank you for solving my IE problem.

  13. Robbie says:

    Thanks!

  14. jukarpenz says:

    thank u so much bro

  15. Kirill says:

    Thank you!

Leave a Reply