Use multiple font colors in a single label
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Using multiple font colors in a single label means styling only part of the text instead of the whole string uniformly. The exact technique depends on the UI technology: HTML uses nested elements, while native platforms often use attributed or rich-text APIs.
The key design question is not just "how do I color part of the text" but also whether the result stays readable, accessible, and semantically clear.
HTML and CSS: Use span Elements
On the web, the normal approach is to wrap each differently styled fragment in a span.
Then style the fragment:
This keeps the label as one logical piece of text while letting you style parts independently.
Multiple Colored Segments
You can split the string into as many pieces as needed.
This is a clean way to emphasize values, states, or warnings without breaking the text into separate controls.
UIKit: Use NSAttributedString
In native iOS development, a UILabel cannot assign multiple colors through its plain text property. You use an attributed string instead.
That gives one substring its own color while the rest of the label keeps the default styling.
Android: Use SpannableString
On Android, the equivalent idea is a SpannableString.
This is the usual approach when only part of the label needs emphasis.
Keep Accessibility in Mind
Multiple colors should support the meaning, not carry the meaning alone. For example, if the red text indicates an error, the words should also explicitly say something is wrong.
Good:
with the word Failed in red.
Weaker:
where only the color change suggests that something is different.
Color-only communication can fail for users with color-vision deficiencies or low-contrast displays.
Design Restraint Matters
Using multiple colors inside one label can improve scannability, but overuse turns the interface noisy. Usually it works best when only one fragment needs emphasis, such as:
- status words
- prices or totals
- warnings
- changed values
If every fragment is a different color, the label stops being easier to read.
Prefer Rich Text APIs Over Manual Layout Tricks
Sometimes developers try to fake multi-color text by stacking several labels side by side. That can work for simple layouts, but it becomes fragile when text wraps, localizes, or changes dynamically. Rich-text or attributed-text support is usually the better long-term solution because the content remains one logical label.
Common Pitfalls
- Trying to use one plain label property when the platform requires rich-text or attributed-text support.
- Splitting the text into too many styled fragments and making the UI visually noisy.
- Using color alone to communicate meaning.
- Choosing colors with poor contrast against the background.
- Forgetting that native and web platforms use different APIs for partial text styling.
Summary
- On the web, use nested
spanelements with CSS. - In iOS, use
NSAttributedStringfor substring styling. - In Android, use
SpannableStringand color spans. - Multi-color labels work best when only a small, meaningful part of the text is emphasized.
- Keep accessibility and contrast in mind so the label remains readable and understandable.

