<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/padding(_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE7paddingyQrAA4EdgeO3SetV_14CoreFoundation7CGFloatVSgtF"
  },
  "title" : "padding(_:_:)"
}
-->

# padding(_:_:)

Adds an equal padding amount to specific edges of this view.

```
nonisolated func padding(_ edges: Edge.Set = .all, _ length: CGFloat? = nil) -> some View
```

## Parameters

`edges`

The set of edges to pad for this view. The default
is [`all`](/documentation/SwiftUI/Edge/Set/all).

`length`

An amount, given in points, to pad this view on the
specified edges. If you set the value to `nil`, SwiftUI uses
a platform-specific default amount. The default value of this
parameter is `nil`.

## Return Value

A view that’s padded by the specified amount on the
specified edges.

## Discussion

Use this modifier to add a specified amount of padding to one or more
edges of the view. Indicate the edges to pad by naming either a single
value from [`Edge.Set`](/documentation/SwiftUI/Edge/Set), or by specifying an
<doc://com.apple.documentation/documentation/Swift/OptionSet>
that contains edge values:

```
VStack {
    Text("Text padded by 20 points on the bottom and trailing edges.")
        .padding([.bottom, .trailing], 20)
        .border(.gray)
    Text("Unpadded text for comparison.")
        .border(.yellow)
}
```

The order in which you apply modifiers matters. The example above
applies the padding before applying the border to ensure that the
border encompasses the padded region:

![A screenshot of two text strings arranged vertically, each surrounded](images/com.apple.SwiftUI/View-padding-2-iOS@2x.png)

You can omit either or both of the parameters. If you omit the `length`,
SwiftUI uses a default amount of padding. If you
omit the `edges`, SwiftUI applies the padding to all edges. Omit both
to add a default padding all the way around a view. SwiftUI chooses a
default amount of padding that’s appropriate for the platform and
the presentation context.

```
VStack {
    Text("Text with default padding.")
        .padding()
        .border(.gray)
    Text("Unpadded text for comparison.")
        .border(.yellow)
}
```

The example above looks like this in iOS under typical conditions:

![A screenshot of two text strings arranged vertically, each surrounded](images/com.apple.SwiftUI/View-padding-2a-iOS@2x.png)

To control the amount of padding independently for each edge, use
[`padding(_:)`](/documentation/SwiftUI/View/padding(_:)-6pgqq). To pad all outside edges of a view by a
specified amount, use [`padding(_:)`](/documentation/SwiftUI/View/padding(_:)-68shk).

---

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)