react · React Basics
How do you write an inline style which specifies the font-size:12px and color:red; in JSX?
Answers
- style={{font-size:12,color:'red'}}
- style={{fontSize:'12px',color:'red'}}
- style={fontSize:'12px',color:'red'}
- style={{font-size:12px,color:'red'}}
Attention: Please fill out all required fields.
); } ``` ## Best Practices and Additional Insights - Although JSX allows inline styling, it's best to avoid it for large chunks of CSS and maintainability. Instead, use it for dynamic and small-scale styles. - Properties that accept numeric values (such as `margin`, `padding`, `fontSize`) can also be written without the quotes and unit, e.g., `fontSize:12` is also valid in JSX, assuming the size unit as pixels. - JSX also allows the use of conditional styling, where styles can change based on certain conditions. By understanding the unique syntax of inline styles in JSX, you can efficiently style your React elements and create dynamic, visually pleasing web applications.