A modal can be perfectly centered and still look wrong: pasted onto the page instead of floating above it. The difference is rarely the backdrop or the border. It is the shadow. A resting card casts a short, tight shadow. A modal hangs between the reader and the page, and its shadow has to report that distance, or the eye refuses to believe the element has left the surface.

Floating is not a style, it is a measurement. This guide explains how offset, blur and opacity combine to express height, and how to build it with the free Box Shadow Generator on Ovatly, which assembles a shadow layer by layer and hands you the declaration to copy.

Contents

  • Quick answer
  • Floating is distance, written in pixels
  • Two layers: a core and a halo
  • Opacity decides height versus dirt
  • How to build a floating modal shadow, step by step
  • Worked example: from a resting card to a floating modal
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

To make a modal float, give it more distance than a resting element: a larger vertical offset and a larger blur, built as two layers, a tight darker core and a wide soft halo, with opacity kept modest. The resting baseline from the Box Shadow Generator example is a 0px horizontal offset, an 8px vertical offset, a 24px blur and 20% opacity, producing box-shadow: 0px 8px 24px 0px rgba(0, 0, 0, 0.2);. A modal scales those numbers up: more drop, more softness, same light direction, same construction.

Floating is distance, written in pixels

Watch a real shadow as an object lifts off a table. Two things happen: the shadow moves further from the object, and its edge dissolves. A sheet of paper casts a crisp shadow near its outline. Raise the paper a metre and the shadow sits below it, larger, paler and soft.

The vertical offset is the first half of that report: it sets how far below the element the shadow lands, and a bigger gap reads as a bigger height. The blur radius is the second half: it softens the shadow's edge, and the higher the element, the softer the edge should be. Offset without blur looks like a hard copy of the box. Blur without offset looks like a glow. Height needs both, growing together.

Two layers: a core and a halo

One layer can suggest height, but a natural shadow is two shadows at once. Under an object there is a tight, darker core where the light is fully blocked. Around it spreads a wide, faint halo where the light is partly blocked. The generator's layer system, up to four layers per element, exists to reproduce this pairing.

The core layer takes the smaller offset and blur with stronger opacity: it grounds the element and stops it looking like it is drifting. The halo layer takes the larger offset and blur at lower opacity: it is the layer that sells the gap between the modal and the page. Build the core first so the modal stays anchored, then widen the halo until the height reads.

Opacity decides height versus dirt

Opacity is where floating effects fail. The instinct is to make a higher element cast a stronger shadow, so the opacity goes up, and the result is a dark rim around the modal. That rim reads as grime, or as a thick border, because a real shadow spreads its darkness over a wider area as an object rises. The total darkness stays similar; it just covers more ground, more thinly.

Keep each layer modest. The resting baseline works at 20% opacity, and a floating version wants the same neighbourhood, sometimes less on the halo, never a jump to 40 or 50%. If the shadow looks dirty, the fix is never more darkness. It is more blur and less opacity.

How to build a floating modal shadow, step by step

  1. Open the Box Shadow Generator and start from the resting baseline: horizontal offset 0px, vertical offset 8px, blur 24px, spread 0px, black at 20% opacity.
  2. Raise the vertical offset and the blur together until the preview looks lifted rather than resting. Keep the horizontal offset at 0 unless your page's light leans sideways, so the direction matches the rest of the page.
  3. Add a second layer as the core: smaller offset and blur than the halo, higher opacity. Leave the first layer as the wide, soft halo.
  4. Check the opacity on both layers. If either reads as a dark edge instead of a soft presence, lower it and compensate with more blur.
  5. Copy the declaration into your modal's CSS, then view the page: the preview shows one element, and the float only counts if it convinces against your content.

Worked example: from a resting card to a floating modal

The baseline is the generator's example, a card resting on the page:

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

One layer, an 8px drop, a 24px blur, 20% opacity. Now scale it up. The scaled values below are one designer's call within the pattern, not a preset: the vertical offsets roughly double and triple, the blurs widen with them, and the opacities stay at or below the baseline so extra size does not turn into extra darkness.

box-shadow: 0px 12px 16px 0px rgba(0, 0, 0, 0.18),
  0px 28px 48px 0px rgba(0, 0, 0, 0.16);

The first layer is the core: a 12px drop and a 16px blur keep it tight and defined. The second is the halo: a 28px drop with a 48px blur spreads wide and faint. Both keep a horizontal offset of 0, so the light stays directly overhead, the same direction a resting card would use. Tune the numbers to your modal's size; keep the relationship between them.

Limitations and honest tradeoffs

The generator produces the box-shadow declaration and nothing else. The dimmed backdrop behind most modals is a separate element, and no shadow setting in the generator creates it. The preview shows a single element on a plain background, so it cannot tell you how the shadow will sit over photographs, colored panels or busy content underneath the modal. That judgement has to happen in the page itself.

There is a ceiling: four layers maximum, and a shadow is still one color per layer with one opacity. Very large blurs can cost rendering effort on low-powered devices when a modal animates, which is a reason to keep the halo as small as still convinces.

Common mistakes

  • Raising opacity instead of blur. The shadow turns into a dark rim and the modal looks dirty, not high.
  • One giant layer doing both jobs. A single huge blur has no core, so the modal looks like it is floating in fog.
  • Forgetting the direction. A modal whose shadow leans left while every card leans down breaks the page's light source.
  • Using an inset shadow. Inset draws inside the border and reads as pressed in, the exact opposite of floating.
  • Copying a shadow from a larger or smaller element. Shadow scale should follow the element's size and height, not a screenshot.

FAQs

How is a modal shadow different from a card shadow? It is the same construction with more distance: a bigger vertical offset, a wider blur, and usually a second layer. The resting baseline in the generator's example is a 0px horizontal offset, an 8px vertical offset and a 24px blur at 20% opacity; a modal scales those numbers up.

Why does my modal shadow look like dirt around the edges? The opacity is too high or the blur too small for the offset, so the shadow hugs the box as a dark rim. Lower the opacity, widen the blur, and let a soft halo layer carry the effect instead of one strong layer.

Should a modal shadow use an inset layer? No. An inset shadow is drawn inside the element's border, which makes the surface look pressed in or carved out. A floating modal needs the opposite: shadows outside the box, falling on the page beneath it.

How many layers does a good floating shadow need? Two is enough for most modals: a tight core that grounds the element and a wide halo that suggests the gap beneath it. The generator allows up to four layers, but extra layers add visual weight faster than they add realism.

Does the generator change my page or upload anything? No. It runs in your browser and only produces the box-shadow declaration. You copy the value into your own stylesheet, and nothing about your design leaves your device.

Conclusion

A floating modal is a resting card with more air under it: larger offsets, wider blur, two layers, restrained opacity, and the same light direction as everything on the page. The Box Shadow Generator lets you scale the baseline until the height reads, then hands you the declaration to paste. If you have not settled the page's light direction yet, our guide to matching shadow direction to a light source covers that decision first. 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