Search code examples
htmlcsswebkit

How to add semi-transparent highlight to text?


I am trying to figure out how to add some semi-transparent highlighting to text and have be able to change it's color. I have see it quite a bit lately and am wondering what would be the best way to go about it. So basically the highlight is like a selection highlight but being visible all of the time. An example of highlighted text

Can anyone help me out with this? Thanks.


Solution

  • It's done the same as normal highlighting, but with rgba.

    .highlighted {
        background-color: rgba(0,0,0,.5);
    }
    
    <span class="highlighted">This text is highlighted.</span>
    

    http://css-tricks.com/rgba-browser-support/