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

# aspectRatio(_:contentMode:)

Constrains this view’s dimensions to the specified aspect ratio.

```
nonisolated func aspectRatio(_ aspectRatio: CGFloat? = nil, contentMode: ContentMode) -> some View
```

## Parameters

`aspectRatio`

The ratio of width to height to use for the resulting
view. Use `nil` to maintain the current aspect ratio in the
resulting view.

`contentMode`

A flag that indicates whether this view fits or fills
the parent context.

## Return Value

A view that constrains this view’s dimensions to the aspect
ratio of the given size using `contentMode` as its scaling algorithm.

## Discussion

Use `aspectRatio(_:contentMode:)` to constrain a view’s dimensions to an
aspect ratio specified by a
<doc://com.apple.documentation/documentation/CoreFoundation/CGFloat-swift.struct>
using the specified content mode.

If this view is resizable, the resulting view will have `aspectRatio` as
its aspect ratio. In this example, the purple ellipse has a 3:4
width-to-height ratio, and scales to fit its frame:

```
Ellipse()
    .fill(Color.purple)
    .aspectRatio(0.75, contentMode: .fit)
    .frame(width: 200, height: 200)
    .border(Color(white: 0.75))
```

![A view showing a purple ellipse that has a 3:4 width-to-height ratio,](images/com.apple.SwiftUI/SwiftUI-View-aspectRatio-cgfloat@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)