React Native Render HTML

6.3.4 · active · verified Sun Apr 19

react-native-render-html is a powerful, open-source JavaScript component for React Native that translates HTML content into 100% native views across iOS, Android, macOS, and Windows. Unlike WebView-based solutions, it aims for improved performance and a truly native look and feel. The current stable version is v6.3.4, with the v6 "Foundry" release representing a major architectural rewrite focused on enhanced features, performance, and accessibility. The library is actively maintained with regular patch releases and significant minor updates (like v6.2.0 which focused on accessibility improvements). Key differentiators include its highly customizable and "hackable" API, extensive styling options, and robust support for custom renderers and HTML model definitions. It also ships with comprehensive TypeScript types, ensuring type safety for developers.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates rendering a complex HTML string using the `RenderHtml` component. It includes basic styling, links, images, lists, and utilizes `useWindowDimensions` for responsive rendering. It also showcases applying custom `tagsStyles`.

import React from 'react';
import { ScrollView, StyleSheet, useWindowDimensions, View } from 'react-native';
import { RenderHtml } from 'react-native-render-html';

const source = {
  html: `
    <h1>Hello from React Native!</h1>
    <p>This is a <strong>rich text</strong> example rendered by <code>react-native-render-html</code>.</p>
    <p>It supports <a href="https://meliorence.github.io/react-native-render-html/">links</a>, images, and various HTML elements.</p>
    <img src="https://reactnative.dev/img/tiny_logo.png" alt="React Native Logo" width="50" height="50" />
    <ul>
      <li>Item one</li>
      <li>Item two</li>
    </ul>
    <p style="color: #007bff; text-align: center;">Custom styles are also applied.</p>
  `
};

export default function App() {
  const { width } = useWindowDimensions();

  return (
    <View style={styles.container}>
      <ScrollView style={styles.scrollViewContent}>
        <RenderHtml
          contentWidth={width}
          source={source}
          tagsStyles={{
            p: {
              marginVertical: 5
            },
            h1: {
              color: 'purple'
            },
            a: {
              color: 'blue',
              textDecorationLine: 'underline'
            }
          }}
        />
      </ScrollView>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    paddingTop: 50,
    paddingHorizontal: 15,
    backgroundColor: '#fff',
  },
  scrollViewContent: {
    flex: 1
  }
});

view raw JSON →