<!--
{
  "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/Color",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI5ColorV"
  },
  "title" : "Color"
}
-->

# Color

A representation of a color that adapts to a given context.

```
@frozen struct Color
```

## Overview

You can create a color in one of several ways:

- Load a color from an Asset Catalog:
  
  ```
  let aqua = Color("aqua") // Looks in your app's main bundle by default.
  ```
- Specify component values, like red, green, and blue; hue,
  saturation, and brightness; or white level:
  
  ```
  let skyBlue = Color(red: 0.4627, green: 0.8392, blue: 1.0)
  let lemonYellow = Color(hue: 0.1639, saturation: 1, brightness: 1)
  let steelGray = Color(white: 0.4745)
  ```
- Create a color instance from another color, like a
  <doc://com.apple.documentation/documentation/UIKit/UIColor> or an
  <doc://com.apple.documentation/documentation/AppKit/NSColor>:
  
  ```
  #if os(iOS)
  let linkColor = Color(uiColor: .link)
  #elseif os(macOS)
  let linkColor = Color(nsColor: .linkColor)
  #endif
  ```
- Use one of a palette of predefined colors, like [`black`](/documentation/SwiftUI/ShapeStyle/black),
  [`green`](/documentation/SwiftUI/ShapeStyle/green), and [`purple`](/documentation/SwiftUI/ShapeStyle/purple).

Some view modifiers can take a color as an argument. For example,
[`foregroundStyle(_:)`](/documentation/SwiftUI/View/foregroundStyle(_:)) uses the color you provide to set the
foreground color for view elements, like text or
<doc://com.apple.documentation/design/Human-Interface-Guidelines/sf-symbols>:

```
Image(systemName: "leaf.fill")
    .foregroundStyle(Color.green)
```

![A screenshot of a green leaf.](images/com.apple.SwiftUI/Color-1@2x.png)

Because SwiftUI treats colors as [`View`](/documentation/SwiftUI/View) instances, you can also
directly add them to a view hierarchy. For example, you can layer
a rectangle beneath a sun image using colors defined above:

```
ZStack {
    skyBlue
    Image(systemName: "sun.max.fill")
        .foregroundStyle(lemonYellow)
}
.frame(width: 200, height: 100)
```

A color used as a view expands to fill all the space it’s given,
as defined by the frame of the enclosing [`ZStack`](/documentation/SwiftUI/ZStack) in the above example:

![A screenshot of a yellow sun on a blue background.](images/com.apple.SwiftUI/Color-2@2x.png)

SwiftUI only resolves a color to a concrete value
just before using it in a given environment.
This enables a context-dependent appearance for
system defined colors, or those that you load from an Asset Catalog.
For example, a color can have distinct light and dark variants
that the system chooses from at render time.

## Topics

### Creating a color

[`init(_:bundle:)`](/documentation/SwiftUI/Color/init(_:bundle:))

Creates a color from a color set that you indicate by name.

[`init(_:)`](/documentation/SwiftUI/Color/init(_:))

Creates a constant color with the values specified by the resolved
color.

[`resolve(in:)`](/documentation/SwiftUI/Color/resolve(in:))

Evaluates this color to a resolved color given the current
`context`.

### Creating a color from component values

[`init(hue:saturation:brightness:opacity:)`](/documentation/SwiftUI/Color/init(hue:saturation:brightness:opacity:))

Creates a constant color from hue, saturation, and brightness values.

[`init(_:white:opacity:)`](/documentation/SwiftUI/Color/init(_:white:opacity:))

Creates a constant grayscale color.

[`init(_:red:green:blue:opacity:)`](/documentation/SwiftUI/Color/init(_:red:green:blue:opacity:))

Creates a constant color from red, green, and blue component values.

[`Color.RGBColorSpace`](/documentation/SwiftUI/Color/RGBColorSpace)

A profile that specifies how to interpret a color value for display.

### Creating a color from another color

[`init(uiColor:)`](/documentation/SwiftUI/Color/init(uiColor:))

Creates a color from a UIKit color.

