<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/contentMargins(_:_:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE14contentMargins__3forQrAA4EdgeO3SetV_AA0G6InsetsVAA22ContentMarginPlacementVtF::OverloadGroup"
  },
  "title" : "contentMargins(_:_:for:)"
}
-->

# contentMargins(_:_:for:)

Configures the content margin for a provided placement.

```
nonisolated func contentMargins(_ edges: Edge.Set = .all, _ insets: EdgeInsets, for placement: ContentMarginPlacement = .automatic) -> some View
```

## Parameters

`edges`

The edges to add the margins to.

`insets`

The amount of margins to add.

`placement`

Where the margins should be added.

## Discussion

Use this modifier to customize the content margins of different
kinds of views. For example, you can use this modifier to customize
the margins of scrollable views like [`ScrollView`](/documentation/SwiftUI/ScrollView). In the
following example, the scroll view will automatically inset
its content by the safe area plus an additional 20 points
on the leading and trailing edge.

```
ScrollView(.horizontal) {
    // ...
}
.contentMargins(.horizontal, 20.0)
```

You can provide a [`ContentMarginPlacement`](/documentation/SwiftUI/ContentMarginPlacement) to target specific
parts of a view to customize. For example, provide a
[`scrollContent`](/documentation/SwiftUI/ContentMarginPlacement/scrollContent) placement to
inset the content of a [`TextEditor`](/documentation/SwiftUI/TextEditor) without affecting the
insets of its scroll indicators.

```
TextEditor(text: $text)
    .contentMargins(.horizontal, 20.0, for: .scrollContent)
```

Similarly, you can customize the insets of scroll indicators
separately from scroll content. Consider doing this when applying
a custom clip shape that may clip the indicators.

```
ScrollView {
    // ...
}
.clipShape(.rect(cornerRadius: 20.0))
.contentMargins(10.0, for: .scrollIndicators)
```

When applying multiple contentMargins modifiers, modifiers with
the same placement will override modifiers higher up in the view
hierarchy.

---

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)