Color

public enum Color : Encodable
extension Color: CustomPlaygroundDisplayConvertible
extension Color: ExpressibleByIntegerLiteral

Data structure that stores color, optionally with opacity.

Color can be expressed in a variety of ways:

  • As a one of 100+ CSS named colors :

    let darkRed = Color.darkRed
    
  • As red, green and blue pixel intensities with optional alpha channel for transparency:

    let black = Color.RGB(255, 255, 255)
    let blackTransparent = Color.RGB(255, 255, 255, 0.2)
    
  • As hue, saturation and lightness values, also with optional transparency:

    let pink = Color.HSL(300, 100, 50)
    let pinkTransparent = Color.HSL(300, 100, 50, 0.3)
    
  • As a hexadecimal integer literal in 0xRRGGBB format:

    let black: Color = 0xffffff
    

Transparency is expressed as alpha channel between 0 (transparent) and 1 (opaque). Valid lightness and saturation values are percentages between 0 and 100. Hue represents a positive angle smaller than 360°. There are no checks, clippings or exceptions that enforce these constraints.

Warning

CSS hexadecimal 3-digit #RGB and 6-digit+transparency #RRGGBBAA formats are not supported. For example the following code doesn’t work as expected:

let black: Color = 0xfff // Blue #000fff
let blackTransparent: Color = 0xffffff88 // Yellow #ffff88

It’s not possible to distinguish between these situations in Swift because they are all of the same type - a hexadecimal 32-bit integer literal. Failures, tough, are usually very visible and produce a significantly different result. The only correctly working format for literals is #RRGGBB.

Reds

  • Indian red standard CSS color: #cd5c5c or rgb(205,92,92).

    Declaration

    Swift

    public static let indianRed: Color
  • Light coral standard CSS color: #f08080 or rgb(240,128,128).

    Declaration

    Swift

    public static let lightCoral: Color
  • Salmon standard CSS color: #fa8072 or rgb(250,128,114).

    Declaration

    Swift

    public static let salmon: Color
  • Dark salmon standard CSS color: #e9967a or rgb(233,150,122).

    Declaration

    Swift

    public static let darkSalmon: Color
  • Light salmon standard CSS color: #ffa07a or rgb(255,160,122).

    Declaration

    Swift

    public static let lightSalmon: Color
  • Crimson standard CSS color: #dc143c or rgb(220,20,60).

    Declaration

    Swift

    public static let crimson: Color
  • red

    Red standard CSS color: #ff0000 or rgb(255,0,0).

    Declaration

    Swift

    public static let red: Color
  • Fire brick standard CSS color: #b22222 or rgb(178,34,34).

    Declaration

    Swift

    public static let fireBrick: Color
  • Dark red standard CSS color: #8b0000 or rgb(139,0,0).

    Declaration

    Swift

    public static let darkRed: Color

Pinks

  • Pink standard CSS color: #ffc0cb or rgb(255,192,203).

    Declaration

    Swift

    public static let pink: Color
  • Light pink standard CSS color: #ffb6c1 or rgb(255,182,193).

    Declaration

    Swift

    public static let lightPink: Color
  • Hot pink standard CSS color: #ff69b4 or rgb(255,105,180).

    Declaration

    Swift

    public static let hotPink: Color
  • Deep pink standard CSS color: #ff1493 or rgb(255,20,147).

    Declaration

    Swift

    public static let deepPink: Color
  • Medium violet red standard CSS color: #c71585 or rgb(199,21,133).

    Declaration

    Swift

    public static let mediumVioletRed: Color
  • Pale violet red standard CSS color: #db7093 or rgb(219,112,147).

    Declaration

    Swift

    public static let paleVioletRed: Color

Oranges

  • Coral standard CSS color: #ff7f50 or rgb(255,127,80).

    Declaration

    Swift

    public static let coral: Color
  • Tomato standard CSS color: #ff6347 or rgb(255,99,71).

    Declaration

    Swift

    public static let tomato: Color
  • Orange red standard CSS color: #ff4500 or rgb(255,69,0).

    Declaration

    Swift

    public static let orangeRed: Color
  • Dark orange standard CSS color: #ff8c00 or rgb(255,140,0).

    Declaration

    Swift

    public static let darkOrange: Color
  • Orange standard CSS color: #ffa500 or rgb(255,165,0).

    Declaration

    Swift

    public static let orange: Color

