<!--
{
  "availability" : [
    "iOS: 27.1.0 -",
    "iPadOS: 27.1.0 -",
    "macCatalyst: 27.1.0 -",
    "macOS: 27.1.0 -",
    "tvOS: 27.1.0 -",
    "visionOS: 27.1.0 -",
    "watchOS: 27.1.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/contentMargins(for:edges:alignment:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE14contentMargins3for5edges9alignmentQrAA18ContentMarginGuideV_AA4EdgeO3SetVAA9AlignmentVSgtF"
  },
  "title" : "contentMargins(for:edges:alignment:)"
}
-->

# contentMargins(for:edges:alignment:)

Insets the content of this view by a content margin guide.

```
nonisolated func contentMargins(for guide: ContentMarginGuide, edges: Edge.Set = .all, alignment: Alignment? = nil) -> some View
```

## Parameters

`guide`

The guide that provides the insets.

`edges`

The edges to inset, any edges not in this set are
unchanged, even when `guide` provides a value for them.

`alignment`

The alignment of the view within the inset bounds.
Most alignment values have no apparent effect when the view
fills the size it was proposed.

## Return Value

A view inset on `edges` by `guide`.

## Discussion

Use this modifier to lay a view out against a system metric, like
the margins of the container it appears in:

```
NavigationStack {
    AlbumGrid()
        .contentMargins(for: .container, edges: .horizontal)
}
```

The view is proposed the size it would otherwise receive, and is
inset by the value of `guide` when it’s placed.

A view that doesn’t fill the size it was proposed is positioned
within the inset bounds using `alignment`. Here, a compose button
sits in the bottom trailing corner of the margins of its container:

```
ZStack {
    MessageList()
    ComposeButton()
        .contentMargins(
            for: .container, alignment: .bottomTrailing)
}
```

---

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)