Change background opacity without affecting text

I see this being used in websites across the net and used in plugins for various common free CMS’ however I have never needed to set the set the background opacity without effecting child elements. It is surprising quite how much incorrect information is floating around on the internet which would results in everything being opaque.

Finally found an example which told me what I needed to know. Tested in the latest versions of FireFox, Chrome and Internet Explorer on the PC; also in Firefox, Safari and Chrome on the Mac.


Red background set to 50% opacity and white text

Here is the content.
Background should grow to fit.


Manage background opacity without effecting text


<style type="text/css">
       /* These three lines are for transparency in all browsers. */
       filter: alpha(opacity=50);
<div class="container">
   <div class="content">
       Here is the content. <br />
       Background should grow to fit.
   <div class="background"></div>


How does it work?


  • Main container is set to relative position. It contains the div with the opacity set and a div with the content you wish not to be affected;
  • The div with the opaque background is absolutely positioned to top left. Because the containing div has a relative position the div will align itself to the top left of the containing div and not the top left of the page;
  • The div with the copy and text is set to effectively float above the translucent background.



This solution comes thanks to Gorkem Pacaci from a StackOverflow answer

Comments: 17

  • marcus
    October 29, 2012 4:57 pm

    Thanks for the tip it works but it will not let me access links in the content div. Any tips on how to get that working?

  • Chuck
    November 7, 2012 9:17 pm

    YES! Thank you.

  • Sandra
    November 30, 2012 1:41 pm

    Thank you! very useful article! it helped me a lot:)

  • Farah
    March 14, 2013 8:43 pm

    THANK YOU SO MUCH!!!! I’ve been looking for hours and hours trying to figure this out on the web, and don’t understand why google hates me, but I keep getting crap info, and html/css split into two parts and I am a total noob with coding!

    I could kiss you right now !! <3 YAY

  • Farah
    March 16, 2013 4:53 am

    hehe thanks! yes i tweaked it a little to allow scrolling and it also didn’t bite me 😀 you’re a life saver thanks so much!

  • Jaye
    May 20, 2013 11:57 am


    I have an issue with a template im using on blogger.. ive got everything running how i like it, and managed to add a fixed test backbround image.. however i have a WHITE STRIPE along the top of the screen that i want to get rid of or add opacity to it so as i JUST DONT WANT

    Help Appreciated.. have a look.. HELP..

  • Robin
    July 30, 2013 3:22 pm

    >>Thanks for the tip it works but it will not let me access links in the content div. Any tips on how to get that working?

    I have the same problem. As soon as the opacity is set to lower than 1 no links are working.

  • amrit
    August 9, 2013 4:31 pm

    This is a great post, loved it..
    I want to increase the opaqueness of the watermark around my text.

  • Murphy
    September 3, 2014 7:14 am

    Good solution, but it can be done in the one single line of code! Just use semi-transparency like here:

    Anyway, your solution will work in old versions of IE.

Post a Comment