Yellows

  • Gold standard CSS color: #ffd700 or rgb(255,215,0).

    Declaration

    Swift

    public static let gold: Color
  • Yellow standard CSS color: #ffff00 or rgb(255,255,0).

    Declaration

    Swift

    public static let yellow: Color
  • Light yellow standard CSS color: #ffffe0 or rgb(255,255,224).

    Declaration

    Swift

    public static let lightYellow: Color
  • Lemon chiffon standard CSS color: #fffacd or rgb(255,250,205).

    Declaration

    Swift

    public static let lemonChiffon: Color
  • Light goldenrod yellow standard CSS color: #fafad2 or rgb(250,250,210).

    Declaration

    Swift

    public static let lightGoldenrodYellow: Color
  • Papaya whip standard CSS color: #ffefd5 or rgb(255,239,213).

    Declaration

    Swift

    public static let papayaWhip: Color
  • Moccasin standard CSS color: #ffe4b5 or rgb(255,228,181).

    Declaration

    Swift

    public static let moccasin: Color
  • Peach puff standard CSS color: #ffdab9 or rgb(255,218,185).

    Declaration

    Swift

    public static let peachPuff: Color
  • Pale goldenrod standard CSS color: #eee8aa or rgb(238,232,170).

    Declaration

    Swift

    public static let paleGoldenrod: Color
  • Khaki standard CSS color: #f0e68c or rgb(240,230,140).

    Declaration

    Swift

    public static let khaki: Color
  • Dark khaki standard CSS color: #bdb76b or rgb(189,183,107).

    Declaration

    Swift

    public static let darkKhaki: Color

Purples

  • Lavender standard CSS color: #e6e6fa or rgb(230,230,250).

    Declaration

    Swift

    public static let lavender: Color
  • Thistle standard CSS color: #d8bfd8 or rgb(216,191,216).

    Declaration

    Swift

    public static let thistle: Color
  • Plum standard CSS color: #dda0dd or rgb(221,160,221).

    Declaration

    Swift

    public static let plum: Color
  • Violet standard CSS color: #ee82ee or rgb(238,130,238).

    Declaration

    Swift

    public static let violet: Color
  • Orchid standard CSS color: #da70d6 or rgb(218,112,214).

    Declaration

    Swift

    public static let orchid: Color
  • Fuchsia standard CSS color: #ff00ff or rgb(255,0,255).

    Declaration

    Swift

    public static let fuchsia: Color
  • Magenta standard CSS color: #ff00ff or rgb(255,0,255).

    Declaration

    Swift

    public static let magenta: Color
  • Medium orchid standard CSS color: #ba55d3 or rgb(186,85,211).

    Declaration

    Swift

    public static let mediumOrchid: Color
  • Medium purple standard CSS color: #9370db or rgb(147,112,219).

    Declaration

    Swift

    public static let mediumPurple: Color
  • Blue violet standard CSS color: #8a2be2 or rgb(138,43,226).

    Declaration

    Swift

    public static let blueViolet: Color
  • Dark violet standard CSS color: #9400d3 or rgb(148,0,211).

    Declaration

    Swift

    public static let darkViolet: Color
  • Dark orchid standard CSS color: #9932cc or rgb(153,50,204).

    Declaration

    Swift

    public static let darkOrchid: Color
  • Dark magenta standard CSS color: #8b008b or rgb(139,0,139).

    Declaration

    Swift

    public static let darkMagenta: Color
  • Purple standard CSS color: #800080 or rgb(128,0,128).

    Declaration

    Swift

    public static let purple: Color
  • Rebecca purple standard CSS color: #663399 or rgb(102,51,153).

    Declaration

    Swift

    public static let rebeccaPurple: Color
  • Indigo standard CSS color: #4b0082 or rgb(75,0,130).

    Declaration

    Swift

    public static let indigo: Color
  • Medium slate blue standard CSS color: #7b68ee or rgb(123,104,238).

    Declaration

    Swift

    public static let mediumSlateBlue: Color
  • Slate blue standard CSS color: #6a5acd or rgb(106,90,205).

    Declaration

    Swift

    public static let slateBlue: Color
  • Dark slate blue standard CSS color: #483d8b or rgb(72,61,139).

    Declaration

    Swift

    public static let darkSlateBlue: Color

