Menu

Three Hex Color Bugs That Survive Code Review
πŸ“°

Three Hex Color Bugs That Survive Code Review

DEV Community: cssΒ·zhihu wuΒ·13 days ago
#GgDQAQDe
#devtocss#devto#dev#rrggbbaa#aarrggbb
Reading 0:00
15s threshold

Designers hand off hex strings. Developers paste them. And three times out of ten the string is fine and the render is still wrong β€” because a hex value is not a color, it's a set of numbers that each platform reads differently.

1. Eight digits, two different channel orders

CSS defines 8-digit hex as #RRGGBBAA β€” alpha last. Android, Flutter and Kotlin define it as #AARRGGBB β€” alpha first. So #80FF0000 is:

CSS: red 0x80 , green 0xFF , blue 0x00 , alpha 0x00 β†’ completely invisible. Your UI element quietly disappears.

Android: alpha 0x80 , red 0xFF , green 0x00 , blue 0x00 β†’ a 50% red overlay.

Same literal, opposite meaning, no error anywhere. Six-digit hex is safe because all three channels are present in the same order; the moment you add the fourth pair you have an ambiguous string. Hand off rgba(255, 0, 0, 0.5) or a 6-digit hex plus a separate opacity token instead.

2.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.