Sociologix
← Latest in AI

Digital experiences · · 6 min read

model-viewer: add click-to-load 3D to an AI-built website

Use a real poster, a deliberate Load 3D button and a still-image fallback instead of making every visitor start with a rotating scene.

By Sociologix Editorial

Official google/model-viewer GitHub repository preview identifying the interactive 3D web component.
Official google/model-viewer repository preview, retrieved December 5, 2026. This identifies the component; it is not a performance benchmark or a client website.Image source ↗

Give visitors a choice before the 3D scene

This AI-assisted editorial tutorial uses official model-viewer documentation checked December 5, 2026. The complete example below was tested in Edge with model-viewer 4.4.0: the poster appeared, the button changed to a loading state, the model rendered and an arrow key changed the view. A 390-pixel viewport had no horizontal overflow. Physical mobile devices and other browser engines were not tested.

When an AI coding worker adds a 3D product showcase, a useful brief is more specific than “make it immersive.” Ask for a readable still image, a deliberate way to enter 3D and a fallback if the scene cannot load. The official component supports interactive models on web pages; the Google repository distributes the component under Apache 2.0. [1]

This lab uses the public Astronaut sample rather than a client asset. It demonstrates a small interaction pattern, not an augmented-reality experience, a complete accessibility audit or a measured improvement in conversion.

1. Start with a poster and manual reveal

The loading API distinguishes a poster image, model preloading and revealing the rendered scene. With loading="lazy" and reveal="manual", dismissPoster() initiates loading and rendering as needed. The documentation also supports eager loading, which is a different choice. [2] Do not substitute eager loading and still describe the model as waiting for the visitor.

The example imports the component module at page startup, so it does not defer all JavaScript work until the click. It defers the model interaction through the documented manual path. If the library itself is too costly for your page budget, evaluate a separate on-demand module-loading design and measure it.

2. Run the complete small example

Save the HTML below as index.html in a new folder. From that folder, run python -m http.server 8010 --bind 127.0.0.1 and open http://127.0.0.1:8010 in a browser. Python documents this command-line server and address binding. Use it for local experimentation, not production hosting. [3]

The library import is pinned to version 4.4.0, verified from the package registry for this exercise. The module, model and poster URLs returned successfully during preparation. The sample is credited as Astronaut by Poly under CC BY 2.0 in the official examples; preserve that attribution and the linked source when reusing it. [4] Replace it with a model and poster you are authorized to publish for client work.

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Click-to-load 3D lab</title>
<style>
  body { max-width: 760px; margin: 40px auto; padding: 20px;
    font: 18px/1.6 system-ui; color: #17222b; }
  model-viewer { display: block; width: 100%; height: 420px;
    background: #f1f4f6; border-radius: 12px; }
  model-viewer img { width: 100%; height: 100%; object-fit: contain; }
  button { padding: 12px 24px; min-height: 44px; font: inherit; }
  :focus-visible { outline: 3px solid #087fa4; outline-offset: 4px; }
</style>
<h1>Explore the sample in 3D</h1>
<p>A still image is available while the 3D component initializes.</p>
<model-viewer id="viewer"
  src="https://modelviewer.dev/shared-assets/models/Astronaut.glb"
  poster="https://modelviewer.dev/assets/poster-astronaut.png"
  alt="A stylized astronaut wearing a white spacesuit"
  camera-controls touch-action="pan-y" disable-zoom
  loading="lazy" reveal="manual" interaction-prompt="none">
  <img slot="poster"
    src="https://modelviewer.dev/assets/poster-astronaut.png"
    alt="Still view of the sample astronaut">
</model-viewer>
<p><button id="load" disabled>Load 3D</button>
  <a href="https://modelviewer.dev/assets/poster-astronaut.png">Open still image</a></p>
<p id="status" role="status">Preparing the 3D controls...</p>
<p>Sample: Astronaut by Poly, <a href="https://creativecommons.org/licenses/by/2.0/">CC BY 2.0</a>,
  from the <a href="https://modelviewer.dev/examples/stagingandcameras/">official examples</a>.
  Model unchanged.</p>
<script type="module">
  const viewer = document.querySelector('#viewer');
  const button = document.querySelector('#load');
  const status = document.querySelector('#status');
  viewer.addEventListener('load', () => {
    status.textContent = '3D ready. Drag or use arrow keys to change the view.';
    button.hidden = true;
  });
  viewer.addEventListener('error', () => {
    status.textContent = '3D is unavailable. Open the still image instead.';
    button.disabled = true;
  });
  button.addEventListener('click', () => {
    button.disabled = true;
    status.textContent = 'Loading the 3D model...';
    viewer.dismissPoster();
  });
  try {
    await import('https://unpkg.com/@google/model-viewer@4.4.0/dist/model-viewer.min.js');
    button.disabled = false;
    status.textContent = 'Select Load 3D when you want to explore.';
  } catch {
    status.textContent = '3D controls are unavailable. Open the still image instead.';
  }
</script>
</html>

3. Keep the controls deliberate

camera-controls enables interaction with the model. The staging examples document that behavior and provide an option to disable viewer zoom so wheel and pinch gestures can retain browser behavior. [4] This lab uses disable-zoom, retains vertical touch scrolling through pan-y and omits auto-rotate. A still image remains available through a normal link.

The interaction prompt is disabled, and the script exposes readiness through a status region. It enables the Load 3D button only after the component import succeeds, disables it during loading and hides it after a successful load event. Import and model errors have separate messages. Those handlers are part of the example; failure branches were not exercised in the successful browser run.

4. Review the handoff with observable checks

In the tested run, the initial page showed the astronaut poster and an enabled Load 3D button after initialization. Clicking it displayed the loading message, followed by the ready message and rendered model. After focusing the model, a right-arrow key changed its orientation. That is evidence for this example in one browser, not certification across devices.

Ask the AI worker to preserve the fallback and explain every change to the loading attributes. Test the page with the network panel open on your own target devices: confirm when the GLB request starts, inspect its transfer cost and verify that the rest of the page stays usable. No network timing or frame-rate result is claimed here.

  • Before activation, confirm the real poster and its descriptive text are present.
  • After activation, confirm a useful loading state and a visible, controllable model.
  • Check keyboard focus, vertical page scrolling and the still-image link.
  • Exercise blocked-module, failed-model and low-capability-device paths before release.

5. Replace the demo with a meaningful business object

For an automotive page, the object might be an approved vehicle model; for an industrial service, a component whose shape matters to the buyer. Keep a useful static view and nearby product details even when the visitor never chooses 3D. Do not hide specifications, prices or the inquiry action inside the canvas.

Before production, review the model’s licensing, file size, geometry, textures and hosting policy. The public sample URLs are convenient for the lab, not a promise of a client asset service. Integrate the tested pattern into the site’s build, content-security policy and browser/device checks, then compare the visitor’s actual task with and without 3D.

Sources & further reading

  1. Google model-viewer repository and license
  2. Official model-viewer API source: loading, reveal and methods
  3. Python http.server command-line usage
  4. model-viewer staging and camera-control examples, including sample credits
  5. model-viewer loading examples

Make 3D earn its place on your website

Sociologix can help build AI-enabled websites with purposeful 3D interactions, useful fallbacks and a review process for performance, accessibility and customer tasks.

Talk to Sociologix