Greens

  • Green yellow standard CSS color: #adff2f or rgb(173,255,47).

    Declaration

    Swift

    public static let greenYellow: Color
  • Chartreuse standard CSS color: #7fff00 or rgb(127,255,0).

    Declaration

    Swift

    public static let chartreuse: Color
  • Lawn green standard CSS color: #7cfc00 or rgb(124,252,0).

    Declaration

    Swift

    public static let lawnGreen: Color
  • Lime standard CSS color: #00ff00 or rgb(0,255,0).

    Declaration

    Swift

    public static let lime: Color
  • Lime green standard CSS color: #32cd32 or rgb(50,205,50).

    Declaration

    Swift

    public static let limeGreen: Color
  • Pale green standard CSS color: #98fb98 or rgb(152,251,152).

    Declaration

    Swift

    public static let paleGreen: Color
  • Light green standard CSS color: #90ee90 or rgb(144,238,144).

    Declaration

    Swift

    public static let lightGreen: Color
  • Medium spring green standard CSS color: #00fa9a or rgb(0,250,154).

    Declaration

    Swift

    public static let mediumSpringGreen: Color
  • Spring green standard CSS color: #00ff7f or rgb(0,255,127).

    Declaration

    Swift

    public static let springGreen: Color
  • Medium sea green standard CSS color: #3cb371 or rgb(60,179,113).

    Declaration

    Swift

    public static let mediumSeaGreen: Color
  • Sea green standard CSS color: #2e8b57 or rgb(46,139,87).

    Declaration

    Swift

    public static let seaGreen: Color
  • Forest green standard CSS color: #228b22 or rgb(34,139,34).

    Declaration

    Swift

    public static let forestGreen: Color
  • Green standard CSS color: #008000 or rgb(0,128,0).

    Declaration

    Swift

    public static let green: Color
  • Dark green standard CSS color: #006400 or rgb(0,100,0).

    Declaration

    Swift

    public static let darkGreen: Color
  • Yellow green standard CSS color: #9acd32 or rgb(154,205,50).

    Declaration

    Swift

    public static let yellowGreen: Color
  • Olive drab standard CSS color: #6b8e23 or rgb(107,142,35).

    Declaration

    Swift

    public static let oliveDrab: Color
  • Olive standard CSS color: #808000 or rgb(128,128,0).

    Declaration

    Swift

    public static let olive: Color
  • Dark olive green standard CSS color: #556b2f or rgb(85,107,47).

    Declaration

    Swift

    public static let darkOliveGreen: Color
  • Medium aquamarine standard CSS color: #66cdaa or rgb(102,205,170).

    Declaration

    Swift

    public static let mediumAquamarine: Color
  • Dark sea green standard CSS color: #8fbc8f or rgb(143,188,143).

    Declaration

    Swift

    public static let darkSeaGreen: Color
  • Light sea green standard CSS color: #20b2aa or rgb(32,178,170).

    Declaration

    Swift

    public static let lightSeaGreen: Color
  • Dark cyan standard CSS color: #008b8b or rgb(0,139,139).

    Declaration

    Swift

    public static let darkCyan: Color
  • Teal standard CSS color: #008080 or rgb(0,128,128).

    Declaration

    Swift

    public static let teal: Color

