<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/background(_:ignoresSafeAreaEdges:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE10background_20ignoresSafeAreaEdgesQrqd___AA4EdgeO3SetVtAA10ShapeStyleRd__lF"
  },
  "title" : "background(_:ignoresSafeAreaEdges:)"
}
-->

# background(_:ignoresSafeAreaEdges:)

Sets the view’s background to a style.

```
nonisolated func background<S>(_ style: S, ignoresSafeAreaEdges edges: Edge.Set = .all) -> some View where S : ShapeStyle
```

## Parameters

`style`

An instance of a type that conforms to [`ShapeStyle`](/documentation/SwiftUI/ShapeStyle) that
SwiftUI draws behind the modified view.

`edges`

The set of edges for which to ignore safe area insets
when adding the background. The default value is [`all`](/documentation/SwiftUI/Edge/Set/all).
Specify an empty set to respect safe area insets on all edges.

## Return Value

A view with the specified style drawn behind it.

## Discussion

Use this modifier to place a type that conforms to the [`ShapeStyle`](/documentation/SwiftUI/ShapeStyle)
protocol — like a [`Color`](/documentation/SwiftUI/Color), [`Material`](/documentation/SwiftUI/Material), or
[`HierarchicalShapeStyle`](/documentation/SwiftUI/HierarchicalShapeStyle) — behind a view. For example, you can add
the [`regularMaterial`](/documentation/SwiftUI/ShapeStyle/regularMaterial) behind a [`Label`](/documentation/SwiftUI/Label):

```
struct FlagLabel: View {
    var body: some View {
        Label("Flag", systemImage: "flag.fill")
            .padding()
            .background(.regularMaterial)
    }
}
```

SwiftUI anchors the style to the view’s bounds. For the example above,
the background fills the entirety of the label’s frame, which includes
the padding:

![A screenshot of a flag symbol and the word flag layered over a](images/com.apple.SwiftUI/View-background-5@2x.png)

SwiftUI limits the background style’s extent to the modified view’s
container-relative shape. You can see this effect if you constrain the
`FlagLabel` view with a [`containerShape(_:)`](/documentation/SwiftUI/View/containerShape(_:)) modifier:

```
FlagLabel()
    .containerShape(RoundedRectangle(cornerRadius: 16))
```

The background takes on the specified container shape:

![A screenshot of a flag symbol and the word flag layered over a](images/com.apple.SwiftUI/View-background-6@2x.png)

By default, the background ignores safe area insets on all edges, but
you can provide a specific set of edges to ignore, or an empty set to
respect safe area insets on all edges:

```
Rectangle()
    .background(
        .regularMaterial,
        ignoresSafeAreaEdges: []) // Ignore no safe area insets.
```

If you want to specify a [`View`](/documentation/SwiftUI/View) or a stack of views as the background,
use [`background(alignment:content:)`](/documentation/SwiftUI/View/background(alignment:content:)) instead.
To specify a [`Shape`](/documentation/SwiftUI/Shape) or [`InsettableShape`](/documentation/SwiftUI/InsettableShape), use
[`background(_:in:fillStyle:)`](/documentation/SwiftUI/View/background(_:in:fillStyle:)) .
To configure the background of a presentation, like a sheet, use
[`presentationBackground(_:)`](/documentation/SwiftUI/View/presentationBackground(_:)).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)