<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreImage",
  "identifier" : "/documentation/CoreImage/CIFilter-swift.class/linearGradient()",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core Image",
      "CoreImage"
    ],
    "preciseIdentifier" : "c:objc(cs)CIFilter(cm)linearGradientFilter"
  },
  "title" : "linearGradient()"
}
-->

# linearGradient()

Generates a color gradient that varies along a linear axis between two defined endpoints.

```
class func linearGradient() -> any CIFilter & CILinearGradient
```

## Return Value

The generated image.

## Discussion

This method generates a linear-gradient image. The effect creates a gradient that varies linearly between the two input properties of `point0` and `point1`.

The linear-gradient filter uses the following properties:

- `point0`: A <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint> representing the starting position of the gradient.
- `point1`: A <doc://com.apple.documentation/documentation/CoreFoundation/CGPoint> representing the ending position of the gradient.
- `color0`: A [`CIColor`](/documentation/CoreImage/CIColor) representing the first color to use in the gradient.
- `color1`: A [`CIColor`](/documentation/CoreImage/CIColor) representing the second color to use the gradient.

The following code creates a filter that generates a gradient image:

```swift
func linear() -> CIImage {
    let linearGradient = CIFilter.linearGradient()
    linearGradient.point0 = CGPoint(x: 0, y: 0)
    linearGradient.point1 = CGPoint(x: 200, y: 200)
    linearGradient.color0 = CIColor(red: 216/255, green: 232/255, blue: 146/255)
    linearGradient.color1 = CIColor(red: 0/255, green: 112/255, blue: 201/255)
    return linearGradient.outputImage!
}
```

![An image that gradually changes in color from yellow in the top left corner to light blue in the bottom right corner.](images/com.apple.coreimage/media-3558797@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)