How to set inner shadow on text in CSS (in webkit…)

Unlike the box-shadow property, inner-shadow does not support the inset attribute. The following code is NOT valid:

Which is a bummer, I really wanted to style the logo of my site in CSS and not use an image, font or SVG for it. But I came over a clever hack that solves the issue for us.

How it works

There are 5 steps that are needed to acheive this, and you can see the result of each of them below:

How it works:

  1. The normal style without any applied effects
  2. The text when a black shadow with opacity applied
  3. We hide the text the only thing visible is the shadow
  4. We set the background color to the color we want the text in
  5. We clip the background to the bounds of the text. This will make the shadow look like it is just on the inside of the text!


Background is a webkit specific property at this point.

UPDATE: Turns out it is tricky to feature test this unless you want to browsersniff. Modernizr has not yet found a good solution:

Happy coding!

Published by

Anders M. Andersen

Digital Project Manager and Front End Developer.