Blues/Cyans

  • Aqua standard CSS color: #00ffff or rgb(0,255,255).

    Declaration

    Swift

    public static let aqua: Color
  • Cyan standard CSS color: #00ffff or rgb(0,255,255).

    Declaration

    Swift

    public static let cyan: Color
  • Light cyan standard CSS color: #e0ffff or rgb(224,255,255).

    Declaration

    Swift

    public static let lightCyan: Color
  • Pale turquoise standard CSS color: #afeeee or rgb(175,238,238).

    Declaration

    Swift

    public static let paleTurquoise: Color
  • Aquamarine standard CSS color: #7fffd4 or rgb(127,255,212).

    Declaration

    Swift

    public static let aquamarine: Color
  • Turquoise standard CSS color: #40e0d0 or rgb(64,224,208).

    Declaration

    Swift

    public static let turquoise: Color
  • Medium turquoise standard CSS color: #48d1cc or rgb(72,209,204).

    Declaration

    Swift

    public static let mediumTurquoise: Color
  • Dark turquoise standard CSS color: #00ced1 or rgb(0,206,209).

    Declaration

    Swift

    public static let darkTurquoise: Color
  • Cadet blue standard CSS color: #5f9ea0 or rgb(95,158,160).

    Declaration

    Swift

    public static let cadetBlue: Color
  • Steel blue standard CSS color: #4682b4 or rgb(70,130,180).

    Declaration

    Swift

    public static let steelBlue: Color
  • Light steel blue standard CSS color: #b0c4de or rgb(176,196,222).

    Declaration

    Swift

    public static let lightSteelBlue: Color
  • Powder blue standard CSS color: #b0e0e6 or rgb(176,224,230).

    Declaration

    Swift

    public static let powderBlue: Color
  • Light blue standard CSS color: #add8e6 or rgb(173,216,230).

    Declaration

    Swift

    public static let lightBlue: Color
  • Sky blue standard CSS color: #87ceeb or rgb(135,206,235).

    Declaration

    Swift

    public static let skyBlue: Color
  • Light sky blue standard CSS color: #87cefa or rgb(135,206,250).

    Declaration

    Swift

    public static let lightSkyBlue: Color
  • Deep sky blue standard CSS color: #00bfff or rgb(0,191,255).

    Declaration

    Swift

    public static let deepSkyBlue: Color
  • Dodger blue standard CSS color: #1e90ff or rgb(30,144,255).

    Declaration

    Swift

    public static let dodgerBlue: Color
  • Cornflower blue standard CSS color: #6495ed or rgb(100,149,237).

    Declaration

    Swift

    public static let cornflowerBlue: Color
  • Royal blue standard CSS color: #4169e1 or rgb(65,105,225).

    Declaration

    Swift

    public static let royalBlue: Color
  • Blue standard CSS color: #0000ff or rgb(0,0,255).

    Declaration

    Swift

    public static let blue: Color
  • Medium blue standard CSS color: #0000cd or rgb(0,0,205).

    Declaration

    Swift

    public static let mediumBlue: Color
  • Dark blue standard CSS color: #00008b or rgb(0,0,139).

    Declaration

    Swift

    public static let darkBlue: Color
  • Navy standard CSS color: #000080 or rgb(0,0,128).

    Declaration

    Swift

    public static let navy: Color
  • Midnight blue standard CSS color: #191970 or rgb(25,25,112).

    Declaration

    Swift

    public static let midnightBlue: Color

Browns

  • Cornsilk standard CSS color: #fff8dc or rgb(255,248,220).

    Declaration

    Swift

    public static let cornsilk: Color
  • Blanched almond standard CSS color: #ffebcd or rgb(255,235,205).

    Declaration

    Swift

    public static let blanchedAlmond: Color
  • Bisque standard CSS color: #ffe4c4 or rgb(255,228,196).

    Declaration

    Swift

    public static let bisque: Color
  • Navajo white standard CSS color: #ffdead or rgb(255,222,173).

    Declaration

    Swift

    public static let navajoWhite: Color
  • Wheat standard CSS color: #f5deb3 or rgb(245,222,179).

    Declaration

    Swift

    public static let wheat: Color
  • Burly wood standard CSS color: #deb887 or rgb(222,184,135).

    Declaration

    Swift

    public static let burlyWood: Color
  • tan

    Tan standard CSS color: #d2b48c or rgb(210,180,140).

    Declaration

    Swift

    public static let tan: Color
  • Rosy brown standard CSS color: #bc8f8f or rgb(188,143,143).

    Declaration

    Swift

    public static let rosyBrown: Color
  • Sandy brown standard CSS color: #f4a460 or rgb(244,164,96).

    Declaration

    Swift

    public static let sandyBrown: Color
  • Goldenrod standard CSS color: #daa520 or rgb(218,165,32).

    Declaration

    Swift

    public static let goldenrod: Color
  • Dark goldenrod standard CSS color: #b8860b or rgb(184,134,11).

    Declaration

    Swift

    public static let darkGoldenrod: Color
  • Peru standard CSS color: #cd853f or rgb(205,133,63).

    Declaration

    Swift

    public static let peru: Color
  • Chocolate standard CSS color: #d2691e or rgb(210,105,30).

    Declaration

    Swift

    public static let chocolate: Color
  • Saddle brown standard CSS color: #8b4513 or rgb(139,69,19).

    Declaration

    Swift

    public static let saddleBrown: Color
  • Sienna standard CSS color: #a0522d or rgb(160,82,45).

    Declaration

    Swift

    public static let sienna: Color
  • Brown standard CSS color: #a52a2a or rgb(165,42,42).

    Declaration

    Swift

    public static let brown: Color
  • Maroon standard CSS color: #800000 or rgb(128,0,0).

    Declaration

    Swift

    public static let maroon: Color

