<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/UIHostingConfiguration/margins(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI22UIHostingConfigurationV7marginsyACyxq_GAA4EdgeO3SetV_AA0F6InsetsVtF::OverloadGroup"
  },
  "title" : "margins(_:_:)"
}
-->

# margins(_:_:)

Sets the margins around the content of the configuration.

```
func margins(_ edges: Edge.Set = .all, _ insets: EdgeInsets) -> UIHostingConfiguration<Content, Background>
```

## Parameters

`edges`

The edges to apply the insets. Any edges not specified will
use the system default values. The default value is
[`all`](/documentation/SwiftUI/Edge/Set/all).

`insets`

The insets to apply.

## Discussion

Use this modifier to replace the default margins applied to the root of
the configuration. The following example creates 10 points of space
between the content and the background on the leading edge and 20 points
of space on the trailing edge:

```
UIHostingConfiguration {
    Text("My Contents")
}
.margins(.horizontal, 20.0)
```

---

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)