<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/ShapeStyle/linearGradient(_:startPoint:endPoint:)-5xsg4",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI10ShapeStylePA2A14LinearGradientVRszrlE06linearF0_10startPoint03endI0QrAA03AnyF0V_AA04UnitI0VALtFZ"
  },
  "title" : "linearGradient(_:startPoint:endPoint:)"
}
-->

# linearGradient(_:startPoint:endPoint:)

A linear gradient.

```
@export(implementation) static func linearGradient(_ gradient: AnyGradient, startPoint: UnitPoint, endPoint: UnitPoint) -> some ShapeStyle
```

## Discussion

The gradient applies the color function along an axis, as
defined by its start and end points. The gradient maps the unit
space points into the bounding rectangle of each shape filled
with the gradient.

For example, a linear gradient used as a background:

```
ContentView()
    .background(.linearGradient(.red.gradient,
        startPoint: .top, endPoint: .bottom))
```

For information about how to use shape styles, see `ShapeStyle`.

---

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)