DEV Community

Cover image for "Drawing" with box-shadow
Dan Strandberg
Dan Strandberg

Posted on

3 2

"Drawing" with box-shadow

I like to share one "trick" or technique that I really like, it's one of those things that's good to have in the tool belt and I've found myself using it pretty often over the years.

The box-shadow property

When you think of box shadow, it's easy to only think of it as shadows on boxes, but it can do more. You can actually use it to draw in a sense.


Here we have two boxes, one is obviously using a box shadow, but the other one is as well.


You can "draw" on the outside:

.el {
    box-shadow: 
        0 0 0 3px red,
        0 0 0 8px green,
        0 0 0 10px blue;
}

or "draw" on the inside:

.el {
    box-shadow: 
        inset 0 0 0 3px red,
        inset 0 0 0 8px green,
        inset 0 0 0 10px blue;
}

You apply multiple box shadows to draw lines that overlap. So the above would result in a "border" of 3px red, 5px green, 2px blue and in this lies the power.


You can get really creative with this technique.

Like the tablet above, it has two HTML elements with psuedo ::before and ::after elements. Most of the layers are box-shadows. 🙂

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay