Posted almost 8 years ago. Visible to the public.

CSS: Emulate linear gradients with inset box shadows

Why is this useful?

  • You can have a background image on the same element, overlaying it with a transparent gradient.
  • Since you are probably using gradients to give an element a glossy or three-dimensional feel, box shadows work much better for this. This is because linear gradients always stretch to the full size of the element (which can grow with user input), while a natural shine or shadow only highlights a fixed size on the top or bottom.
  • Browser support for linear gradients is a mess. I avoid using them. In particular, IE 7-9 can only emulate gradients with a weirdo DirectX filter directive which has issues.


Take this gradient from top to bottom:

background-image: linear-gradient(top, red 0%, bottom 100%);

You can emulate this with a box shadow (assuming that the element is 50px high):

background-color: blue box-shadow: 0 50px 50px -50px red


Real browsers and IE9+.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Henning Koch
Last edit:
over 7 years ago
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more