.background()

iOS 13+

Layers a view behind the current view, useful for adding colors, gradients, images, or custom views as backgrounds.

Visual Effects
Official Apple Documentation →
iOS User Coverage
96.9%
coverage

96.9% of iOS users can use this modifier

Version Compatibility
iOS 18.7
24.1% Supported
iOS 26.2
22.9% Supported
iOS 18.6
19.7% Supported
iOS 26.1
7.7% Supported
iOS 18.5
5.0% Supported
iOS 16.7
2.2% Supported
iOS 15.8
1.7% Supported
iOS 18.3
1.6% Supported
iOS 17.6
1.5% Supported
iOS 26.0
1.0% Supported

iOS 13+ required

Variants
.background(_:)

Sets a view or shape as the background

Parameters:
  • content: View or ShapeStyle
.background(_:ignoresSafeAreaEdges:)

Sets background that can extend into safe area

Parameters:
  • content: View or ShapeStyle
  • edges: Edge.Set
Code Examples

Color Background

Add a solid color background

Text("Hello, World!")
    .padding()
    .background(.blue)

Gradient Background

Use a linear gradient as background

Text("Hello, World!")
    .padding()
    .background(
        LinearGradient(
            colors: [.blue, .purple],
            startPoint: .top,
            endPoint: .bottom
        )
    )

Custom View Background

Layer a rounded rectangle behind content

Text("Hello, World!")
    .padding()
    .background(
        RoundedRectangle(cornerRadius: 10)
            .fill(.blue.opacity(0.2))
    )

Loading related modifiers...

Frequently Asked Questions

What iOS version is required for .background()?

The .background() modifier requires iOS 13 or later. This means 96.9% of current iOS users can use this modifier.

How do I use .background() in SwiftUI?

Apply the .background() modifier to any SwiftUI view. Check the code examples above for usage patterns.

Where can I learn more?

Visit the official Apple documentation for detailed information.

Explore More SwiftUI Modifiers