[`init(nsColor:)`](/documentation/SwiftUI/Color/init(nsColor:))

Creates a color from an AppKit color.

[`init(cgColor:)`](/documentation/SwiftUI/Color/init(cgColor:))

Creates a color from a Core Graphics color.

### Getting standard colors

[`black`](/documentation/SwiftUI/Color/black)

A black color suitable for use in UI elements.

[`blue`](/documentation/SwiftUI/Color/blue)

A context-dependent blue color suitable for use in UI elements.

[`brown`](/documentation/SwiftUI/Color/brown)

A context-dependent brown color suitable for use in UI elements.

[`clear`](/documentation/SwiftUI/Color/clear)

A clear color suitable for use in UI elements.

[`cyan`](/documentation/SwiftUI/Color/cyan)

A context-dependent cyan color suitable for use in UI elements.

[`gray`](/documentation/SwiftUI/Color/gray)

A context-dependent gray color suitable for use in UI elements.

[`green`](/documentation/SwiftUI/Color/green)

A context-dependent green color suitable for use in UI elements.

[`indigo`](/documentation/SwiftUI/Color/indigo)

A context-dependent indigo color suitable for use in UI elements.

[`mint`](/documentation/SwiftUI/Color/mint)

A context-dependent mint color suitable for use in UI elements.

[`orange`](/documentation/SwiftUI/Color/orange)

A context-dependent orange color suitable for use in UI elements.

[`pink`](/documentation/SwiftUI/Color/pink)

A context-dependent pink color suitable for use in UI elements.

[`purple`](/documentation/SwiftUI/Color/purple)

A context-dependent purple color suitable for use in UI elements.

[`red`](/documentation/SwiftUI/Color/red)

A context-dependent red color suitable for use in UI elements.

[`teal`](/documentation/SwiftUI/Color/teal)

A context-dependent teal color suitable for use in UI elements.

[`white`](/documentation/SwiftUI/Color/white)

A white color suitable for use in UI elements.

[`yellow`](/documentation/SwiftUI/Color/yellow)

A context-dependent yellow color suitable for use in UI elements.

### Getting semantic colors

[`accentColor`](/documentation/SwiftUI/Color/accentColor)

A color that reflects the accent color of the system or app.

[`primary`](/documentation/SwiftUI/Color/primary)

The color to use for primary content.

[`secondary`](/documentation/SwiftUI/Color/secondary)

The color to use for secondary content.

### Modifying a color

[`opacity(_:)`](/documentation/SwiftUI/Color/opacity(_:))

Multiplies the opacity of the color by the given amount.

[`gradient`](/documentation/SwiftUI/Color/gradient)

Returns the standard gradient for the color `self`.

[`mix(with:by:in:)`](/documentation/SwiftUI/Color/mix(with:by:in:))

Returns a version of self mixed with `rhs` by the amount specified
by `fraction`.

[`exposureAdjust(_:)`](/documentation/SwiftUI/Color/exposureAdjust(_:))

Returns a new color with an exposure adjustment applied.

[`headroom(_:)`](/documentation/SwiftUI/Color/headroom(_:))

Creates a new color with specified HDR content headroom.

### Working with high dynamic range (HDR) colors

[`resolveHDR(in:)`](/documentation/SwiftUI/Color/resolveHDR(in:))

Evaluates this color to a resolved color with content headroom,
given a set of environment values.

[`Color.ResolvedHDR`](/documentation/SwiftUI/Color/ResolvedHDR)

A concrete color value, including HDR headroom information.

### Describing a color

[`description`](/documentation/SwiftUI/Color/description)

A textual representation of the color.

### Comparing colors

[`==(_:_:)`](/documentation/SwiftUI/Color/==(_:_:))

Indicates whether two colors are equal.

[`hash(into:)`](/documentation/SwiftUI/Color/hash(into:))

Hashes the essential components of the color by feeding them into the
given hash function.

### Deprecated symbols

[`cgColor`](/documentation/SwiftUI/Color/cgColor)

A Core Graphics representation of the color, if available.



---

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)