Open two components from the same page and their shadows disagree. A card drops its shadow straight down, a dropdown throws one to the left, and a button looks lit from the right. Nothing is broken and no CSS rule is violated, yet the page feels assembled rather than designed. The eye reads shadows as evidence about light, and contradictory evidence makes the whole scene harder to believe.

Shadow direction is not decoration. It is a claim about where the light in the scene comes from, and every element on the page has to make the same claim. This guide explains how the two offsets in a CSS box-shadow encode a light direction, how to choose one direction for a whole page, and how to build it with the free Box Shadow Generator on Ovatly, which assembles the declaration in your browser.

Contents

  • Quick answer
  • A shadow always falls opposite the light
  • The two offsets are a compass
  • Pick one light direction for the whole page
  • How to set a consistent shadow direction, step by step
  • Worked example: overhead light, then angled light
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

A shadow falls on the opposite side of its light source, so direction is set by the two offsets. A positive vertical offset drops the shadow below the element, which reads as light from above; a positive horizontal offset pushes it to the right, which reads as light from the left; negative values reverse each one. Pick a single light direction for the page, most interfaces imply light from above, then give every element offsets with the same signs. In the Box Shadow Generator, the example shadow with a 0px horizontal offset and an 8px vertical offset is light directly overhead: the shadow pools straight underneath.

A shadow always falls opposite the light

Put a cup on a table near a window and the shadow stretches away from the window. Move the cup under a ceiling light and the shadow pools beneath it. The object never decides where its shadow goes; the light does, and the shadow always lands on the far side.

Screen design borrows this physics wholesale. Nobody studies a button to work out where its light comes from, but the visual system registers the direction anyway. One consistent direction is the cheapest realism a page can buy, because it costs nothing but agreement.

The two offsets are a compass

A box-shadow layer carries a horizontal offset and a vertical offset, and together they point from the element toward its shadow, away from the light.

The vertical offset is the north-south needle. Positive values move the shadow down, so the light reads as above the element. Negative values move it up, so the light reads as below. The horizontal offset is the east-west needle. Positive values move the shadow right, so the light reads as coming from the left; negative values move it left, so the light reads as coming from the right.

Blur and spread do not steer. Blur softens the shadow's edge, and it cannot be negative; spread grows or shrinks the shadow's shape, and it may be negative. Layers need the same care: the generator allows up to four layers per element, each with its own offsets, and a natural shadow pairs a tight darker core with a wide soft halo. Both layers must point the same way, or the element argues with itself.

Pick one light direction for the whole page

Decide the direction before styling anything, and write it down as a pair of signs: horizontal zero or positive, vertical positive, for example. Most interfaces imply light from above, because that is where light comes from in rooms. A slight sideways lean is fine, as long as it is the same lean everywhere.

Elevation then changes size, never direction. A resting card sits close to the surface, so it gets small offsets and a modest blur. A modal floats higher, so it gets larger offsets and a wider blur. Both point the same way. Menus, tooltips, sticky headers and buttons all follow the same rule: one page, one sun.

How to set a consistent shadow direction, step by step

  1. Open the Box Shadow Generator and settle the page's light direction first, before touching a control: directly overhead, or overhead leaning from one side.
  2. Set the horizontal offset to match: 0 for directly overhead, a small positive value if the light leans from the left, a small negative value if it leans from the right.
  3. Set the vertical offset positive so the shadow falls below the element, then choose a blur that softens the edge without washing out the direction.
  4. If you add a second layer for the core-and-halo look, give it the same offset direction as the first layer, with smaller offsets and blur for the tighter, darker core.
  5. Copy the declaration, then check every other shadowed element against the same pair of signs, using the generator's preview to confirm each one reads as the same light.

Worked example: overhead light, then angled light

Start with the generator's example layer: horizontal offset 0px, vertical offset 8px, blur 24px, spread 0px, color #000000 at 20% opacity, which produces this declaration:

box-shadow: 0px 8px 24px 0px rgba(0, 0, 0, 0.2);

The horizontal offset of zero means no sideways lean: the light is directly overhead, like a ceiling light over a desk. Now angle the light to the upper left. The shadow slides down and to the right, which in offsets means a positive horizontal value alongside the positive vertical one, for example:

box-shadow: 6px 10px 24px 0px rgba(0, 0, 0, 0.2);

The exact numbers are a designer's call; the signs are the commitment. If a header copied from another project then arrives with a horizontal offset of -4px, the page suddenly has two light sources. Nothing errors, but the scene stops agreeing with itself. Flipping that one sign back is the whole fix.

Limitations and honest tradeoffs

The generator builds one declaration at a time and previews one element at a time. It cannot audit your stylesheet, compare components, or enforce a house direction; that discipline stays with you.

Direction also gets harder to read as blur grows. A very soft shadow communicates height more than direction, which is fine for a floating panel and unhelpful when diagnosing a mismatch. And an inset shadow, drawn inside the element's border, plays by different visual rules: it suggests a pressed or carved surface, not an external light, so it sits outside this one-direction system.

Common mistakes

  • Mixing directions across components. One card lit from the left and one from the right is the classic failure. Audit the signs, not the sizes.
  • Judging direction with a huge blur. The shadow becomes a fog. Set direction with a modest blur, then soften.
  • Giving each layer its own direction. A core pointing down-left under a halo pointing down-right looks like a smudge, not a shadow.
  • A negative vertical offset by accident. The shadow climbs above the element and the light reads as coming from the floor.
  • Copying shadows from other sites. A borrowed shadow imports a borrowed light direction, which rarely matches yours.

FAQs

Which offset moves the shadow sideways? The horizontal offset. A positive value moves the shadow to the right, which reads as light coming from the left. A negative value moves it to the left, which reads as light coming from the right.

What does a horizontal offset of 0 with a vertical offset of 8px mean? The shadow sits directly below the element, so the light reads as directly overhead. That is the safest default, because windows, ceiling lights and the sun at midday all put the light above the things they light.

Can a shadow point up instead of down? Yes. A negative vertical offset places the shadow above the element, which reads as a light source below it. It can suit a glowing panel or a stage effect, but on an ordinary page it usually looks wrong, because nothing else is lit from below.

Does blur change the direction of a shadow? No. Blur only softens the edge of the shadow; the two offsets decide where it falls. A very large blur can make the direction harder to read, which is why direction is easier to judge with a modest blur first.

Is my design uploaded anywhere when I use the generator? No. The generator runs in your browser and builds the declaration locally. You copy the finished box-shadow value into your own stylesheet, and nothing about your design leaves your device.

Conclusion

Consistent shadows come from one decision made once: where the page's light lives. After that, every offset is just arithmetic with the same signs, and the Box Shadow Generator turns the decision into a declaration you can paste. When an element needs to hover above the page rather than rest on it, our guide to creating a floating effect for a modal or popup scales the same shadow up without changing its direction. For more guides in this series, see our Website and Webmaster Tools guides, which pair each technique with the free tool that performs it.

References