<!--
{
  "availability" : [
    "iOS: 16.1.0 -",
    "iPadOS: 16.1.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "WidgetKit",
  "identifier" : "/documentation/WidgetKit/DynamicIsland/contentMargins(_:_:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "WidgetKit"
    ],
    "preciseIdentifier" : "s:9WidgetKit13DynamicIslandV14contentMargins__3forAC7SwiftUI4EdgeO3SetV_SdAA0cD4ModeVtF"
  },
  "title" : "contentMargins(_:_:for:)"
}
-->

# contentMargins(_:_:for:)

Overrides default content margins for the provided content modes in the Dynamic Island.

```
func contentMargins(_ edges: Edge.Set = .all, _ length: Double, for mode: DynamicIslandMode) -> DynamicIsland
```

## Parameters

`edges`

The edges that should use custom content margins.

`length`

The value for the custom content margin for the specified `edges`.

`mode`

The presentation of the Dynamic Island that the custom content margins apply to.

## Return Value

The Dynamic Island view with updated content margins.

## Discussion

Use this modifier to customize the content margins for a content mode in the Dynamic Island. Avoid placing content
too close to the edges of the Dynamic Island.

The following example uses the default margin for the leading edge and sets a custom margin of 8 points
for the top, bottom, and trailing edges of a Live Activity in the expanded presentation:

```swift
dynamicIsland
    .contentMargins([.top, .bottom, .trailing], 8, for:.expanded)
```

When you apply multiple `contentMargins(_:_:for:)` modifiers, modifiers with the same
placement override modifiers higher up in the view hierarchy. The following example results in a margin of
8 points for the trailing edge and 20 points for all other edges when the Live Activity appears in the
expanded presentation:

```swift
dynamicIsland
    .contentMargins(.trailing, 8, for:.expanded)
    .contentMargins(.all, 20, for:.expanded)
```

---

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)