HEX to Kotlin Color Converter
Convert any HEX color to Color(0xAARRGGBB) for Jetpack Compose, plus Color.rgb(), Color.parseColor(), and raw ARGB int. Copy-ready snippets in one click.
Light UI preview
Dark UI preview
Kotlin preview
Quick presets
Click any preset to load it. All are common Material and Compose colors.
Saved tokens
Tap the swatch to reload a saved token. Stored in your browser only.
Export formats
What is a HEX to Kotlin color converter?
A HEX to Kotlin color converter turns a HEX color code into a Kotlin Color(0xAARRGGBB) literal for Jetpack Compose, plus Color.rgb(), Color.argb(), Color.parseColor(), and a raw ARGB int. This converter handles 3, 4, 6, and 8-digit HEX codes, shows every Kotlin format at once, and lets you copy the snippet you need in one click.
Key takeaways
- HEX to Compose:
#FF5722becomesColor(0xFFFF5722). - Alpha first: Kotlin colors use ARGB order, so the leading
FFis the alpha channel. - Missing FF is the #1 bug:
0xFF5722becomes a fully transparent color. - Also get Color.rgb(), Color.argb(), Color.parseColor(), and raw ARGB int.
- Export a ready-to-paste Compose theme or Color.kt token file.
How to use the HEX to Kotlin color converter
Convert any HEX color to ready-to-paste Kotlin code in seconds. Follow these steps.
- Enter your HEX colorPaste a 3-digit or 6-digit HEX code with or without the # symbol. Optionally add an alpha channel (4 or 8 digits) to control opacity.
- Adjust alpha if you need transparencyUse the alpha slider or type an alpha value from 0 to 1. The tool updates every Kotlin format live, including Color(0xAARRGGBB).
- Copy the format you needChoose between Color(0xAARRGGBB) for Compose, Color.rgb() or Color.argb() for runtime construction, Color.parseColor() for View-based code, and a raw ARGB int for XML or Bundle use.
- See the color in contextThe preview shows the color on light and dark surfaces, with text contrast warnings so you know if the color works as a background.
- Round-trip checkPaste a Kotlin color back into the reverse tab to confirm you get the same HEX. Useful when porting a design token file into a Compose theme.
- Save and export your paletteSave the color as a token, or export a ready-to-paste Compose theme file with the color included.
HEX to Kotlin color cheat sheet
The table below shows the correct Kotlin form for the same HEX color across every common Android format.
| Format | Kotlin code | Where it is used |
|---|---|---|
| Compose Color | Color(0xFFFF5722) | Jetpack Compose theme and UI |
| Color.rgb | Color.rgb(255, 87, 34) | Compose, from individual channel ints |
| Color.argb | Color.argb(255, 255, 87, 34) | Compose, with alpha |
| Color.parseColor | Color.parseColor("#FF5722") | View-based code, string colors |
| Raw ARGB int | 0xFFFF5722.toInt() | XML, Bundle, legacy APIs |
| Color state list | ColorStateList.valueOf(0xFFFF5722.toInt()) | View backgrounds, tinting |
Why Kotlin colors start with 0xFF
Kotlin's Color constructor in Compose takes an ARGB ULong literal. ARGB stands for Alpha, Red, Green, Blue, so the first two hex digits are alpha. FF means fully opaque. 80 means 50 percent transparent. 00 means fully transparent.
If you pass Color(0xFF5722) (no leading FF), Kotlin treats it as a 24-bit value where alpha is 0x00. The color renders perfectly invisible. This is the single most common Compose color bug, and it happens because the constructor does not check digit count. Always include the leading FF unless you actually want transparency.
ARGB vs RGBA vs ARGB_8888
| Order | Example | Used by |
|---|---|---|
| ARGB | 0xAARRGGBB | Android, Compose, Color(0x…) |
| RGBA | 0xRRGGBBAA | CSS rgb(), some graphics APIs |
| RGB only | 0xRRGGBB | Web HEX — Kotlin expands it to 0xFFRRGGBB |
| ARGB_8888 | 8 bits per channel | Android bitmap format, highest quality |
The order matters. If you copy an RGBA value like 0xFF5722FF and paste it into Compose, you get a color that is very slightly transparent with the wrong hue. Use the ARGB form in Kotlin.
How to add alpha in Compose
There are two correct ways to add opacity to a Kotlin color:
- Set alpha in the literal:
Color(0x80FF5722)— 0x80 is 50 percent. - Use copy:
Color(0xFFFF5722).copy(alpha = 0.5f)— returns a new color, keeps the original hue.
The literal approach is best for design tokens. The copy approach is best for runtime state, hover, and pressed states. The alpha slider in the tool above uses the literal approach so the copied snippet is always self-contained.
Kotlin color formats in practice
Compose theme
In a Compose MaterialTheme, define colors in a Color.kt file as top-level vals, then reference them from a lightColorScheme() or darkColorScheme() call. This is the format the "Compose theme" export tab produces.
val BrandOrange = Color(0xFFFF5722)
private val LightColors = lightColorScheme(
primary = BrandOrange,
onPrimary = Color.White,
surface = Color(0xFFFAFAFA),
)
@Composable
fun AppTheme(content: @Composable () -> Unit) {
MaterialTheme(colorScheme = LightColors, content = content)
}
View-based Android
For View code, use Color.parseColor("#FF5722") or Color.rgb(255, 87, 34). Both are in android.graphics.Color and take plain values, so no ARGB prefix is needed — parseColor infers the alpha from the string length.
XML resources
In res/values/colors.xml, the alpha channel is optional. <color name="brand_orange">#FF5722</color> is valid and implicitly opaque. If you want alpha, use #80FF5722.
Common mistakes and how to fix them
- Missing alpha:
Color(0xFF5722)renders invisible. UseColor(0xFFFF5722). - Copying RGBA:
0xFF5722FFis RGBA, not ARGB. Swap to0xFFFF5722. - Using Compose Color in View code:
androidx.compose.ui.graphics.Coloris notandroid.graphics.Color. They are different classes. UseColor.parseColor()in View code. - Forgetting the ULong suffix: Some overloads require
0xFFFF5722UL.toLong()or0xFFFF5722u. The ComposeColor(Long)overload accepts aULongdirectly. - Wrong alpha convention: CSS uses 0..1 floats for alpha, Kotlin uses 0..255 ints.
0.5fin CSS is0x80in Kotlin.
Frequently asked questions
How do I write a HEX color in Kotlin?
The most common way in Jetpack Compose is Color(0xFFRRGGBB) where FF is the alpha channel. For example, #FF5722 becomes Color(0xFFFF5722). The alpha channel is required: without the leading FF, the value is interpreted as a very transparent color.
What does 0xFF in a Kotlin color mean?
0xFF is the alpha channel in ARGB order. FF means fully opaque. If you want 50 percent opacity, use 0x80. If you want fully transparent, use 0x00. The order is always alpha first, then red, green, blue: 0xAARRGGBB.
Why is my Kotlin color transparent?
You are probably passing 0xRRGGBB instead of 0xFFRRGGBB. Kotlin reads a Long literal as ARGB, so 0xFF5722 becomes a 24-bit color with alpha 0x00 — effectively invisible. Always include the leading alpha byte.
What is the difference between Color(0xAARRGGBB) and Color.parseColor()?
Color(0xAARRGGBB) is a Compose constructor that takes a ULong literal and is the standard way to declare colors in a Compose theme. Color.parseColor() is an older Android method that takes a "#RRGGBB" string. Use Color(0xAARRGGBB) inside Compose, and Color.parseColor() only in View-based code or when you already have a string color.
How do I convert a HEX color to ARGB int for Android?
Convert the HEX to an ARGB int by writing 0xAARRGGBB. In Kotlin this is an Int if you suffix with .toInt() or a Long otherwise. Example: #FF5722 becomes 0xFFFF5722.toInt(). The Kotlin tab on this page shows this exact code.
Does this converter support 3-digit HEX codes?
Yes. #F52 is expanded to #FF5522, then converted. 4-digit HEX (#F52A) is also supported, with the last digit treated as alpha.
What is the difference between ARGB and RGBA?
ARGB places alpha first (0xAARRGGBB), which is the Android and Compose convention. RGBA places alpha last (0xRRGGBBAA), which is the CSS convention. The Kotlin Color class expects ARGB, so use 0xAARRGGBB in Kotlin code.
How do I convert a HEX to a Color with opacity in Compose?
Use Color(0x80FF5722) for 50 percent alpha, or take an existing color and call copy(alpha = 0.5f). Both are shown in the Kotlin tab. The Color.copy function returns a new Color and keeps the original hue.
How do I use this HEX color in a Compose theme?
Declare it as a val at the top of your theme file, like val BrandOrange = Color(0xFFFF5722), and reference it inside a MaterialTheme colors block or a custom CompositionLocal. The Tailwind/Theme export tab on this page shows a ready-to-paste Compose theme.
What does Color.rgb() and Color.argb() do?
Color.rgb(red, green, blue) creates an opaque color from three 0..255 ints. Color.argb(alpha, red, green, blue) creates a color with alpha. Both are Compose functions. They are useful when you already have the channels as ints from a data source.
Is this tool free?
Yes. The HEX to Kotlin Color converter is free, needs no account, and runs entirely in your browser.
Does the converter upload my data?
No. All conversion runs in plain JavaScript in your browser. Nothing is uploaded, stored on a server, or shared.