React Navigation 6: Header background and header title color

Updated: January 18, 2022 By: A Goodman Post a comment

When using React Navigation 6 to route and navigate your React Native apps, the header bar background color and the header title color are customizable.

To set the header background color, use this option:

headerStyle: {
   backgroundColor: '#833471', 
   // use your preferred color code
}

For the header title color, use:

headerTitleStyle: {
  color: '#fff',
  // use your preferred color code
}

Full example:

import React from 'react';
import {View, Text, StyleSheet} from 'react-native';
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';

const MainStack = createNativeStackNavigator();

const HomeScreen = props => {
  return (
    <View style={styles.screen}>
      <Text>Home Screen</Text>
    </View>
  );
};

function App() {
  return (
    <NavigationContainer>
      <MainStack.Navigator>
        <MainStack.Screen
          name="home"
          component={HomeScreen}
          options={{
            title: 'Home Title',
            headerTitleStyle: {
              color: '#fff',
            },
            headerStyle: {
              backgroundColor: '#833471',
            },
          }}
        />
      </MainStack.Navigator>
    </NavigationContainer>
  );
}

export default App;

/// Just some styles
const styles = StyleSheet.create({
  screen: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});

Screenshot:

Hope this article can help you in some way. Further reading:

You can also check our React topic page and React Native topic page for the latest tutorials and examples.

Related Articles