Transparent DIV SPAN for all browsers, Firefox, Opera, Safari, Chrome, Internet Explorer

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.

32 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!

  16. Dartkrs says:

    Simple and it works. Thank you very much, it solved my problem completely.

  17. Nazar says:

    Great…

  18. Bhanu says:

    Excellent, thats really a great post!!!

  19. rizomer says:

    this opens horizons. thanks.

  20. Excellent idea, Thanks a lot.

  21. Greg J says:

    Hi,

    Everyone seems to be having success getting this to work in IE. I’m using IE8 and it’s not working for me. Here is the css I am using for the transparent div:

    #feedscroller {
    display: block;
    background: #fff;
    overflow: scroll;
    width: 598px;
    height: 390px;
    border: 1px solid #c6cdb4;
    opacity: 0.5;
    filter:alpha(opacity=50);
    -moz-opacity: 0.5;
    }

    any ideas anyone?

  22. Vince says:

    Does anyone know what the performance difference is using this method over using a 1 pixel semi-transparent png?

  23. Nic Hanafey says:

    Hey there,

    Thanks so much! This worked perfectly- now my page works in IE, Firefox and Chrome :)

    Cheers

  24. Shelly Caldwell says:

    Remember you have to have a width (‘auto’ won’t work) for this to work in IE7

  25. wayne says:

    Hey everyone. I love this. I have one more question: How do I get just the background to be transparent. Right now, EVERYTHING associated with the element is transparent.

    #main {
    background:#000000;
    filter:alpha(opacity=50);
    -moz-opacity: 0.5;
    opacity: 0.5;
    }

    Content

    The container is transparent, and so is the text and that is my problem. Any help would be great, thanks.

  26. donjoe says:

    Apparently the only way is to move your content outside the transparent container (HTML-wise) and then use trickery to make it _visually_ appear on top of the transparent container when the page is rendered. (One suggested trick has something to do with negative margin values in CSS.)

  27. anish says:

    thanks Coding Day !!! it works well in IE hell
    and also thanks Shelly Caldwell ! for giving valuable tip about the width property.

  28. Saikat says:

    #transparency {filter: alpha(opacity=55); -moz-opacity: .55; background-color:#EEE; position:absolute; top:450px; left:110px; }

  29. santosh says:

    Thank you so much for this code……..it’s working…..

Leave a Reply