# Code a Kick widget: quick start

> Write custom Kick widgets in HTML, CSS, and JavaScript in the KickBot code editor: the four files, a working follow counter, testing, versions, and OBS setup.

Source: https://kickbot.com/docs/widgets/code-editor

You can write custom Kick overlays directly in HTML, CSS, and JavaScript using the KickBot widget code editor. KickBot runs your widget inside a sandboxed page, connects to your Kick channel, and exposes the global `kb` object for live Kick events, settings, saved data, dashboard controls, chat, and TTS.

You need a [KickBot account](https://kickbot.com/docs/getting-started/create-your-account) with your Kick channel connected, and a computer (the widget editor requires a desktop screen). Custom widgets are free with no limit on how many you can make. Team moderators need the **Widget builder** permission in [Manage team](https://kickbot.com/docs/account/team).

## Start from code

1. Open **Widgets** > **Create** ([kickbot.com/dashboard/widget-create](https://kickbot.com/dashboard/widget-create)) and click **Start from code** ([kickbot.com/dashboard/widget-create/code](https://kickbot.com/dashboard/widget-create/code)).
2. Pick one of three starting points:
   - **Starter widget:** A small working example that shows live Kick chat messages.
   - **A library widget:** Search the library and copy any widget as an editable remix.
   - **Files from your computer:** Choose a `.zip` file (up to 20 MB) or a folder that contains an `index.html`. KickBot imports `index.html`, CSS, JavaScript, and `widget.json` (inlining local stylesheet and script references into `style.css` and `script.js`). Images and sounds are not imported; upload them in the editor instead.
3. Under **Details**, enter a **Name** (up to 80 characters; you can leave it empty) and set the **Width** and **Height** in pixels (`800 × 600` by default; a library widget keeps its own size).
4. Click **Create widget**.

The editor opens in **Code** view. Use the panel toggles in the top right to show or hide **AI**, **Files**, **Preview**, and **Console**, or switch between **Preview**, **Code**, and **Settings** in the top bar.

## The four files

Every KickBot widget is made of four files:

| File | Purpose | Size limit |
| --- | --- | --- |
| `index.html` | HTML markup only. Do not include `<html>`, `<head>`, `<body>`, `<link href="style.css">`, or `<script src="script.js">`; KickBot injects the SDK, CSS, and JavaScript automatically. | 500 KB |
| `style.css` | CSS styles. Keep `html` and `body` transparent so the stream shows behind your widget. | 500 KB |
| `script.js` | Plain browser JavaScript. Runs after the HTML is in the page, and `kb` is ready right away. | 500 KB |
| `widget.json` | Widget size (`width`, `height`), `settings` (up to 60), `saved_data` labels (up to 30), and `controls` buttons (up to 8). | 100,000 characters |

You can edit `widget.json` directly in **Code** or build settings visually in the **Settings** tab. The visual editor supports **Text**, **Number**, **Switch**, **Color**, **Font**, **Choice**, **Image**, **Sound**, and **Video** fields, along with drag-to-reorder, sections, and **Show only when** rules. The **Files** sidebar also lists uploaded image, sound, and video defaults under `assets` and shows your total file and saved-data sizes. If you paste a full HTML page, mismatched CSS or JavaScript, or stray wrapper tags into a file, the editor offers a one-click fix with **Undo**.

For every `kb` method, event payload, and `widget.json` field, see [KickBot widget SDK reference](https://kickbot.com/docs/widgets/sdk).

![The KickBot widget editor in Code view with the Files list (widget.json, index.html, style.css, script.js), script.js open in the code editor, the live preview with test buttons on the right and the Console below the code](https://kickbot.com/docs/images/widgets/code-editor/01-code-view.webp "Edit a file and the preview reloads. Errors show in the Console.")

## Build your first widget: session follow counter

Create a new widget with **Starter widget**, then replace the four files below to build a working follow counter with one color setting, one saved count that survives OBS restarts, and one reset button.

### 1. Define size, settings, saved data, and controls in `widget.json`

```json
{
	"width": 360,
	"height": 120,
	"settings": [
		{
			"key": "accent",
			"type": "color",
			"label": "Accent color",
			"default": "#53FC18"
		}
	],
	"saved_data": [
		{
			"key": "follows",
			"type": "number",
			"label": "Follows this session",
			"default": 0
		}
	],
	"controls": [
		{
			"id": "reset",
			"label": "Reset count",
			"confirm": true
		}
	]
}
```

### 2. Add the markup in `index.html`

```html
<div class="card">
	<span class="label">Session follows</span>
	<span id="count" class="count">0</span>
</div>
```

### 3. Style the card in `style.css`

```css
html,
body {
	margin: 0;
	width: 100%;
	height: 100%;
	background: transparent;
}

.card {
	box-sizing: border-box;
	width: 100%;
	height: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 24px;
	border-radius: 14px;
	background: rgba(14, 15, 18, 0.88);
	border-left: 5px solid var(--accent, #53fc18);
	color: #ffffff;
	font-family: Inter, system-ui, sans-serif;
}

.label {
	font-size: 16px;
	font-weight: 600;
	opacity: 0.85;
}

.count {
	font-size: 42px;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
	color: var(--accent, #53fc18);
}
```

### 4. Wire up events, saved data, controls, and settings in `script.js`

```js
const countEl = document.getElementById('count');
let follows = 0;

function applySettings(settings) {
	document.documentElement.style.setProperty('--accent', settings.accent || '#53FC18');
}

function render() {
	countEl.textContent = String(follows);
}

applySettings(kb.settings);

kb.store
	.get('follows')
	.then((saved) => {
		follows = typeof saved === 'number' ? saved : 0;
		render();
	})
	.catch((err) => console.error('Failed to load follows:', err));

kb.on('follow', (e) => {
	follows += 1;
	render();
	console.log('Follow from', e.user.username);
	kb.store.set('follows', follows).catch((err) => console.error('Failed to save follows:', err));
});

kb.on('control', ({ id }) => {
	if (id !== 'reset') return;
	follows = 0;
	render();
	kb.store.set('follows', follows).catch((err) => console.error('Failed to reset follows:', err));
});

kb.on('settings', (next) => {
	applySettings(next);
});
```

### 5. Test it

1. Click **Follow** in the test bar to watch the counter increment and see the viewer's name logged in **Console**.
2. Open the **Saved data** tab at the bottom to verify `follows` updated.
3. Switch to **Preview** at the top of the editor and click **Reset count** under **Actions** in the test bar to test your control button. In the editor it runs at once, without the confirm popup. On the widget's settings page, **Actions** asks first.
4. Click **Clear test events** when finished testing.

## Console, Events, and Saved data tabs

The bottom strip in the editor has three tabs:

- **Console:** Shows `console.log`, `console.info`, `console.warn`, and `console.error` output plus runtime errors with file and line numbers. Simulated chat and TTS output from test events appears here too. Click **Fix with AI** next to an error to send it to **KickBot AI** chat (this uses one of your monthly KickBot AI messages). The console clears each time your code reloads.
- **Events:** Lists test events sent during this editing session with timestamps and whether each event came **from you** or from a connected AI app.
- **Saved data:** Shows live key-value pairs stored with `kb.store` in the editor preview. The preview starts from your channel's saved data; changes written inside the preview stay in the preview. On your installed widget's settings page in [My widgets](https://kickbot.com/dashboard/saved-widgets), streamers can inspect, edit, or reset values defined under `saved_data` (up to 3 MB per installed widget, 512 KB per value).

## Test events

Use the test buttons below or next to the preview to trigger sample events: **Follow**, **Sub**, **Gifted subs**, **KICKs**, **Tip**, **Raid**, **Chat message**, **TTS**, and **AI image**. When your code listens for **Pinned message**, **Unpin**, **Stream start**, **Stream end**, or chat commands (`!command`), those buttons appear too. Events your code does not listen for appear dimmed. Your `controls` buttons show under **Actions** in **Preview** view; test them there.

> **Note:** Test events show in both the editor preview and OBS, even while live. Chat messages (`kb.chat.send`) and TTS (`kb.tts.say`) triggered by test events are not sent for real; they appear in **Console** instead.

> **Caution:** Clicking **Clear test events** restores saved data to how it was before your first test and removes any real events that arrived since then. Do not click **Clear test events** during a live stream.

## Sizes and preview modes

Set `width` (50 to 3840 px) and `height` (50 to 2160 px) in `widget.json`, or click the size in the **Preview** toolbar to edit it directly. Use these preview modes to check layout and readability:

- **Close-up:** Inspect the widget at **Fit** or real size (`100%`) on **Studio**, **Game**, **Moving**, **Bright**, or **None** backgrounds.
- **On stream:** See your widget at real scale on a 1920 × 1080 stream canvas and drag it to test placement (position in the preview does not change OBS).

Click **Reload preview** (the round arrow next to the preview) to load the widget again from the start.

## How settings reach your code

- **Initial values:** `kb.settings.<key>` is ready as soon as `script.js` starts, filled with the streamer's values or your `default` values from `widget.json`.
- **Live updates:** Listen to `kb.on('settings', (next) => ...)` to apply setting changes without reloading the widget. If a widget does not register a `settings` listener, KickBot restarts the widget with the new settings.
- **Fonts:** For any setting with `"type": "font"`, KickBot loads the selected Google Font stylesheet automatically. Set `font-family` in CSS or JavaScript with a fallback font.
- **Conditional settings (`show_if`):** Hiding a setting with `show_if` only hides it in the dashboard. Its value stays in `kb.settings`, so check the controlling setting in your code.

## Saving and Versions

Your changes save automatically in the editor. The status indicator shows **Not saved yet**, **Saving**, or **All changes saved**. If `widget.json` has an error, nothing is saved: the top bar shows **Some changes were not saved** and the error appears under `widget.json` until you fix it.

Each save updates your own installed copy and reloads it in OBS automatically. Other channels using a published version of your widget do not receive edits until you publish a new version.

Click **Versions** in the top bar to browse earlier saved snapshots and click **Restore** to roll back. KickBot saves your current files as **Before a restore** before replacing them.

## Add to OBS

Click **Add to OBS** in the top right of the editor to reveal and copy your private widget URL along with the exact width and height for your OBS browser source. Click **Put it in a scene** to add the widget to a KickBot scene instead; see [Combine widgets in KickBot scenes](https://kickbot.com/docs/widgets/scenes) and [Add a KickBot overlay to OBS](https://kickbot.com/docs/getting-started/add-browser-source-obs).

A widget only counts live events and chat commands while it is open in OBS (or another streaming app such as Streamlabs Desktop, Meld Studio, XSplit, vMix, PRISM Live Studio, or Lightstream).

## Next steps

- [KickBot widget SDK reference](https://kickbot.com/docs/widgets/sdk): every `kb` event payload, channel property, saved data method, chat and TTS helper, and `widget.json` field.
- [Publish and share a widget](https://kickbot.com/docs/widgets/publish-and-share): run the automatic library check, add preview pictures, and share via the library or a direct link.
- [Build a Kick widget with KickBot AI](https://kickbot.com/docs/widgets/build-with-kickbot-ai): ask the built-in AI chat to generate or update code inside the editor.
- [Build a Kick widget with your own AI](https://kickbot.com/docs/widgets/build-with-your-ai): connect Claude, ChatGPT, Cursor, or Codex over MCP to edit and test your files directly.
