This is where I write about website development, search engine optimization and my thoughts on various issues. If you are interested in a particular topic, then check the section under categories on the right. I hope you will find something here that might interest you. So, sit back and read along.

How to Make the Background of a Div Semi-Transparent?

October 31st, 2005

If you look below, the light gray div over the darker one is transparent. As a result, the content inside the darker gray div shows up through the light gray div over it. This capability can enable us to create really attractive designs. It’s really simple to do it. If you are interested, just read along.

This is opaque div. This is opaque div. This is opaque div. This is opaque div. This is opaque div. This is opaque div. This is opaque div.

This is opaque div. This is opaque div. This is opaque div. This is opaque div. This is opaque div. This is opaque div. This is opaque div.

This is opaque div. This is opaque div. This is opaque div. This is opaque div. This is opaque div. This is opaque div. This is opaque div.

Step 1:

In the HTML code, give a unique ID to the div with transparent background such as below:

<div id="transparency"></div>

Step 2:

In the stylesheet, define the style for this ID such as below:

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

Points to note:

*You do need to absolutely position the transparent div over the opaque one.

*filter: alpha(opacity=55); This one works in IE. The number 55 implies 55% of opacity. You may want to adjust this number depending on the amount of transparency desired.

*-moz-opacity: .55; This one works in FireFox. The number 55 implies 55% of opacity. Once again, you may want to adjust this number depending on the amount of transparency desired.

I’ve no clue how to make it work in Safari and Opera. If you do, please let me know.

Related Articles:

19 Responses to “How to Make the Background of a Div Semi-Transparent?”

  1. janbfe Says:

    A very good article i really gain something from here.

  2. dalinar Says:

    informative, and to-the-point. Instructions basic and simple enough for a beggining coder.

    One thing to add for those beginners though:
    you can put *- filter:alpha(opacity=55); -* into any style block, cascading, or inline.
    *- Works Fine -*

    *~- Tony

  3. Sarfaras Says:

    Very good article.. very informative and so simple… Really useful…

  4. minky Says:

    Hi… this is my page on Yahoo360! I want to make my module background opaque light gray like the blast background above(so that the background image shows through) but I donĀ“t know how. I can only make it transparent as you see. Could you please help me? Thanks much!!

  5. minky Says:

    http://360.yahoo.com/profile-eqIrIIsmc684zi27NXzxZqb4LA–?cq=1 is my page. Thank you!

  6. Someone Says:

    It works for Mozilla, but how can I make transparent div in internet explorer???

  7. Rajiv Ranjan Says:

    Article was really helpful. Did we find the varible for Safari and Opera. Immediate help is required here.

  8. Rajiv Ranjan Says:

    One quick question here. Can we have the following structure.

    where div_Label is 10% transparent and div_Img 88% transparent. If yes then how following is the style setting I made.

    div#div_Label{

    background-color:#345671;
    color:#ffffff;
    width:300px;
    height:200px;
    position:relative;
    left:20px;
    top:20px;
    filter: alpha(opacity=44);
    -moz-opacity: .44;

    }

    div#div_Img{
    filter: alpha(opacity=99);
    -moz-opacity: .99;
    width:150px;
    height:100px;
    position:relative;
    left:20px;
    top:20px;

    }

  9. Rajiv Ranjan Says:

    –>

  10. Rajiv Ranjan Says:

    div id=div_Label
    div id=div_Img
    img src………
    div
    div

    I guess wordpress here does not allow HTML tags so writing the above code.

  11. Arif Says:

    its really nice. very simple but helpfull.

  12. nidhin Says:

    nice and is their is any way to get window size

  13. joey Says:

    Safari seems to respond to “opacity: x” where x is anything between .1 and 1; example: “opacity: .7″

  14. Rakesh Says:

    Hi!

    Its nice to have the fade over the text but what if you want just the background of the div to fade but not the text?

    Ideally i want ot write as much content as i like and the div will scroll according to whatever is typed but the fade will continue to fade ni the background …

    possible??

    Thanks

    Rakesh

  15. Shruti Says:

    It’s the background that will fade and not the text. As an example, look here: http://www.soxx.com/
    Try it yourself.

  16. Breno Lewroy Says:

    Very good!
    Simple and direct.

  17. Chris Says:

    I would also like to know how to make the text non-translucent while making the container div translucent. The example makes them *both* translucent. Shruti is wrong.

  18. gaby Says:

    im a beginner coder…like SERIOUSLY a newbie…and i dont get it…xD :( ….why dont i understand it? T_T

  19. pumpkinskull Says:

    using all three variables, filter:alpha(opacity=##) and -moz-opacity:.## and opacity:.## works for pretty much everything, I believe.

    To make the text non-transparent, simply put the text in another div atop of the first one, this div having no background variable at all. gets messy, you’ll need to use positioning, but it works.

Leave a Reply