Posted over 9 years ago. Visible to the public.

CSS: Emulate borders with inset box shadows

When is this useful?

  • When both parent and child elements have borders, with this technique you don't get two borders (which looks ugly). This is because child elements are rendered over inset box shadows, not inside inset box shadows.
  • You want more than one border on the same element. You can have as many inset box shadows on the same element as you like, e.g. allowing you to make a picture-frame-like border.


Remember the attribute list of box-shadow is x-offset, y-offset, blur radius, shadow radius. You can emulate hard, solid borders by having a blur radius of zero. You can show or hide individual border sides by offsetting or scaling the shadow radius:

| With border | With box-shadow |
| border: 1px solid red | box-shadow: inset 0 0 0 -1px red |
| border-top: 1px solid red | box-shadow: inset 0 1px 0 0 red |
| border-right: 1px solid red | box-shadow: inset -1px 0 0 red |
| border-bottom: 1px solid red | box-shadow: inset 0 -1px 0 0 red |
| border-left: 1px solid red | box-shadow: inset 1px 0 0 red |


  • Box shadows render slower than borders.


Real browsers and IE9+ understand box-shadow Archive . Avoid hacks like CSS3 PIE for older IEs because they only look good on paper.

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Henning Koch
Last edit:
over 8 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