<!--
{
  "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/border(_:width:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE6border_5widthQrqd___14CoreFoundation7CGFloatVtAA10ShapeStyleRd__lF"
  },
  "title" : "border(_:width:)"
}
-->

# border(_:width:)

Adds a border to this view with the specified style and width.

```
nonisolated func border<S>(_ content: S, width: CGFloat = 1) -> some View where S : ShapeStyle
```

## Parameters

`content`

A value that conforms to the [`ShapeStyle`](/documentation/SwiftUI/ShapeStyle) protocol,
like a [`Color`](/documentation/SwiftUI/Color) or [`HierarchicalShapeStyle`](/documentation/SwiftUI/HierarchicalShapeStyle), that SwiftUI
uses to fill the border.

`width`

The thickness of the border. The default is 1 pixel.

## Return Value

A view that adds a border with the specified style and width
to this view.

## Discussion

Use this modifier to draw a border of a specified width around the
view’s frame. By default, the border appears inside the bounds of this
view. For example, you can add a four-point wide border covers the text:

```
Text("Purple border inside the view bounds.")
    .border(Color.purple, width: 4)
```

![A screenshot showing the text Purple border inside the view bounds.](images/com.apple.SwiftUI/View-border-1@2x.png)

To place a border around the outside of this view, apply padding of the
same width before adding the border:

```
Text("Purple border outside the view bounds.")
    .padding(4)
    .border(Color.purple, width: 4)
```

![A screenshot showing the text Purple border outside the view bounds.](images/com.apple.SwiftUI/View-border-2@2x.png)

---

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)