Custom Fonts In React Native: Pro Tip!
Tags: tutorial, javascript, reactnative, beginners
Published: 2024-05-07 12:10:25

So, recently, I was tasked with creating custom fonts for a React Native project, and I'm thrilled to share how I accomplished it!


![let me show you](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fmdzwsgropvqabtzdj1f.gif)



Hey there! In this episode, I'm going to guide you into making your React Native app look amazing with custom fonts across both iOS and Android. Don't worry if you're new to this; I'll walk you through step by step!

First things first, why do we need custom font files? Well, while iOS comes with a bunch of fonts, Android's options are a bit limited. So, if you want those pretty fonts on both platforms, custom fonts are the way to go.

You can snag font files from various places online. Google Fonts is a popular spot for freebies. Once you've got your font file downloaded, there's just one thing to watch out for: make sure the font file name matches the font family's full name. This ensures compatibility across platforms.

**Step 1: Download Custom Font Files**

Head over to a font repository like [Google Fonts] (https://fonts.google.com/) and choose a font you like. Let's say we pick "Briem Hand" from the search input. Download the font files by clicking Get Font, usually provided in a zip format.

![Font Briem](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0puffzaj05vjq4nyr9n3.png)

**Step 2: Extract and Rename Font Files**
Extract the zip file and find the font file you want to use. Rename it to match the font family's full name. You can find this name in the font information section of your system's font book.

For example, if the font's full name is "BriemHand-Variable-Font ," rename the file to "Briem Hand.ttf".
![Fullname font](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kf7rlspiny8r9kwumh78.png)

**Step 3: Add Font Files to Your React Native Project**
Create a folder named "fonts" within the "assets" directory of your React Native project. Place your custom font file inside this folder.

**Step 4: Configure React Native**
If you don't already have a "`react-native.config.js`" file, create one at the root of your project. Inside this file, export the configuration for React Native and specify the assets folder.


```javascript
module.exports = {
  assets: ['./assets/fonts/'],
};
```

**Step 5: Link Assets**
Run the command to link the assets to your iOS and Android projects:

```
npx react-native-asset
```

**Step 6: Define Styles with Custom Fonts**
In your app's main file or wherever you define your styles, set up styles for your text components. Include the custom font family pointing to your font file name.


```javascript
import React from 'react';
import { Text, View, StyleSheet } from 'react-native';

const styles = StyleSheet.create({
  main: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center'
  }
  customText: {
    color: 'black',
    fontSize: 30,
    fontFamily: 'Briem Hand'
  },
});

const App = () => {
  return (
    <View style={styles.main}>
      <Text style={styles.customText}>Hello, Custom Font!</Text>
    </View>
  );
};

export default App;
```

![result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d8m8se2tiju1626pm5mu.png)





 

And that's it! You're all set. Your custom fonts will now beautifully adorn your app on both iOS and Android without any platform-specific hassle.

_Until next time!..... Hope you will have a font-tastic journey ahead using custom fonts! 😃_


![cheers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/25nez2r5jjc92egz87y4.jpeg)