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

# contentTransition(_:)

Modifies the view to use a given transition as its method of animating
changes to the contents of its views.

```
@export(implementation) nonisolated func contentTransition(_ transition: ContentTransition) -> some View
```

## Parameters

`transition`

The transition to apply when animating the
content change.

## Discussion

This modifier allows you to perform a transition that animates a change
within a single view. The provided [`ContentTransition`](/documentation/SwiftUI/ContentTransition) can present an
opacity animation for content changes, an interpolated animation of
the content’s paths as they change, or perform no animation at all.

> Tip: The `contentTransition(_:)` modifier only has an effect within
> the context of an ``doc://com.apple.SwiftUI/documentation/SwiftUI/Animation``.

In the following example, a [`Button`](/documentation/SwiftUI/Button) changes the color and font size
of a [`Text`](/documentation/SwiftUI/Text) view. Since both of these properties apply to the paths of
the text, the [`interpolate`](/documentation/SwiftUI/ContentTransition/interpolate) transition can animate a
gradual change to these properties through the entire transition. By
contrast, the [`opacity`](/documentation/SwiftUI/ContentTransition/opacity) transition would simply fade
between the start and end states.

```
private static let font1 = Font.system(size: 20)
private static let font2 = Font.system(size: 45)

@State private var color = Color.red
@State private var currentFont = font1

var body: some View {
    VStack {
        Text("Content transition")
            .foregroundColor(color)
            .font(currentFont)
            .contentTransition(.interpolate)
        Spacer()
        Button("Change") {
            withAnimation(Animation.easeInOut(duration: 5.0)) {
                color = (color == .red) ? .green : .red
                currentFont = (currentFont == font1) ? font2 : font1
            }
        }
    }
}
```

This example uses an ease-in–ease-out animation with a five-second
duration to make it easier to see the effect of the interpolation. The
figure below shows the `Text` at the beginning of the animation,
halfway through, and at the end.

|Time  |Display                                                                    |
|------|---------------------------------------------------------------------------|
|Start |![The text Content transition in a small red font.](ContentTransition-1)   |
|Middle|![The text Content transition in a medium brown font.](ContentTransition-2)|
|End   |![The text Content transition in a large green font.](ContentTransition-3) |

To control whether content transitions use GPU-accelerated rendering,
set the value of the
[`contentTransitionAddsDrawingGroup`](/documentation/SwiftUI/EnvironmentValues/contentTransitionAddsDrawingGroup) environment
variable.

---

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)