Works on this device
Flutter Color Converter
Type a colour as in CSS, such as #3366cc or rgba(51, 102, 204, 0.5), and get the Flutter forms Color(0xFF3366CC), Color.fromARGB and Color.fromRGBO. Paste a Flutter colour to get the CSS hex and rgb() values. Or turn a list of named colours into a Dart class of constants. Nothing is run or sent.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose Convert.
Your result
How it was worked out
How to use the Flutter colour converter
- Choose CSS colour to Flutter and type a colour: hex (
#3366cc,#3366cc80,f80),rgb(),rgba(),hsl()or a name such asteal. - Copy
Color(0x...),Color.fromARGB(...)orColor.fromRGBO(...)into your Dart code. - To go back, choose Flutter to CSS and paste a Flutter colour.
- For a whole set, choose Palette to a Dart class, write one name and colour on each line, and copy the class.
How Flutter writes a colour
- A Flutter
Coloris 32 bits: alpha (opacity), red, green and blue, each from 0 to 255, written as two hexadecimal digits. In0xAARRGGBBthe alpha comes first:0xFFis solid and0x00is fully transparent. - CSS writes the alpha last:
#3366cc80isColor(0x803366CC)in Flutter. Color.fromARGB(a, r, g, b)takes the same four numbers from 0 to 255.Color.fromRGBO(r, g, b, opacity)takes an opacity from 0.0 to 1.0. Flutter before version 3.27 took the whole part of opacity × 255 as the alpha; later versions round it. The tool writes the shortest opacity for which both give the same alpha, so 128 is written as 0.502, not 0.5.- An opacity from CSS becomes the alpha round(opacity × 255): 0.5 is 128 (0x80) and 0.25 is 64 (0x40).
- A common mistake:
Color(0x3366CC)has only 6 digits, so its alpha is 00 and it is invisible. The tool warns about it.
Worked example
#3366cc: 33, 66 and CC in hexadecimal are 51, 102 and 204, and the colour is solid, so the alpha is FF (255). In Flutter it is Color(0xFF3366CC), Color.fromARGB(255, 51, 102, 204) or Color.fromRGBO(51, 102, 204, 1.0).
rgba(51, 102, 204, 0.5) has the alpha round(0.5 × 255) = 128 = 0x80: Color(0x803366CC) and Color.fromRGBO(51, 102, 204, 0.502).
Limits you should know
- Colours are 8-bit sRGB. A colour outside sRGB, such as some
oklch()colours, is clipped and marked. - Named Material colours such as
Colors.blueand the newerColor.from(alpha:, red:, green:, blue:)are not read. Type the value instead. - For other colour codes (HSL, CMYK, CSS names), use the Color Code Converter.