Hex to Android colors.xml converter
Paste hex colours with names and get colors.xml, a values-night file and Compose Color(0xAARRGGBB) constants. Android puts alpha first and CSS puts it last, so 8-digit values are converted rather than copied, and each resource name is checked.
Updated
Colours converted
5 colours
3 with a dark variant
res/values/colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="brand_primary">#FF6200EE</color>
<color name="brandSecondary">#FF03DAC5</color>
<color name="surface_tint">#FFFFFFFF</color>
<color name="scrim">#80000000</color>
<color name="color_b00020">#FFB00020</color>
</resources>| Name | As entered | Android #AARRGGBB | CSS #RRGGBBAA | Compose | Opacity |
|---|---|---|---|---|---|
| brand_primary | #6200EE | #FF6200EE | #6200EE | Color(0xFF6200EE) | 100% |
| brandSecondary | #03DAC5 | #FF03DAC5 | #03DAC5 | Color(0xFF03DAC5) | 100% |
| surface_tint | #FFFFFF | #FFFFFFFF | #FFFFFF | Color(0xFFFFFFFF) | 100% |
| scrim | #00000080 | #80000000 | #00000080 | Color(0x80000000) | 50% |
| color_b00020 | #B00020 | #FFB00020 | #B00020 | Color(0xFFB00020) | 100% |
| brand_primary (night) | #BB86FC | #FFBB86FC | #BB86FC | Color(0xFFBB86FC) | 100% |
| brandSecondary (night) | #03DAC6 | #FF03DAC6 | #03DAC6 | Color(0xFF03DAC6) | 100% |
| surface_tint (night) | #121212 | #FF121212 | #121212 | Color(0xFF121212) | 100% |
- 2 colour(s) have no dark variant, so values-night/colors.xml leaves them out and Android uses the values/ colour in dark mode.
- Renamed to valid resource names: Surface Tint → surface_tint.
- 1 colour(s) had no name, so they are called color_ plus their hex. Give them meaningful names (what it is for, not what it looks like) before shipping.
- 1 value(s) have 8 digits and were read as #RRGGBBAA (CSS order, alpha last). If the other order was meant, change “4 and 8 digit input” above.
- Colours with alpha are written with the alpha first for Android and Compose and last for CSS. 0x80 is about 50% opacity.
- Some names contain uppercase letters. Most Android projects write resource names in lowercase_with_underscores, so consider renaming them.
How are hex colours converted for Android?
Android puts the alpha channel first. A colour resource is #AARRGGBB, so #80FF6200 is a 50% opaque orange. CSS puts alpha last: the same colour is #FF620080. Both accept the short and opaque forms #RGB and #RRGGBB, so only 4-digit and 8-digit values are ambiguous, and the same eight characters mean different colours in the two orders. That is why this page asks how your input is written. A scrim written as #00000080 in a design tool is 50% black in CSS order; read as Android order it would be a nearly transparent colour with red 0, green 0, blue 0x80, which is a dark blue. The tool converts, it doesn't guess.
res/values/colors.xml holds one <color name="..."> element per colour. The name becomes the resource ID, referenced as @color/name in XML and R.color.name in code, so it has to be a valid identifier: letters, digits and underscores, not starting with a digit and not a Java keyword. A space or a hyphen can't be part of an identifier, so this tool rejects them, and “Fix invalid resource names” turns Surface Tint into surface_tint.
Dark mode uses the night qualifier. Colours in res/values-night/colors.xml replace the ones with the same name in res/values/colors.xml when the device is in night mode, and any name missing from values-night simply falls back to the default. The default file should always define every name, because a resource that exists only in a qualified folder can crash at runtime on a configuration that doesn't match it.
In Jetpack Compose the same colour is a Kotlin Long: Color(0xFF6200EE). The leading FF is alpha, so a 6-digit hex colour needs FF put in front of it. Forgetting that gives Color(0x6200EE), which is alpha 0 and draws nothing.
CSS #RRGGBBAA #FF620080 Android #AARRGGBB #80FF6200 (colors.xml) Compose 0xAARRGGBB Color(0x80FF6200) opacity alpha / 255 0x80 = 128 = 50.2%
Which hex formats does each platform accept?
| Digits | Android colors.xml | CSS | Compose Color(0x…) |
|---|---|---|---|
| 3 | #RGB, opaque | #RGB, opaque | not used |
| 4 | #ARGB (alpha first) | #RGBA (alpha last) | not used |
| 6 | #RRGGBB, opaque | #RRGGBB, opaque | write 0xFF then the six digits |
| 8 | #AARRGGBB (alpha first) | #RRGGBBAA (alpha last) | 0xAARRGGBB (alpha first) |
| 5, 7, other | rejected by the resource compiler | invalid | n/a |
How to convert hex colours to Android colors.xml
- 1Paste your coloursOne per line, as name: #6200EE. A bare #6200EE works too and gets a generated name. You can also paste lines from an existing colors.xml or from Compose.
- 2Say how 8-digit values are writtenChoose #RRGGBBAA if they come from CSS or a design tool, #AARRGGBB if they are already Android order. 6-digit colours are the same in both.
- 3Add dark variants if you have themUse the same names. Choose the values-night output to get the second file.
- 4Copy the output into your projectSave the XML as res/values/colors.xml (and res/values-night/colors.xml), or paste the Compose constants into Color.kt. The table shows each colour in all three byte orders.
Frequently asked questions
Why is my colour transparent or the wrong colour after pasting a web hex into colors.xml?
Can an Android colour resource name contain a hyphen or a space?
Do I need #FF in front of a 6-digit colour in colors.xml?
What happens to colours that are only defined in values-night?
How do I get opacity into a Compose colour?
Why does Compose need 0xFF before the colour?
Sources
- Android developers: More resource types, Color (#RGB, #ARGB, #RRGGBB, #AARRGGBB; res/values/colors.xml; @color/name) (checked 11 Nov 2026)
- Android developers: App resources overview, alternative resources and the night qualifier (values-night) (checked 11 Nov 2026)
- AOSP aapt2 ResourceUtils.cpp, TryParseColor (accepted colour lengths) (checked 11 Nov 2026)
- Jetpack Compose: androidx.compose.ui.graphics.Color (Color(0xFF0000FF) from a Long, alpha in [0..1]) (checked 11 Nov 2026)
- W3C CSS Color Module Level 4: hex notation (#RGB, #RGBA, #RRGGBB, #RRGGBBAA) (checked 11 Nov 2026)
Need a custom dev tool for your team?
We build internal tools, dashboards, APIs, and SaaS platforms. If you can describe it, we can ship it.
Built by CountryDevs · No signup · No ads · We count visits, never what you enter