Free tool

Flutter BoxShadow generator

Design a shadow with a live preview, stack up to five layers, and copy the BoxDecoration code for your Container.

Flutter code

Container(
  width: 200.0,
  height: 140.0,
  decoration: BoxDecoration(
    color: Color(0xFFFFFFFF),
    borderRadius: BorderRadius.circular(16.0),
    boxShadow: [
      BoxShadow(
        color: Color(0x14000000),
        offset: Offset(0.0, 8.0),
        blurRadius: 24.0,
        spreadRadius: -4.0,
      ),
    ],
  ),
)

The preview uses the same blur maths as Flutter, so the shadow looks the same on a phone.

Why I built this

Most of the UI projects on my channel live or die by their shadows: a login card that floats off the background, a product tile that lifts when selected, a soft neumorphic button. Getting them right meant hot-reloading again and again to nudge a blur value by two pixels. CSS shadow generators exist, but copying their numbers into Flutter doesn’t give the same result, because Flutter blurs differently (more on that below). So I made a generator that previews shadows the way Flutter actually draws them.

How to use it

  • Start from a preset, for example Soft card or Material elevation 8.
  • Adjust the colour, opacity, offset, blur and spread of each shadow with the sliders, or type exact numbers.
  • Add up to five shadows. Real shadows look better with two: a small sharp one close to the box and a large soft one further away.
  • Set the box colour, corner radius and the background behind it so the preview matches your screen.
  • Copy the Container code, or just the boxShadow list, into your widget.

What each BoxShadow property does

  • color: the shadow colour, including its opacity. Keep black shadows light, usually 5–20%. A tinted shadow (a darker version of the box or background colour) looks more natural on coloured screens.
  • offset: how far the shadow moves. Offset(0, 8) moves it 8 pixels down, as if the light comes from above.
  • blurRadius: how soft the edge is. 0 gives a hard, solid shadow.
  • spreadRadius: grows (positive) or shrinks (negative) the shadow before the blur. A negative spread with a larger blur keeps the shadow under the box instead of around it, which is the trick behind most “soft card” designs.
  • blurStyle: BlurStyle.normal by default. Others, such as outer, are rarely needed for UI.

Why CSS shadow values look different in Flutter

Both use a Gaussian blur, but they convert the number you type into blur strength differently. CSS uses half the blur value. Flutter uses blurRadius × 0.57735 + 0.5 (from BoxShadow.convertRadiusToSigma). So blurRadius: 20 in Flutter is about as soft as 24px in CSS, and a shadow copied from a CSS tool looks a bit sharper in your app. This generator does the conversion for the preview, so the code you copy matches what you see.

Order is reversed too: Flutter paints the first shadow in the list at the bottom, while CSS paints the first one on top. That matters when you stack a light and a dark shadow, as in neumorphism.

Material elevation shadows

The Material elevation 2 and 8 presets use the exact values from Flutter’s kElevationToShadow map: three layers called umbra, penumbra and ambient. If you want standard Material shadows, you don’t need custom code at all:

// Simplest: let Material draw the elevation shadow.
Card(
  elevation: 4,
  child: ...,
)

// Or reuse Flutter's own shadow values in a BoxDecoration:
BoxDecoration(
  boxShadow: kElevationToShadow[8],
)

Material elevation shadows are fairly tight and dark. For the softer, “floating” look common in modern app designs, a custom BoxShadow with a larger blur and a negative spread usually works better.

Common BoxShadow problems

  • The shadow is cut off: a parent clips it. A ListView, ClipRRect or a tight SizedBox leaves no room outside the box. Add padding around the container, or set clipBehavior: Clip.none on the list or Stack.
  • The shadow shows but the image corners are square: the decoration’s borderRadius doesn’t clip the child. Clip the child, not the container:
// The shadow is drawn outside the box, so give it room:
Padding(
  padding: const EdgeInsets.all(24),
  child: Container(
    decoration: BoxDecoration(
      borderRadius: BorderRadius.circular(16),
      boxShadow: [/* … */],
    ),
    // Clip the content, not the shadow.
    child: ClipRRect(
      borderRadius: BorderRadius.circular(16),
      child: Image.network(url),
    ),
  ),
)
  • No shadow is visible: the box has no colour. A shadow is drawn behind the box, so if the box is transparent you only see a blurry outline. Give the decoration a color.
  • Scrolling stutters with many shadows: big blurs on every list item are expensive. Keep blur values moderate and use one or two layers in long lists.

FAQ

Does it work for Card or Material widgets? Those use elevation instead of a list of shadows. For full control, use a Container with this BoxDecoration, or the same boxShadow list on a DecoratedBox.

Why Color(0x14000000) instead of Colors.black.withOpacity? The hex form can be const, and withOpacity is deprecated since Flutter 3.27. The Hex to Flutter Color tool explains the alpha values.

Want to see shadows in complete screens? Read building a beautiful login screen or browse the Flutter UI projects with source code.

More free Flutter tools