# Getting started
A custom widget is a small web page that you write in HTML, CSS and JavaScript. Streamed shows it as a layer of an overlay, and the overlay is added to OBS (or any streaming software) as a browser source. The widget receives your stream's events (follows, subscriptions, cheers, raids, tips, chat) and your [variables](https://streamed.hu/docs/variables.md), and shows whatever you like.
The API is the same as that of StreamElements custom widgets, so most widgets written for StreamElements work unchanged. [What differs](https://streamed.hu/docs/streamelements.md).
## The five files
A widget is made of five parts. In the overlay editor they are the tabs of the code editor; outside of it (in a download, or in an answer of an AI) they are five files with these exact names:
| Tab | File | What it holds |
|---|---|---|
| HTML | `widget.html` | The markup inside `
`. No ``, `` or `` tags. |
| CSS | `widget.css` | The styles. |
| JS | `widget.js` | The code. It runs at the end of ``, after the HTML. |
| Fields | `fields.json` | The widget's settings: each one becomes a control in the editor. [Fields](https://streamed.hu/docs/fields.md) |
| Data | `data.json` | The values of the settings. The editor writes it when you change a setting. |
The **Import** button of the code editor takes these files (several at once): a file ending in `.html`, `.css` or `.js` goes to that tab, a `.json` file with `field` in its name to Fields, and one with `data` in its name to Data.
## The smallest widget
It shows the name of the latest follower.
`widget.html`
```html
Waiting for a follower…
```
`widget.css`
```css
#name {
font-family: sans-serif;
font-size: 48px;
color: white;
}
```
`widget.js`
```js
window.addEventListener('onEventReceived', (obj) => {
const { listener, event } = obj.detail;
if (listener !== 'follower-latest') return;
// Names are written by viewers: always insert them as text
document.getElementById('name').textContent = event.name;
});
```
`fields.json` and `data.json` can be `{}`.
## How the code runs
1. Streamed puts your HTML, CSS and JS into one page, replacing `{{fieldName}}` placeholders with the values of your settings ([Fields](https://streamed.hu/docs/fields.md)). jQuery is loaded before your code.
2. When the page has loaded, the window event `onWidgetLoad` fires with your settings, session data and recent events. [Lifecycle](https://streamed.hu/docs/lifecycle.md)
3. From then on, `onEventReceived` fires for every event, and `onSessionUpdate` whenever the session data changes. [Events](https://streamed.hu/docs/events.md), [Session data](https://streamed.hu/docs/session-data.md)
4. `SE_API` lets you store values, read variables and more. [API reference](https://streamed.hu/docs/api-reference.md)
The widget runs in an isolated sandbox: it cannot reach your Streamed account, and a few browser features (such as `localStorage`) are not available. [Limits and security](https://streamed.hu/docs/limits-and-security.md)
## Making one
1. Dashboard → **Overlays** → open an overlay (or create one).
2. **Add layer** → **Custom Widget**. A new one starts with an example: an alert card for follows, subscriptions, cheers and raids.
3. Click **Code editor** in the layer's settings. Every change shows in the preview within a moment; **Ctrl+S** (or **Save**) saves it.
4. Size and place the layer on the canvas. The widget's page is exactly as large as the layer.
## Testing
- **▶ in the editor's top bar** sends a test event of the chosen kind (with a random name and message) to all of your layers. The Events section of the dashboard does the same with your own name, amount and message. Test events count like real ones (also in tip variables) until you delete them from the event history.
- A **button field** in your settings fires `widget-button` in the widget, so you can add your own test buttons. [Fields](https://streamed.hu/docs/fields.md#button)
- In the preview, `onWidgetLoad`'s `overlay.isEditorMode` is `true`, so you can show sample content there.
- The browser's developer tools (F12 in the editor) show your `console.log` output. The widget runs in a frame of the preview: pick it in the console's context menu.
Which events reach a widget is set per overlay: the **Accounts** button of the overlay editor chooses the accounts and events. While a layer is hidden, its events are dropped.