hex to SwiftUI Color
SwiftUI takes 0–1 components. It has no hex initialiser built in, which is why this conversion comes up so often.
Paste a hex value. Other formats work too.
Color(red: 0, green: 0.671, blue: 0.906)Need every format at once? Open in the full picker
Worked examples
Common colors converted from hex to SwiftUI Color, computed with the same engine the picker uses.
| Color | hex | SwiftUI Color | Copy |
|---|---|---|---|
| Pure red | #ff0000 | Color(red: 1, green: 0, blue: 0) | |
| Pure green | #00ff00 | Color(red: 0, green: 1, blue: 0) | |
| Pure blue | #0000ff | Color(red: 0, green: 0, blue: 1) | |
| White | #ffffff | Color(red: 1, green: 1, blue: 1) | |
| Mid gray | #808080 | Color(red: 0.502, green: 0.502, blue: 0.502) | |
| Black | #000000 | Color(red: 0, green: 0, blue: 0) | |
| Interface blue | #4287f5 | Color(red: 0.259, green: 0.529, blue: 0.961) | |
| Success green | #22c55e | Color(red: 0.133, green: 0.773, blue: 0.369) | |
| Danger red | #ef4444 | Color(red: 0.937, green: 0.267, blue: 0.267) | |
| Warning amber | #f59e0b | Color(red: 0.961, green: 0.62, blue: 0.043) | |
| Editor black | #1e1e1e | Color(red: 0.118, green: 0.118, blue: 0.118) | |
| Warm sand | #e9c46a | Color(red: 0.914, green: 0.769, blue: 0.416) |
How the conversion works
SwiftUI takes 0–1 components. It has no hex initialiser built in, which is why this conversion comes up so often.
Both formats are computed from a single canonical representation (CIE XYZ with a D65 white point, held in floating point) rather than by chaining one format into the next. That matters because chained conversions accumulate rounding error, and because it means a color that cannot be represented in the target format is handled deliberately rather than by accident.
When the source describes a color outside the target's gamut, chroma is reduced in OKLCh while lightness and hue are held, following the CSS Color 4 gamut mapping algorithm. Clipping each channel independently would be simpler but visibly shifts hue on saturated colors.