Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make text bold, italic, or underline in React Native?

Surprisingly there isn't one question that groups these all together yet on Stack Overflow; there hasn't been an answer on SO for italics or underline, in fact, only this question for bold. I self-answered this quesiton below.

like image 743
James Ko Avatar asked May 27 '18 22:05

James Ko


People also ask

How do you bold text in react native?

Use inline styles to bold specific text in React. js, e.g. <span style={{fontWeight: 'bold'}}>world</span> . The bold font will only be applied to the element to which it was added and its children. Copied!

How do I add underline in text in react native?

In react native we can create underline text using textDecorationLine: 'underline' style prop. This prop works on both Android and iOS platforms.

How do you apply bold and underline the text?

Click the Bold button on the Formatting toolbar (Ctrl+B). Click the Italic button on the Formatting toolbar (Ctrl+I). Click the Underline button on the Formatting toolbar (Ctrl+U).


2 Answers

<Text style={styles.bold}>I'm bold!</Text> <Text style={styles.italic}>I'm italic!</Text> <Text style={styles.underline}>I'm underlined!</Text>  const styles = StyleSheet.create({     bold: {fontWeight: 'bold'},     italic: {fontStyle: 'italic'},     underline: {textDecorationLine: 'underline'} }) 

Working demo on Snack: https://snack.expo.io/BJT2ss_y7

like image 156
James Ko Avatar answered Oct 22 '22 22:10

James Ko


<View style={styles.MainContainer}>     <Text style={styles.TextStyle}>Example of Underline Text</Text> </View> 
TextStyle: {     textAlign: 'center',     fontWeight: 'bold'     fontStyle: 'italic'     fontSize: 20,     textDecorationLine: 'underline',     //line-through is the trick }, 
like image 41
Shivo'ham 0 Avatar answered Oct 22 '22 21:10

Shivo'ham 0