NUI (HTML UI)
Build interfaces with HTML, CSS and JavaScript.
Developer Preview. Scripting is live on Neighborly servers – everything on these pages works today. The API is young, so tell us what you need next on Discord.
NUI lets you build interfaces with HTML, CSS and JavaScript – phones, shops, menus, HUDs, tablets. Your page is shown in the Neighborly overlay on top of the game, with a transparent background, so it looks like part of the game. If you can build a web page, you can build a Neighborly UI.
How it fits together
| Direction | From | How |
|---|---|---|
| Lua → page | Client script | SendNUIMessage(table) – the page receives it in a message event. |
| Page → server | Client script | A NUI callback that calls TriggerServerCallback and answers the page with the result – see Client ↔ server data. |
| Page → Lua | JavaScript | fetch('https://resource_name/callbackName', …) – handled by RegisterNUICallback. |
| Mouse & keyboard | Client script | SetNuiFocus(hasFocus, hasCursor) gives your page the input. |
1. Declare the page
Set ui_page and list every file the page needs in files – only listed files are sent to players.
name = "rtx_menu"
version = "1.0.0"
author = "RTX Development"
client_scripts = ["client.lua"]
server_scripts = ["server.lua"]
ui_page = "html/index.html"
files = ["html/index.html", "html/style.css", "html/app.js"]2. Send messages to the page
SendNUIMessage takes any Lua table and delivers it to your page as JSON. Use a field like action to tell different messages apart.
SendNUIMessage({ action = 'setBalance', balance = 1250 })window.addEventListener('message', (event) => {
if (event.data.action === 'setBalance') {
document.getElementById('balance').textContent = '§' + event.data.balance;
}
});3. Give the page focus
By default your page is visible but can't be clicked, so players keep controlling the game. When a menu opens, give it focus; when it closes, give focus back. Forgetting to release focus is the most common NUI bug – players are stuck with a cursor and can't play.
| Call | Result |
|---|---|
SetNuiFocus(true, true) | Your page gets keyboard and mouse, the cursor is shown. Use for menus and forms. |
SetNuiFocus(true, false) | Keyboard only – for example a full-screen camera app controlled with keys. |
SetNuiFocus(false, false) | The game gets input back. Your page stays visible – hide it yourself. |
4. Callbacks from the page
When the player clicks something, the page POSTs JSON to https://<resource name>/<callback name>. GetParentResourceName() returns your resource name inside the page, so the code keeps working if a server owner renames the folder. In Lua, RegisterNUICallback receives the decoded data and a cb function – call it exactly once with the response.
RegisterNUICallback('setVolume', function(data, cb)
local volume = tonumber(data.volume) or 0.5
SetResourceKvp('volume', volume)
cb({ ok = true, volume = volume })
end)fetch(`https://${GetParentResourceName()}/setVolume`, {
method: 'POST',
headers: { 'Content-Type': 'application/json; charset=UTF-8' },
body: JSON.stringify({ volume: 0.8 })
})
.then((res) => res.json())
.then((data) => console.log('Saved volume', data.volume));
NUI callbacks run on the player's PC. If the click should cost money or change the world, forward it to the server with TriggerServerEvent and let the server decide – exactly like the buy callback in the full example below.
Full example: a café menu
A complete resource with an HTML menu. /cafemenu opens it, clicking an item asks the server to buy it, and the new balance comes back into the page. The buy NUI callback waits for the server's answer with a server callback before responding to the page.
local menuOpen = false
local items = {
{ id = 'latte', label = 'Latte', price = 12 },
{ id = 'espresso', label = 'Espresso', price = 8 },
{ id = 'croissant', label = 'Croissant', price = 10 }
}
local function closeMenu()
menuOpen = false
SetNuiFocus(false, false)
SendNUIMessage({ action = 'close' })
end
RegisterCommand('cafemenu', function()
if menuOpen then
return closeMenu()
end
menuOpen = true
SetNuiFocus(true, true)
SendNUIMessage({
action = 'open',
title = 'Café Menu',
balance = GetHouseholdFunds(GetPlayerHousehold(PlayerId())),
items = items
})
end, false)
RegisterNUICallback('close', function(data, cb)
closeMenu()
cb({ ok = true })
end)
RegisterNUICallback('buy', function(data, cb)
local ok, balance = TriggerServerCallback('rtx_menu:buy', data.id)
cb({ ok = ok == true, balance = balance })
end)
AddEventHandler('onResourceStop', function(name)
if name == GetCurrentResourceName() and menuOpen then
SetNuiFocus(false, false)
end
end)local prices = { latte = 12, espresso = 8, croissant = 10 }
RegisterServerCallback('rtx_menu:buy', function(source, id)
local price = prices[id]
local ok = price ~= nil and TakeMoney(source, price, 'Café: ' .. id)
if ok then
AddSimBuff(GetPlayerCharacter(source), 'caffeinated', 120)
end
return ok, GetBalance(source)
end)<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="nui://neighborly/ui/kit.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="menu" class="nb-card hidden">
<header>
<h1 id="title">Café Menu</h1>
<button id="close" class="nb-btn ghost">×</button>
</header>
<ul id="items"></ul>
<footer>
<span>Balance: <b id="balance">§0</b></span>
</footer>
</div>
<script src="app.js"></script>
</body>
</html>body {
margin: 0;
background: transparent;
font-family: "Nunito", sans-serif;
}
#menu {
position: absolute;
right: 40px;
top: 50%;
transform: translateY(-50%);
width: 360px;
padding: 22px;
}
#menu.hidden {
display: none;
}
header {
display: flex;
justify-content: space-between;
align-items: center;
}
#items {
list-style: none;
padding: 0;
margin: 14px 0;
}
#items li {
display: flex;
justify-content: space-between;
padding: 12px 14px;
border-radius: 14px;
cursor: pointer;
}
#items li:hover {
background: #eef5fc;
}const resource = GetParentResourceName();
const menu = document.getElementById('menu');
const list = document.getElementById('items');
function post(name, data) {
return fetch(`https://${resource}/${name}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json; charset=UTF-8' },
body: JSON.stringify(data || {})
}).then((r) => r.json());
}
function render(items) {
list.innerHTML = '';
for (const item of items) {
const li = document.createElement('li');
li.innerHTML = `<span>${item.label}</span><b>§${item.price}</b>`;
li.onclick = async () => {
const res = await post('buy', { id: item.id });
if (res.ok) document.getElementById('balance').textContent = '§' + res.balance;
};
list.appendChild(li);
}
}
window.addEventListener('message', (event) => {
const msg = event.data;
if (msg.action === 'open') {
document.getElementById('title').textContent = msg.title;
document.getElementById('balance').textContent = '§' + msg.balance;
render(msg.items);
menu.classList.remove('hidden');
}
if (msg.action === 'close') menu.classList.add('hidden');
});
document.getElementById('close').onclick = () => post('close');
window.addEventListener('keydown', (e) => {
if (e.key === 'Escape') post('close');
});Making it look like Neighborly
Players should feel that your UI belongs in the game. The Neighborly UI kit is a stylesheet every client already has – link it with nui://neighborly/ui/kit.css and you get the font, colors and components the launcher uses.
| Class / variable | What you get |
|---|---|
.nb-card | White card, 26px rounded corners, soft shadow |
.nb-btn, .nb-btn.go, .nb-btn.sky, .nb-btn.ghost | The chunky Neighborly buttons |
.nb-input, .nb-toggle, .nb-pill | Inputs, switches and small labels |
--sky, --mint, --sun, --coral, --lilac, --navy | The Neighborly color palette as CSS variables |
"Nunito" | The Neighborly font, already loaded |
- Keep the background transparent. Only draw what you need; the game should stay visible around your UI.
- Use rounded shapes and friendly colors. Generous padding, 14–26px corner radius, navy text on white cards.
- Respect the edges. The Sims 4 shows needs and the clock at the bottom, notifications at the top right. Leave room for them.
- Always offer a way out. Close on Esc and with a visible button, and release focus when closing.
- Load assets locally. Bundle fonts and images in your resource and list them in
files– external URLs can be slow or blocked. - Reference your own files with relative paths (
img/logo.webp) ornui://my_resource/html/img/logo.webpfrom another resource's page.

Build and debug your page in a normal browser first – open html/index.html and fake the messages from Lua with window.postMessage. In game, your page is served from nui://your_resource/... and fetch calls reach your RegisterNUICallback handlers.