A shadow in React Native can come from three shadow APIs or from Android's elevation, and each one draws something different on a different set of platforms. Pick the wrong one and a card that looks lifted on an iPhone sits flat on an Android phone, or an icon gets a rectangle of shadow behind its transparent corners. Knowing what each API draws, and where, lets you choose one on purpose.

Key terms

  • boxShadow: a View style prop that implements the web box-shadow property and works on both iOS and Android.
  • Shadow props: shadowColor, shadowOffset, shadowOpacity and shadowRadius, which map to the platform's native shadow APIs.
  • New Architecture: the React Native architecture that boxShadow, filter and several other style props in this section require.
  • elevation: an Android-only style prop that uses Android's elevation API to add a drop shadow and change z-order for overlapping views.
  • dropShadow: a function of the filter style prop that casts a shadow from the view's non-transparent pixels.

Border box or alpha mask

boxShadow follows the border box. It is drawn around the outside of the box, or around the inside when the shadow is inset, and the content has no say in its shape: a View holding a PNG with transparent corners still casts a shadow from its whole box.

dropShadow is an alpha mask. Only pixels with a positive alpha cast a shadow, so a star icon on a transparent background gets a star-shaped shadow. It isn't a prop of its own. It is one of the functions of filter, a New Architecture style prop that takes an array of single-key filter objects and applies them to the View and its descendants. It also does less than boxShadow. It can't be inset, has no spread distance, and works only on Android, from Android 12.

The shadow props and elevation hand the work to the platform. The shadow props map directly to the native shadow APIs, and elevation uses Android's elevation API, which also changes z-order for overlapping views. boxShadow and dropShadow can do more than the shadow props, but for a straightforward shadow the shadow props are the recommended choice because they map to native APIs.

Layered and inset shadows with boxShadow

boxShadow works on both platforms within three limits: it needs the New Architecture, outset shadows need Android 9 or later, and inset shadows need Android 10 or later. A new 0.88 app already has the New Architecture, because the app template sets newArchEnabled=true in android/gradle.properties.

boxShadow takes a string in web syntax or an array of BoxShadowValue objects, one object per shadow, so one value can combine several shadows.

The PlanCard example stacks two shadows on the card:

tsx
boxShadow: [
  {offsetX: 0, offsetY: 1, blurRadius: 2, color: 'rgba(15, 23, 42, 0.12)'},
  {offsetX: 0, offsetY: 10, blurRadius: 24, spreadDistance: -6, color: 'rgba(15, 23, 42, 0.2)'},
],

Each BoxShadowValue needs offsetX and offsetY, and color, blurRadius, spreadDistance and inset are optional. A positive offsetX moves the shadow right and a negative one moves it left. blurRadius must be non-negative and defaults to 0, and larger values blur the shadow more. spreadDistance grows the shadow when positive and shrinks it when negative, which lets the second, softer shadow start inside the card's edges. Leave color out and the shadow is black.

The price well inside the card uses the string form, 'inset 0 2px 4px rgba(15, 23, 42, 0.2)'. The inset keyword is its own token and sets inset to true, and every non-zero length needs the px unit. Only 0 can be written without one, so 'inset 0 2 4 black' draws no shadow at all. An inset shadow is drawn around the inside of the border box, which reads as a recessed area.

One bad value cancels the whole prop. A negative blurRadius, or one that can't be parsed, makes React Native return an empty shadow list, so a bad blurRadius in the second shadow also removes the first.

Native shadows on iOS and Android

The ShareButton example sets the four shadow props and elevation on the same style:

tsx
shadowColor: '#000000',
shadowOffset: {width: 0, height: 4},
shadowOpacity: 0.3,
shadowRadius: 6,
elevation: 6,

Only shadowColor works on both platforms, and on Android it needs API 28 (Android 9) or later. shadowOffset (an object with width and height numbers), shadowOpacity and shadowRadius (the blur radius) are iOS only. Forget shadowOpacity and iOS draws nothing: its native default is zero, and a layer only counts as having a shadow when its opacity is above zero. That opacity is also multiplied by the alpha of the shadow color, so a half-transparent shadowColor gives a fainter shadow than the number suggests. Skip shadowOffset and shadowRadius and the native defaults apply, an offset of {width: 0, height: -3} and a radius of 3.

On Android, elevation draws this button's shadow. It takes a number in dp, and because it also changes z-order for overlapping views, it matters for a button that floats over a scrolling list.

A shadow that follows the pixels

Use dropShadow when the shape comes from the image, such as a logo PNG with a transparent background, and the screen targets Android 12 or later:

tsx
filter: [{dropShadow: {offsetX: 0, offsetY: 3, standardDeviation: 4, color: 'rgba(0, 0, 0, 0.35)'}}],

A DropShadowValue is made of 2 or 3 lengths and an optional color. Its blur key is standardDeviation, where boxShadow uses blurRadius, and it has no spreadDistance or inset key. In the filter string syntax the function is written drop-shadow(...). Because dropShadow works only on Android, an iPhone shows this logo without a shadow.

Code Examples

tsx
import {StyleSheet, Text, View} from 'react-native';

type PlanCardProps = {name: string; price: string};

export function PlanCard({name, price}: PlanCardProps) {
  return (
    <View style={styles.card}>
      <Text style={styles.name}>{name}</Text>
      <View style={styles.priceWell}>
        <Text style={styles.price}>{price}</Text>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  card: {
    padding: 20,
    borderRadius: 16,
    backgroundColor: '#ffffff',
    // Two outset shadows in one value: a tight one and a soft, pulled-in one
    boxShadow: [
      {offsetX: 0, offsetY: 1, blurRadius: 2, color: 'rgba(15, 23, 42, 0.12)'},
      {offsetX: 0, offsetY: 10, blurRadius: 24, spreadDistance: -6, color: 'rgba(15, 23, 42, 0.2)'},
    ],
  },
  priceWell: {
    marginTop: 12,
    padding: 12,
    borderRadius: 10,
    backgroundColor: '#f1f5f9',
    // Inset shadow in web syntax (inset shadows need Android 10 or later)
    boxShadow: 'inset 0 2px 4px rgba(15, 23, 42, 0.2)',
  },
  name: {fontSize: 18, fontWeight: '600'},
  price: {fontSize: 24, fontWeight: '700'},
});
tsx
import {Pressable, StyleSheet, Text} from 'react-native';

export function ShareButton({onPress}: {onPress: () => void}) {
  return (
    <Pressable style={styles.button} onPress={onPress}>
      <Text style={styles.label}>Share</Text>
    </Pressable>
  );
}

const styles = StyleSheet.create({
  button: {
    position: 'absolute',
    right: 24,
    bottom: 24,
    paddingHorizontal: 20,
    paddingVertical: 14,
    borderRadius: 28,
    backgroundColor: '#2563eb',
    // shadowColor works on both platforms (Android API 28 and later)
    shadowColor: '#000000',
    // iOS only: nothing is drawn unless shadowOpacity is above zero
    shadowOffset: {width: 0, height: 4},
    shadowOpacity: 0.3,
    shadowRadius: 6,
    // Android only: draws a shadow and changes z-order for overlapping views
    elevation: 6,
  },
  label: {color: '#ffffff', fontWeight: '600'},
});
✓ Completed