Skip to main content
React Native Introduction
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 StyleSheet API.
  • 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. 1. camelCase: CSS properties with hyphens become camelCase. (background-color becomes backgroundColor).
  1. 2. Strings and Numbers: Pixel values are written as raw numbers (width: 100). Color values are written as Strings (color: 'red'). No px suffix is used!
  1. 3. Objects: Styles are wrapped in JavaScript Objects {}.

4. Inline Styling (The Quick Way)

You can style a component directly on the tag using the style prop. Because it requires a JSX injection {} containing a JavaScript object {}, Inline styles require double curly braces {{}}!
javascript
12345678910111213
import React from 'react';
import { View, Text } from 'react-native';

export default function App() {
  return (
    // Note the double curly braces!
    <View style={{ backgroundColor: &#039;dodgerblue&#039;, padding: 20 }}>
      <Text style={{ fontSize: 24, color: &#039;white&#039;, fontWeight: &#039;bold&#039; }}>
        Hello Styled World!
      </Text>
    </View>
  );
}

*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 the StyleSheet.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
1234567891011121314151617181920212223242526272829303132
import React from &#039;react&#039;;
import { View, Text, StyleSheet } from &#039;react-native&#039;;

export default function App() {
  return (
    // We reference the style object we created below!
    <View style={styles.container}>
      <Text style={styles.title}>Welcome Back!</Text>
      <Text style={styles.subtitle}>Please log in to continue.</Text>
    </View>
  );
}

// Defined OUTSIDE the component to prevent recreation on every render!
const styles = StyleSheet.create({
  container: {
    backgroundColor: &#039;#f5f5f5&#039;, // Hex codes work perfectly!
    padding: 30,
    marginTop: 50,
    borderRadius: 15, // Rounds the corners of the box
  },
  title: {
    fontSize: 28,
    fontWeight: &#039;800&#039;, // String for font weights
    color: &#039;#333&#039;,
  },
  subtitle: {
    fontSize: 16,
    color: &#039;gray&#039;,
    marginTop: 10,
  }
});

6. Combining Multiple Styles

What if you want a box to have the generic container 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
1
<View style={[ styles.container, { backgroundColor: isError ? &#039;red&#039; : &#039;green&#039; } ]}>

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 uses shadowColor, Android requires the elevation property).*
javascript
1234567891011121314151617
const styles = StyleSheet.create({
  card: {
    backgroundColor: &#039;white&#039;,
    padding: 20,
    // BORDERS
    borderWidth: 2,
    borderColor: &#039;lightgrey&#039;,
    borderRadius: 10,
    // iOS SHADOWS
    shadowColor: &#039;#000&#039;,
    shadowOffset: { width: 0, height: 2 },
    shadowOpacity: 0.25,
    shadowRadius: 3.84,
    // ANDROID SHADOWS
    elevation: 5, 
  }
});

8. Visual Learning: Web CSS vs Mobile Style

txt
123456
[ Web CSS ]                           [ React Native JS ]
.my-card {                            myCard: {
  background-color: blue;               backgroundColor: &#039;blue',
  font-size: 16px;                      fontSize: 16,
  padding-top: 10px;                    paddingTop: 10
}                                     }

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 apply color: '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 #4A90E2 into 50 different style sheets. Create a file called colors.js (export const colors = { primary: '#4A90E2' }) and import it into your StyleSheet configurations. If the brand color changes, you update one single file.

11. Practice Exercises

  1. 1. Convert this CSS rule into a valid React Native JavaScript property: margin-bottom: 25px;.
  1. 2. Write the JSX necessary to combine a styles.box object 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 called NativeWind. 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 optimized StyleSheet.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.

16. Next Chapter Recommendation

Our boxes and text look beautiful, but they are all stacked on top of each other in the corner. We need to arrange them. Proceed to the most important layout chapter: Chapter 10: Flexbox Layout in React Native.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·