NUI in FiveM: How to Build an HTML UI for a Resource
Learn how to build an HTML UI for a FiveM resource with NUI: ui_page and files in fxmanifest, Lua-to-JS messages, JS-to-Lua callbacks, and focus.
Short answer
Put your HTML, CSS and JavaScript in a folder, point ui_page at the HTML file in your fxmanifest.lua, and list every UI file under files. Open the UI from Lua with SendNUIMessage, let the page send data back through RegisterNUICallback, and release focus with SetNuiFocus when the UI closes.
What NUI is
NUI is FiveM's way of showing a web page on top of the game. The official NUI development section describes it as an HTML-based UI system built on the Chromium Embedded Framework. You use it for menus, HUDs, phones and forms.
The page is separate from your Lua code. Lua and the page talk only by sending messages, so you design both sides as two small pieces that exchange data.
Resource layout
Example layout:
my-ui-resource/
├── fxmanifest.lua
├── client.lua
└── html/
├── index.html
├── app.js
└── style.css
fxmanifest entries
Example fxmanifest.lua:
fx_version 'cerulean'
game 'gta5'
client_script 'client.lua'
ui_page 'html/index.html'
files {
'html/index.html',
'html/app.js',
'html/style.css',
}
ui_pagepoints at one HTML file. The official docs say to specify a singleui_pagein the manifest.fileslists every client-side file the page loads. A file that is not listed is not shipped with the resource, so the page cannot load it.
The Lua side
Example client.lua (the command and the close handler are examples):
RegisterCommand('openui', function()
SetNuiFocus(true, true)
SendNUIMessage({ type = 'open', title = 'Example panel' })
end, false)
RegisterNUICallback('close', function(data, cb)
SetNuiFocus(false, false)
SendNUIMessage({ type = 'close' })
cb({ ok = true })
end)
SendNUIMessage takes one table and sends it to the page as JSON. The table is the message the page receives.
The HTML and JS side
Example html/index.html:
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="panel" hidden>
<h1 id="title"></h1>
<button id="close">Close</button>
</div>
<script src="app.js"></script>
</body>
</html>
Example html/app.js:
window.addEventListener('message', (event) => {
const data = event.data;
if (data.type === 'open') {
document.getElementById('title').textContent = data.title;
document.getElementById('panel').hidden = false;
}
if (data.type === 'close') {
document.getElementById('panel').hidden = true;
}
});
document.getElementById('close').addEventListener('click', () => {
fetch(`https://${GetParentResourceName()}/close`, {
method: 'POST',
headers: { 'Content-Type': 'application/json; charset=UTF-8' },
body: JSON.stringify({}),
});
});
The page receives Lua messages through the message event on window and reads event.data.
Sending messages both ways
Lua to JS: call SendNUIMessage from Lua, as shown above. The page reads it in its message listener.
JS to Lua: the page sends a POST request to https://${GetParentResourceName()}/<name>. Lua receives it with RegisterNUICallback('<name>', ...). The example above uses the name close.
The docs say to always return data through the callback. Call cb in every callback, even with a simple value such as { ok = true }. If you do not, the page's request waits for a reply that never comes.
Focus and closing
Call SetNuiFocus(true, true) when the UI opens so the player can use the keyboard and mouse on it. Release focus with SetNuiFocus(false, false) when it closes. The full-screen NUI page refers to focus through the SET_NUI_FOCUS native; check the reference for what the two boolean arguments control.
To close safely:
- Do the close in Lua: hide the page, release focus, and then reply with
cb. - Release focus in the same function that hides the UI, so the two never drift apart.
- Release focus when your resource stops. The
onResourceStopevent is the place to do this.
Common mistakes
- Leaving a file out of
files, so the page loads without it. - Forgetting
cbin aRegisterNUICallbackhandler, so the request hangs. - Setting focus to
trueand never releasing it, which leaves the player stuck with a cursor on screen. - Trusting the page alone. The player controls the browser, so decide anything that matters on the server or in Lua.
- Mixing up casing. The docs use
RegisterNUICallbackin one place andRegisterNuiCallbackin another, so check the reference for your build.
FAQ
Can I use React or Vue for the page?
Yes. The page is ordinary web code. Build it to plain files, then list every built file in files and point ui_page at the entry HTML file.
Why does my fetch from the page never finish?
Most often the Lua callback did not call cb. Add cb({ ok = true }) at the end of the handler and test again.
Do I need to set focus every time I send a message?
No. Focus is a separate call. Set it when the UI opens and release it when the UI closes, next to the message that shows or hides the page.
Sources
- Full-screen NUI (FiveM docs)
- NUI callbacks (FiveM docs)
- SendNUIMessage (FiveM Lua reference)
- RegisterNUICallback (FiveM Lua reference)
Last checked: 30 November 2026
Note: the official reference page for SetNuiFocus could not be opened when this was checked. The focus guidance above comes from the focus mention on the full-screen NUI page. Check the reference before you ship code that depends on the exact arguments.
FiveM.tools was founded with sponsorship from Nyru.