In short
FiveM NUI lets you show HTML, CSS and JavaScript interfaces in a browser layer that runs on top of the game. You define the page with ui_page and files in fxmanifest, send data from Lua with SendNUIMessage, and POST from the UI with fetch, which you catch with RegisterNUICallback. SetNuiFocus manages mouse and keyboard focus, and every callback must call cb().
In this guide
FiveM NUI (New UI) is the system that lets you add interfaces written in HTML, CSS and JavaScript into the game. Almost every modern-looking panel, like an inventory, phone, banking menu or character creator, is built with NUI. The flow has three parts: you define the page in the manifest with ui_page, send data from Lua to the UI with SendNUIMessage, and reply from the UI to Lua with a fetch request and RegisterNUICallback.
How does NUI work?
The FiveM client places a transparent browser layer (Chromium Embedded Framework, or CEF) on top of the game. Each resource can open its own HTML page in this layer. The page works like a normal web page; the difference is that it gets its data from the client Lua code in the same resource, not from a web server.
- Lua → UI:
SendNUIMessage({...})converts a Lua table to JSON and delivers it to the page as amessageevent. - UI → Lua: The page sends a POST request to
https://kaynak_adi/callback_adi(resource name / callback name); on the Lua side,RegisterNUICallbackcatches that request. - Focus:
SetNuiFocus(true, true)gives keyboard and mouse input to the UI; when closing, you take it back withSetNuiFocus(false, false).
If you don't have a foundation in the client/server split, events and fxmanifest.lua, we recommend reading our guide to writing your first FiveM script in Lua first.
Step by step: A simple NUI menu
1. Folder structure and manifest
resources/
└── basit_menu/
├── fxmanifest.lua
├── client.lua
└── html/
├── index.html
├── style.css
└── script.js
fx_version 'cerulean'
game 'gta5'
lua54 'yes'
client_script 'client.lua'
ui_page 'html/index.html'
files {
'html/index.html',
'html/style.css',
'html/script.js'
}
The files block is required: files not listed here aren't sent to the player, and the page opens blank. If you have many files, you can use wildcards like 'html/**/*'.
2. HTML and JavaScript
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="menu" class="gizli">
<h2 id="baslik"></h2>
<button id="onayla">Onayla</button>
<button id="kapat">Kapat</button>
</div>
<script src="script.js"></script>
</body>
</html>
const menu = document.getElementById('menu');
const kaynak = GetParentResourceName();
function lua(callback, veri = {}) {
return fetch(`https://${kaynak}/${callback}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json; charset=UTF-8' },
body: JSON.stringify(veri)
}).then(r => r.json());
}
window.addEventListener('message', (e) => {
const d = e.data;
if (d.action === 'ac') {
document.getElementById('baslik').textContent = d.baslik;
menu.classList.remove('gizli');
} else if (d.action === 'kapat') {
menu.classList.add('gizli');
}
});
document.getElementById('onayla').addEventListener('click', () => {
lua('onayla', { secim: 'evet' }).then(cevap => console.log(cevap));
});
document.getElementById('kapat').addEventListener('click', () => lua('kapat'));
document.addEventListener('keyup', (e) => {
if (e.key === 'Escape') lua('kapat');
});
GetParentResourceName() is a function automatically defined in the NUI environment that returns the resource name. If you use it instead of hardcoding the resource name, the UI won't break when the folder name changes. In your CSS, leave the body background transparent and define a .gizli { display: none; } (hidden) class.
3. Client Lua
local acik = false
local function menuKapat()
acik = false
SetNuiFocus(false, false)
SendNUIMessage({ action = 'kapat' })
end
RegisterCommand('menu', function()
if acik then return end
acik = true
SetNuiFocus(true, true)
SendNUIMessage({ action = 'ac', baslik = 'OyunBulut Test Menusu' })
end, false)
RegisterNUICallback('kapat', function(data, cb)
menuKapat()
cb({ ok = true })
end)
RegisterNUICallback('onayla', function(data, cb)
print('Secim: ' .. tostring(data.secim))
-- If a persistent action is needed, send it to the server:
-- TriggerServerEvent('basit_menu:onay', data.secim)
menuKapat()
cb({ ok = true })
end)
AddEventHandler('onResourceStop', function(res)
if res == GetCurrentResourceName() and acik then
SetNuiFocus(false, false)
end
end)
The critical rule: every RegisterNUICallback must call cb(...). If it doesn't, the fetch on the JavaScript side waits for a response and hangs. The onResourceStop block matters too; if the resource is restarted while the menu is open, the player's mouse won't get stuck in the UI.
Using images, fonts and files from other resources
You also need to add the images and font files your UI uses to the files block; any file not listed fails to load with a 404 error. To access a file in another resource, such as your inventory's item icons, you can use an address in the form nui://kaynak_adi/yol/dosya.png (resource name/path/file). This keeps you from copying the same icons into every UI resource and making players download them twice. Bundling fonts inside the resource instead of pulling them from an external site also prevents the UI from lagging on open or looking broken during network issues.
Security: Don't trust data coming from the UI
NUI runs on the player's PC. A player can trigger your callbacks with any data they want, using methods similar to browser developer tools. So prices, quantities or item names coming from the UI must never be used directly; they must be re-validated on the server side. The UI should only carry "the player selected this item", while the server decides the price and the permission.
Modern UIs with React or Vue
In complex UIs (phone, inventory, tablet), plain JavaScript quickly becomes hard to manage. A common approach is to build the UI as a separate project with a framework like React, Vue or Svelte using Vite, then put the compiled output into the resource.
- Create a
webfolder inside the resource and set up a Vite project:npm create vite@latest web - Set
base: './'in yourvite.configfile; otherwise the built files are looked up by absolute path and won't load inside NUI. - Run
npm run buildto output to theweb/distfolder. - Update the manifest to point to the build output:
ui_page 'web/dist/index.html'
files {
'web/dist/index.html',
'web/dist/assets/*'
}
In React, listen for the message event inside a useEffect and write it to state; in Vue, add the listener inside onMounted. The fetch helper function is the same as in the example above.
Important security warning: During development, you can pointui_pageat a local Vite dev server for hot reload. But never run the Vite dev server on a VDS or server on a publicly exposed port. Dev servers left open to the internet can be scanned by attackers and used to take over the server. Upload only thenpm run buildoutput to your live server, notnode_modulesor the source folder.
NUI performance tips
Because NUI runs as a separate browser process on the player's PC, a badly written UI directly lowers FPS. Watch out for:
- Don't send messages every frame: Calling
SendNUIMessageinside aWait(0)loop is the most common mistake. Send only when a value changes; for continuous data like a HUD, a 100-250 ms interval is usually enough. - Actually hide closed UIs: Use
display: none; elements with zero opacity that still render also consume resources. - Avoid heavy CSS effects:
backdrop-filter, large shadows and constantly running animations cause noticeable drops for players on low-end hardware. - Keep images local and optimized: Images loaded from a remote server add latency; package item icons inside the resource as small WebP files.
- Keep the bundle size small: Remove libraries you don't use; UI files are downloaded by every player.
- Measure the Lua side too: Check the cost of the loops feeding the UI using the method in our guide to optimizing scripts with resmon.
For the official list of NUI functions, see the FiveM NUI development docs.
Common NUI problems
| Symptom | Likely cause |
|---|---|
| The UI doesn't show at all | The file isn't in the files block, or the ui_page path is wrong |
| The mouse is stuck in the UI | SetNuiFocus(false, false) wasn't called; check the close path and the ESC listener |
| Clicking a button does nothing | The callback name doesn't match, or cb() isn't called |
| The React build opens a blank page | The Vite base setting isn't './' |
To see UI errors, you can use the NUI developer tools; typing nui_devtools in the F8 console of the FiveM client opens an inspector window similar to the one in your browser.
Speeding up UI development
NUI projects require both Lua and HTML/CSS/JavaScript skills, and a phone or inventory UI is made up of dozens of components. Generating component skeletons, the message protocol and stylesheets with AI saves serious time; since UI projects consume a lot of tokens, the AI Developer Ultimate plan with 6M token capacity is the largest plan, designed for big jobs like these.
If you'd rather receive it ready-made with design and server integration included, you can describe what you need through OyunBulut's FiveM Developer Service and have a custom UI built for your server.
What's next
Install the basit_menu resource from this guide and test it with the /menu command, then grow the same skeleton with React or Vue. If you're doing the UI work yourself, compare the AI plans, or if you want to hand it off, the developer service, on the FiveM packages and services page.
Frequently asked questions
What is FiveM NUI?
NUI (New UI) is the Chromium-based browser layer the FiveM client places on top of the game. Each resource can show its own interface in this layer using HTML, CSS and JavaScript.
Why isn't my NUI interface showing?
The most common reason is that the HTML, CSS or JS files aren't listed in the files block of fxmanifest, or the ui_page path is wrong.
Can I use React or Vue in NUI?
Yes. You build the UI with Vite and put the output inside the resource; you need to set base to './' in vite.config.
The mouse stays on screen after closing NUI. What should I do?
Make sure your close flow calls SetNuiFocus(false, false) and that there's a close callback for the ESC key.
Does NUI lower FPS?
Badly written UIs do. Sending SendNUIMessage every frame, continuing to render hidden elements and heavy CSS effects are the most common causes.