how to set background color to the text only in react native

ketan kulkarni picture ketan kulkarni · Jul 16, 2018 · Viewed 16.5k times · Source

in html I can achieve this by

<span style="background-color:red">ketan</span>

but in react native how to implement this so that color will be applied to the text only.

Answer

Raphael Estrada picture Raphael Estrada · May 9, 2019

If you want the background color to only encompass the text, you can use this:

<Text style={{backgroundColor: 'blue', alignSelf: 'flex-start'}}>
    Ketan
</Text>

And just change alignSelf as needed, you need to set this property if you dont want the text to take the whole width of the container