Style parts of text

You can style parts of text to improve readability, increase positive user experience, and encourage greater creativity through use of colors and fonts.

Version compatibility

This implementation requires that your project minSDK be set to API level 21 or higher.

Dependencies

Style parts of text

The following code displays the string "Hello World" using blue for the "H", red for the "W", and black for the rest of the text. To set different styles within a single Text composable, use the following code:

Key points about the code

Results

 Hello World text with multiple styles
Figure 1. A line of text with multiple styles.

Parent collections

Text is a central piece of any UI. Find out different ways you can present text in your app to provide a delightful user experience.

Have questions or feedback

Go to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts.