OBS overlays in plain HTML, CSS and JS, and what actually fails

One file, no build step, and a documented account of which parts of the usual advice survive testing. The first version of this article was wrong about the central mechanism. That is section 3.

Published 3 December 2026, corrected the same day. Tested on OBS Studio 33.0.0 and Chromium on Linux. Bold figures are measurements from this machine, not estimates.

Contents
  1. 1The short version
  2. 2What a Browser Source is
  3. 3What I got wrong
  4. 4The constraints that are real
  5. 5Can a chat widget work as a local file
  6. 6The widgets
  7. 7Local file overlays worth looking at
  8. 8What this costs against renting
  9. 9Prompts that produce this
  10. 10The checklist
  11. 11References

1. The short version

An OBS Browser Source renders a web page and composites it over your scene. The page can be a URL or a file on your disk. A useful overlay is a few hundred lines of HTML, CSS and JavaScript, and it needs no framework, no package manager and no monthly fee. Everything in this article was run before being written down.

A DayZ stream frame with the finished overlay: follower alert top left, session clock top right, chat bottom left
Three widgets over real gameplay: follower alert top left, session clock top right, chat bottom left.

2. What a Browser Source is

It is an embedded Chromium view with a fixed size, composited into the scene. Two consequences follow. Transparency is free, because the page's own background is what shows. And the Chromium inside OBS is not your Chromium: it is whatever the release pinned, so a feature you tested in a current browser may not exist in the source. Test in OBS before shipping, not after[1].

The settings that matter for a 1920x1080 overlay:

SettingDefaultWhy it matters
Width / Height800 / 600This is the viewport the page is laid out in, not a scale. Set it to 1920x1080 or your CSS is designing for the wrong canvas.
Use custom frame rateOffOn, a separate FPS value drives redraw. Off inherits the canvas rate, which is what you want unless you are deliberately decoupling.
FPS30Only used when the above is on. An overlay does not need 60.
Shutdown source when not visibleOffOn, the page unloads when hidden or not in the active scene. Your chat state goes with it.
Refresh browser when scene becomes activeOffOn, the page refreshes on every scene switch. It empties the chat and can flash.
Local fileOffLoads the page from disk instead of a URL. What this does and does not restrict is section 3.

overflow: hidden on both html and body is the single most important line in an overlay. Without it one long chat message produces a scrollbar, and a scrollbar is visible on stream.

3. What I got wrong

The first version of this article claimed that a Local file source cannot load libraries from the internet, and explained it as a security restriction of the file:// origin. That claim is false, and I only found out because someone asked how a chat widget could possibly work under it. I tested the four mechanisms instead of trusting the paragraph[8]:

From a page loaded as file://Result
A JavaScript file sitting next to the HTMLloads
A classic <script src="https://cdn...">loads
A dynamic import() of an ES module from a CDNloads
fetch() to a remote HTTPS endpointsucceeds
Web fonts from Google Fontsload
fetch() to http://127.0.0.1 with no CORS headerblocked
fetch() to http://127.0.0.1 with Access-Control-Allow-Originsucceeds

So a local file page can reach the network. What it cannot do is bypass CORS, which is a rule about reading responses from another origin, not about file access. The observable failure is real, and it is in the last two rows: the direction nobody tests first.

The same overlay rendered over a transparency checkerboard, showing the transparent background
The same page on transparency. The checkerboard is the page behind it, not part of the overlay.

If you hit a library that would not load in OBS in 2025, the cause was most likely one of: the CDN did not send permissive CORS headers for the request the page made, the OBS release pinned a Chromium that lacked the syntax used, or the source had been cached from an earlier attempt. Each of those is worth checking before concluding that local files cannot use libraries.

4. The constraints that are real

5. Can a chat widget work as a local file

Yes, with one extra piece. The demo on this page fakes its own chat, because a static file cannot receive messages. Real chat arrives over a network connection, and there are two shapes that work:

ShapeHowTrade
Hosted pageThe overlay is served over HTTPS and connects to the chat service directlyNeeds a server and a stable URL, but everything is one file and there is no local process
Local page plus local relayA small program on the same machine holds the chat connection and serves it on 127.0.0.1Nothing leaves the machine and it works offline, but the relay must send Access-Control-Allow-Origin or the browser blocks the read

The relay is the piece people miss, and it is about twenty lines. The browser will not let a file:// page read a response from 127.0.0.1 unless that response opts in:

# the minimum that makes a local file able to read a local endpoint
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Content-Type", "application/json")

Then the overlay polls or opens a connection to it like any other endpoint. The wildcard is acceptable here because the endpoint is bound to loopback and holds nothing but chat you were already broadcasting.

6. The widgets

Chat is a list that must be capped. The naive version appends forever, which is fine for ten minutes and awful for six hours.

function addMessage(who, what) {
  const row = document.createElement("div");
  row.className = "msg";
  const n = document.createElement("span");
  n.className = "who";
  n.textContent = who + ":";
  const t = document.createElement("span");
  t.className = "what";
  t.textContent = what;
  row.append(n, t);
  chat.append(row);
  // an overlay left running for six hours must not grow without bound
  while (chat.children.length > 7) chat.firstElementChild.remove();
}

Two details carry more weight than they look. Use textContent, never innerHTML, for chat: it is attacker controlled input, and one message can otherwise inject markup over your scene. And animate only transform and opacity, which the compositor handles without layout work.