Whites

  • White standard CSS color: #ffffff or rgb(255,255,255).

    Declaration

    Swift

    public static let white: Color
  • Snow standard CSS color: #fffafa or rgb(255,250,250).

    Declaration

    Swift

    public static let snow: Color
  • Honeydew standard CSS color: #f0fff0 or rgb(240,255,240).

    Declaration

    Swift

    public static let honeydew: Color
  • Mint cream standard CSS color: #f5fffa or rgb(245,255,250).

    Declaration

    Swift

    public static let mintCream: Color
  • Azure standard CSS color: #f0ffff or rgb(240,255,255).

    Declaration

    Swift

    public static let azure: Color
  • Alice blue standard CSS color: #f0f8ff or rgb(240,248,255).

    Declaration

    Swift

    public static let aliceBlue: Color
  • Ghost white standard CSS color: #f8f8ff or rgb(248,248,255).

    Declaration

    Swift

    public static let ghostWhite: Color
  • White smoke standard CSS color: #f5f5f5 or rgb(245,245,245).

    Declaration

    Swift

    public static let whiteSmoke: Color
  • Seashell standard CSS color: #fff5ee or rgb(255,245,238).

    Declaration

    Swift

    public static let seashell: Color
  • Beige standard CSS color: #f5f5dc or rgb(245,245,220).

    Declaration

    Swift

    public static let beige: Color
  • Old lace standard CSS color: #fdf5e6 or rgb(253,245,230).

    Declaration

    Swift

    public static let oldLace: Color
  • Floral white standard CSS color: #fffaf0 or rgb(255,250,240).

    Declaration

    Swift

    public static let floralWhite: Color
  • Ivory standard CSS color: #fffff0 or rgb(255,255,240).

    Declaration

    Swift

    public static let ivory: Color
  • Antique white standard CSS color: #faebd7 or rgb(250,235,215).

    Declaration

    Swift

    public static let antiqueWhite: Color
  • Linen standard CSS color: #faf0e6 or rgb(250,240,230).

    Declaration

    Swift

    public static let linen: Color
  • Lavender blush standard CSS color: #fff0f5 or rgb(255,240,245).

    Declaration

    Swift

    public static let lavenderBlush: Color
  • Misty rose standard CSS color: #ffe4e1 or rgb(255,228,225).

    Declaration

    Swift

    public static let mistyRose: Color

Grays

  • Gainsboro standard CSS color: #dcdcdc or rgb(220,220,220).

    Declaration

    Swift

    public static let gainsboro: Color
  • Light gray standard CSS color: #d3d3d3 or rgb(211,211,211).

    Declaration

    Swift

    public static let lightGray: Color
  • Silver standard CSS color: #c0c0c0 or rgb(192,192,192).

    Declaration

    Swift

    public static let silver: Color
  • Dark gray standard CSS color: #a9a9a9 or rgb(169,169,169).

    Declaration

    Swift

    public static let darkGray: Color
  • Gray standard CSS color: #808080 or rgb(128,128,128).

    Declaration

    Swift

    public static let gray: Color
  • Dim gray standard CSS color: #696969 or rgb(105,105,105).

    Declaration

    Swift

    public static let dimGray: Color
  • Light slate gray standard CSS color: #778899 or rgb(119,136,153).

    Declaration

    Swift

    public static let lightSlateGray: Color
  • Slate gray standard CSS color: #708090 or rgb(112,128,144).

    Declaration

    Swift

    public static let slateGray: Color
  • Dark slate gray standard CSS color: #2f4f4f or rgb(47,79,79).

    Declaration

    Swift

    public static let darkSlateGray: Color
  • Black standard CSS color: #000000 or rgb(0,0,0).

    Declaration

    Swift

    public static let black: Color

Special

  • Transparent, invisible color.

    Declaration

    Swift

    public static let transparent: Color
  • Undocumented

    Declaration

    Swift

    case value(_: UInt32)
  • Undocumented

    Declaration

    Swift

    case RGB(_: UInt8, _: UInt8, _: UInt8, _: Float? = nil)
  • Undocumented

    Declaration

    Swift

    case HSL(_: Float, _: Float, _: Float, _: Float? = nil)
  • Undocumented

    Declaration

    Swift

    case CSS(_: String, _: UInt32? = nil)
  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws
  • Undocumented

    Declaration

    Swift

    func debugQuickLookObject() -> AnyObject
  • Declaration

    Swift

    public var playgroundDescription: Any { get }
  • Declaration

    Swift

    public typealias IntegerLiteralType = UInt32
  • Declaration

    Swift

    public init(integerLiteral integer: UInt32)