Santa & Christmas Edition36 maps, limited runlimited runShop the drop
Chapter 04 of 8The Loading Screens Handbook for FiveM

Building the loading screen in HTML or React

In short

Plain HTML, CSS and JavaScript are enough for a very good loading screen. React with Vite earns its place once the screen has tabs, carousels and state to keep track of.

index.html
<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <link rel="stylesheet" href="style.css" />
</head>
<body>
  <video class="bg" src="assets/bg.webm" poster="assets/poster.webp" autoplay muted loop playsinline></video>
  <main class="panel">
    <img class="logo" src="assets/logo.png" alt="Night City RP" />
    <p id="status">Loading…</p>
    <div class="bar"><span id="fill"></span></div>
  </main>
  <audio id="music" src="assets/music.mp3" autoplay loop></audio>
  <script src="script.js"></script>
</body>
</html>
script.js
const fill = document.getElementById('fill');
const status = document.getElementById('status');
const music = document.getElementById('music');
let shown = 0;

music.volume = Number(localStorage.getItem('vol') ?? 0.3);

window.addEventListener('message', (e) => {
  const d = e.data;
  if (d.eventName === 'loadProgress') {
    shown = Math.max(shown, d.loadFraction);   // never go backwards
    fill.style.width = `${Math.round(shown * 100)}%`;
  }
  if (d.eventName === 'onLogLine') status.textContent = d.message;
});

const data = window.nuiHandoverData || {};
if (data.name) status.textContent = `Welcome, ${data.name}`;

The script listens for two of the messages the client posts to the page. loadProgress carries loadFraction, a number from 0 to 1, and the Math.max keeps the bar from ever moving backwards. onLogLine carries a message that works as a status line. The remaining messages are listed in the cheat sheet on the handbook page.

  • With React and Vite, set base: './' so that asset paths come out relative, point loadscreen at the built index.html and list the build folder in files.
  • Mock the loading messages while npm run dev is running, so the screen can be designed in an ordinary browser.
  • The player can read handover data, so send only small values that are not sensitive.

The Loading Screens Handbook for FiveM

This chapter is one of 8. The handbook also carries the manifest, message, server list and NUI cheat sheets, a glossary and the official references every chapter is checked against.

Open the handbook