.msg { animation: slideIn .32s cubic-bezier(.2, .9, .2, 1) both; transform-origin: left center; }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-24px) scale(.97); }
  to   { opacity: 1; transform: none; }
}

The follower alert is a three state machine, best driven by a class toggle so the timing lives in the stylesheet. The session clock should compute from a stored start timestamp rather than counting ticks, because background throttling makes a tick counter drift.

const started = Date.now();
setInterval(() => {
  const s = Math.floor((Date.now() - started) / 1000);
  elapsed.textContent = `${Math.floor(s / 3600)}:${two(Math.floor(s / 60) % 60)}:${two(s % 60)}`;
}, 1000);

This is the actual file, running, not a video of it. It fakes its chat so the motion is visible.

Four bars and backgrounds from this channel's own archive, all plain HTML, CSS and JavaScript with no build step. They were written for portfolio pages rather than OBS, which is why one of them pulls a web font from Google and would fall back to Segoe UI if that request failed.

For models and assets, these are the sources worth knowing before writing geometry by hand:

SourceWhat it givesLicence
three.js3D rendering in the browser, one fileMIT[2]
matter.js2D rigid body physicsMIT[3]
KenneyGame art, audio, UI packsCheck the licence page for the specific pack before shipping
QuaterniusAnimated and static low poly modelsCheck the licence page for the specific pack before shipping

8. What this costs against renting

Costs below are structural, not quoted prices. Hosting tiers and overlay subscriptions change, so check the current price of any row you intend to rely on.

ApproachMoneyWhat you ownFails when
Local file, vendored0The file, the assets, the behaviourYou move the folder and forget a vendored file
Hosted on a static hostFree tier, then per bandwidthThe fileThe host, your account, or the network
Self hosted on a VPSMonthly, plus your timeThe file and the machineYou are now on call for a server
Paid overlay serviceMonthly subscriptionNothing you can editThe service changes or ends, and your overlay goes with it

The paid services are not a scam. They are selling convenience and someone else maintaining the connection. The reason to write your own is that an overlay is small enough to understand, and the subscription never stops.

9. Prompts that produce this

The constraint has to be in the prompt. These are the shapes that worked, including the ones that are frankly funny, because the funny ones are the ones people actually need:

hey chadgbd make me a pink rounded corner pulsating and gyrating and ribbed webcam
overlay for my twitch obs ya feel me it is local file no uploads mane
good sir gpt, i need to acquire an all in one html+css+js file that when opened as a local
file in the program known as obs creates a dopalistic hooking attention catching background
that has fireworks, randomization and gambling theory baked into it
Write vanilla HTML, CSS and JavaScript for an OBS Browser Source, 1920x1080, transparent
background. Rules:
1. One file, no build step, no package manager. It must run by opening it.
2. If it needs a library, name the file to download and load it by relative path beside the
   HTML. Do not link a CDN.
3. Use textContent, never innerHTML, for anything user supplied.
4. Animate only transform and opacity.
5. Cap the number of chat rows kept in the DOM.
6. Assume an older Chromium: avoid the newest CSS and JS.

Ask for the verification too. "Give me the two commands that prove it makes no network requests at runtime" is a better request than "make it self contained", because the second one is a claim about the code and the first one is a test you can run.

10. The checklist

  1. Transparent html and body, overflow: hidden on both.
  2. textContent for chat and names, never innerHTML.
  3. Animate transform and opacity only.
  4. Capped DOM: a fixed maximum number of chat rows.
  5. Alert state driven by a class toggle, not stacked timers.
  6. Know which of the two worlds you are in: local file, or hosted. The CORS rules differ, and so does who is on call when it breaks.
  7. Tested in OBS at 1920x1080, through a scene switch, with a hostile message.

If you want to see the output rather than the code, the videos are here and the streams are on Twitch.

11. References

  1. OBS Studio, Browser Source. Also the source for the settings and defaults in section 2 ("Shutdown source when not visible ... Off", "Width ... 800", "Height ... 600", "FPS ... 30"). obsproject.com https://obsproject.com/kb/browser-source
  2. three.js licence, MIT, copyright 2010-2026 three.js authors. github.com three.js LICENSE
  3. matter.js licence, MIT, "Copyright (c) Liam Brummitt and contributors". github.com matter-js LICENSE
  4. OBS Studio 33.0.0 release notes: "Updated CEF from 127/6533 to 150/7871", described as an update "from the July 2024 release to September 2026". This is the lag in section 4. github.com obs-studio 33.0.0
  5. MDN, Same-origin policy: "Modern browsers usually treat the origin of files loaded using the file:/// scheme as opaque origins ... they are not assumed to be coming from the same origin, and may trigger CORS errors." developer.mozilla.org Same-origin policy
  6. MDN, CORS: "For security reasons, browsers restrict cross-origin HTTP requests initiated from scripts. For example, fetch() and XMLHttpRequest follow the same-origin policy." developer.mozilla.org Cross-Origin Resource Sharing
  7. Chromium switches: "By default, file:// URIs cannot read other file:// URIs. This is an override for developers who need the old behavior for testing." chromium.googlesource.com content_switches.cc
  8. The browser behaviour in section 3 was measured on this machine: a page loaded from file:// requesting a sibling script, a CDN classic script, a CDN ES module, a remote fetch, web fonts, and two loopback requests with and without Access-Control-Allow-Origin. Reproduce it before trusting it; browser behaviour changes.