---
title: "border(_:width:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/border(_:width:)"
---

# border(_:width:)

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

## Declaration

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

```

## Parameters

- `content`: A value that conforms to the doc://com.apple.SwiftUI/documentation/SwiftUI/ShapeStyle protocol, like a doc://com.apple.SwiftUI/documentation/SwiftUI/Color or doc://com.apple.SwiftUI/documentation/SwiftUI/HierarchicalShapeStyle, that SwiftUI uses to fill the border.
- `width`: The thickness of the border. The default is 1 pixel.

## Mentioned in

Configuring views Inspecting view layout

## Return Value

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

## Discussion

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)

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)

## See Also

### Styling content

- [foregroundStyle(_:)](swiftui/view/foregroundstyle(_:).md)
- [foregroundStyle(_:_:)](swiftui/view/foregroundstyle(_:_:).md)
- [foregroundStyle(_:_:_:)](swiftui/view/foregroundstyle(_:_:_:).md)
- [backgroundStyle(_:)](swiftui/view/backgroundstyle(_:).md)
- [backgroundStyle](swiftui/environmentvalues/backgroundstyle.md)
- [ShapeStyle](swiftui/shapestyle.md)
- [AnyShapeStyle](swiftui/anyshapestyle.md)
- [Gradient](swiftui/gradient.md)
- [MeshGradient](swiftui/meshgradient.md)
- [AnyGradient](swiftui/anygradient.md)
- [ShadowStyle](swiftui/shadowstyle.md)
- [Glass](swiftui/glass.md)
