CHAPTER 09
Beginner
Styling in React Native
Updated: May 16, 2026
6 min read
# CHAPTER 9
Styling in React Native
1. Introduction
In web development, we use HTML for structure and external CSS files for design. React Native does not use CSS. If you try to use.class { color: red; }, your app will not compile. In React Native, all styling is written entirely in JavaScript using a concept called CSS-in-JS. In this chapter, we will master Styling in React Native. We will explore how to apply Inline Styles for rapid prototyping, how to use the highly optimized StyleSheet API for production design systems, and how to define colors, typography, borders, and shadows to build premium user interfaces.
2. Learning Objectives
By the end of this chapter, you will be able to:- Understand why React Native uses CSS-in-JS instead of standard CSS.
- Apply Inline Styles using JavaScript objects.
-
Implement production-grade styling using the
StyleSheetAPI.
- Style text typography (fonts, sizes, weights).
- Add borders, radii, and drop shadows to components.
3. The Rules of CSS-in-JS
Because styling in React Native is just JavaScript, there are strict syntax shifts from web CSS:-
1.
camelCase: CSS properties with hyphens become camelCase. (
background-colorbecomesbackgroundColor).
-
2.
Strings and Numbers: Pixel values are written as raw numbers (
width: 100). Color values are written as Strings (color: 'red'). Nopxsuffix is used!
-
3.
Objects: Styles are wrapped in JavaScript Objects
{}.
4. Inline Styling (The Quick Way)
You can style a component directly on the tag using thestyle prop.
Because it requires a JSX injection {} containing a JavaScript object {}, Inline styles require double curly braces {{}}!
javascript
*Note: Inline styling is great for testing, but terrible for performance if you have 100 components re-rendering.*
5. The StyleSheet API (The Professional Way)
For production apps, you define your styles at the bottom of the file using theStyleSheet.create() API.
This is heavily optimized by the React Native engine. It compiles the JavaScript styles into native C++ styling rules for maximum performance.
javascript
6. Combining Multiple Styles
What if you want a box to have the genericcontainer styles, but ALSO have an inline style to dynamically change its color based on state?
You can combine styles by passing an Array [] to the style prop!
The style on the *right* will override the style on the *left*.
javascript
7. Borders and Shadows
To make a component feel like a physical card, you add borders and shadows. *(Note: iOS and Android handle shadows completely differently. iOS usesshadowColor, Android requires the elevation property).*
javascript
8. Visual Learning: Web CSS vs Mobile Style
txt
9. Common Mistakes
-
Applying Text Styles to Views: In web HTML, if you apply
color: red;to a<div>, all the<p>tags inside it automatically inherit the red color. React Native does NOT support inheritance. If you applycolor: 'red'to a<View>, the app will crash because Views do not understand typography. You MUST apply text styles directly to the<Text>components!
10. Best Practices
-
Global Constants: Do not hardcode
#4A90E2into 50 different style sheets. Create a file calledcolors.js(export const colors = { primary: '#4A90E2' }) and import it into yourStyleSheetconfigurations. If the brand color changes, you update one single file.
11. Practice Exercises
-
1.
Convert this CSS rule into a valid React Native JavaScript property:
margin-bottom: 25px;.
-
2.
Write the JSX necessary to combine a
styles.boxobject and an inline{ padding: 10 }object using an array.
12. MCQs with Answers
Question 1
Why are Inline Styles (e.g., style={{ padding: 10 }}) generally discouraged for complex production layouts?
Question 2
When attempting to add a drop shadow to a <View> in React Native, what property MUST be included for the shadow to appear on an Android device?
13. Interview Questions
- Q: Explain the transition from CSS to CSS-in-JS regarding React Native. Identify three major syntax differences a web developer must adapt to.
-
Q: Describe the architectural benefit of placing
StyleSheet.create()outside of the main component function block.
- Q: Explain why CSS inheritance (e.g., applying font properties to a parent container) is intentionally excluded from the React Native rendering engine.
14. FAQs
Q: Can I use Tailwind CSS in React Native? A: Yes! The community has created a massive library calledNativeWind. It allows you to use standard Tailwind classes (like className="bg-blue-500 p-4 rounded-lg") perfectly on mobile, compiling them into Native StyleSheets automatically!
15. Summary
In Chapter 9, we transformed into mobile UI designers. We abandoned standard CSS and embraced the JavaScript-driven CSS-in-JS paradigm. We practiced rapid prototyping using double-bracketed Inline Styles, but quickly elevated our code to production standards using the highly optimizedStyleSheet.create() API. We successfully navigated the strict camelCase syntax, mastered combining styles via arrays, and implemented cross-platform shadows using both iOS offsets and Android elevation.