HEX to SwiftUI Color Code Generator
Turn any HEX color into SwiftUI Color(.sRGB, red:, green:, blue:, opacity:) code, plus a UIKit UIColor snippet. Free, instant and processed locally.
Color
Generated code
Color(.sRGB, red: 0.231, green: 0.51, blue: 0.965, opacity: 1.0)UIColor(red: 0.231, green: 0.51, blue: 0.965, alpha: 1.0)Technical Specification & Mathematical Principles
How the SwiftUI Color Code Generator Works
SwiftUI expects each channel as a floating point value from 0 to 1. The generator divides each 8-bit channel by 255, so #3B82F6 becomes red 0.231, green 0.51 and blue 0.965. The .sRGB argument tells SwiftUI the values are in the sRGB color space rather than the extended or Display P3 space.
Opacity is passed as the final argument and is independent of the HEX digits. A UIKit equivalent, UIColor(red:green:blue:alpha:), is provided for projects that still bridge to UIKit.
Frequently Asked Questions
Why use Color(.sRGB, ...) instead of Color(red:green:blue:)?
How many decimals are generated?
Can I use these in an Asset Catalog?
Related Design & Color Instruments
Android Color Converter
Convert HEX to Jetpack Compose Color(0xFF...) and Android XML color resources with alpha. Copy ready-to-paste Kotlin and colors.xml snippets instantly.
Flutter Color Code Generator
Convert HEX to Flutter Dart const Color(0xFFRRGGBB) with an alpha channel, plus Color.fromRGBO output. Instant, private and ready to paste.
Design Tokens Export (DTCG JSON)
Generate W3C Design Tokens Community Group JSON for colors with $value and $type. Name up to 12 tokens and copy a spec-shaped file for Style Dictionary.
HEX to RGB Converter
Convert hexadecimal web color strings (#RRGGBB) to decimal integer rgb(r, g, b) tuples instantly.