API

Babylon.js Viewer (V1)

Display 3D models on your webpage

The Babylon.js viewer is the simplest way to display 3D content on a web page.

To display a 3D model on your web page:

  1. Add a script reference to the viewer

    <script src="https://cdn.babylonjs.com/viewer/babylon.viewer.js"></script>
  2. Add a <babylon> tag and set the model attribute to point to a .gltf or .glb file

    <babylon model="model.gltf"></babylon>

    We recommend using the glTF format (.gltf or .glb) for displaying 3D models on your webpage. Other formats supported by Babylon.js loaders are also supported by the viewer component, including .babylon, .obj, and .stl.

The Babylon.js viewer automatically provides a default viewing experience for 3D models. All aspects of this experience are configurable. See Configuring the viewer for more information on customizing the viewing experience.

Example

Resizing

Controlling the size of the viewer is one of the most common configuration operations. It is fairly easy, as the viewer in default mode fills 100% of the width and height of its container. To control the viewer, you can simply style its enclosing container.

Using the viewer in your project

The Babylon.js viewer is available on a CDN as well as an NPM package. The Babylon.js viewer is a wrapper around the Babylon.js engine and follows the same versioning scheme as the engine. The current stable version of the Babylon.js viewer uses the current stable version of the Babylon.js engine, and the preview version of the Babylon.js viewer uses the preview version of the Babylon.js engine.

CDN

Stable versions of the viewer are available on:

Preview releases (nightlies) of the viewer are available on:

NPM

To install the Babylon.js viewer through NPM, use:

npm install --save babylonjs-viewer

This will install the latest stable version of the viewer, including its needed dependencies.

Afterward, it can be imported into the project using:

import "babylonjs-viewer";

This will enable the BabylonViewer namespace.

Further reading

Configuring the Babylon.js Viewer
How to configure the Babylon.js viewer.
Configuring the Babylon.js Viewer
Babylon.js Viewer Templating System
Using and extending the viewer's simple integrated templating system.
Babylon.js Viewer Templating System
Modify the Babylon.js Viewer
Modifying the Babylon.js viewer using HTML.
Modify the Babylon.js Viewer
Babylon.js Viewer - Advanced usage
Advanced uses of the viewer.
Babylon.js Viewer - Advanced usage
Babylon.js Viewer Examples
Examples of using the viewer
Babylon.js Viewer Examples

    Coming next

    Babylon.js Viewer Templating System
    Using and extending the viewer's simple integrated templating system.
    Babylon.js Viewer Templating System
    Modify the Babylon.js Viewer
    Modifying the Babylon.js viewer using HTML.
    Modify the Babylon.js Viewer
    Babylon.js Viewer - Advanced usage
    Advanced uses of the viewer.
    Babylon.js Viewer - Advanced usage
    Babylon.js Viewer Examples
    Examples of using the viewer
    Babylon.js Viewer Examples
    Configuring the Babylon.js Viewer
    How to configure the Babylon.js viewer.
    Configuring the Babylon.js Viewer