HomeGuidesReferenceLearn

Reference version

ArchiveExpo SnackDiscord and ForumsNewsletter

WebView

GitHub

npm

A library that provides a WebView component.


react-native-webview provides a WebView component that renders web content in a native view.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb

Installation

Terminal
npx expo install react-native-webview

If you are installing this in an existing React Native app (bare workflow), start by installing expo in your project. Then, follow the additional instructions as mentioned by library's README under "Installation in bare React Native projects" section.

Usage

You should refer to the react-native-webview documentation for more information on the API and its usage. The following example (courtesy of that repository) is a quick way to get up and running!

Basic Webview usage
import * as React from 'react';
import { WebView } from 'react-native-webview';
%%placeholder-start%%%%placeholder-end%%import { StyleSheet } from 'react-native';
import Constants from 'expo-constants';

export default function App() {
  return (
    <WebView
      style={styles.container}
      source={{ uri: 'https://expo.dev' }}
    />
  );
}


const styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop: Constants.statusBarHeight,
  },
});

Minimal example with inline HTML:

Webview inline HTML
import * as React from 'react';
import { WebView } from 'react-native-webview';
%%placeholder-start%%%%placeholder-end%%import { StyleSheet } from 'react-native';
import Constants from 'expo-constants';

export default function App() {
  return (
    <WebView
      style={styles.container}
      originWhitelist={['*']}
      source={{ html: '<h1><center>Hello world</center></h1>' }}
    />
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop: Constants.statusBarHeight,
  },
});