HTML, CSS and JS Playground

Type HTML and CSS and the preview changes as you type. Press Run to run the JavaScript. console.log output shows below the preview.

How it works

The three boxes are joined into one small web page, and that page is loaded into a frame beside the editor. The HTML goes in the body, the CSS goes in a style tag, and the JavaScript goes in a script tag at the end of the body, so the elements exist when the script runs.

The frame is sandboxed. Your code runs in a separate, anonymous origin, so it cannot read this site’s cookies or storage, and it cannot change the page around it. The frame also has a Content Security Policy that blocks fetch, XMLHttpRequest, WebSocket and any image, script, style or font loaded from a URL. Only the code you typed, and images written as data: URLs, can run.

HTML and CSS edits re-render the preview at once. The script only runs again when you press Run, because a half-typed loop such as for (;;) { would otherwise start while you type. Between runs the preview keeps the last script you ran.

How to use it

  1. 1 Type or paste markup into the HTML box. The preview updates as you type.
  2. 2 Add styles in the CSS box. You do not need a style tag; the box is the style tag.
  3. 3 Write JavaScript in the last box and press Run, or Ctrl+Enter (Cmd+Enter on a Mac).
  4. 4 Read console.log output, warnings and errors in the Console under the preview. Errors name the line of your script they came from.

Good to know

  • The script runs after the HTML is parsed, so document.querySelector finds your elements without a DOMContentLoaded listener.
  • Links cannot open a new page and redirects are stopped. If your code tries to leave the preview, the preview says so and stops.
  • An endless loop can freeze this tab, because the sandbox may share the page’s thread. If that happens, close the tab and open the tool again.
  • Nothing is saved. Copy your code somewhere before you reload or close the page.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Building a dark mode switch in three boxes

A playground is the quickest way to see how HTML, CSS and JavaScript split the work of a page. Here is one small feature built from nothing: a button that switches a card between light and dark. Each box does one job, and the order you write them in shows why.

Start with the HTML box. Type <div class="card"><h2>Notes</h2><p>Three things to buy.</p><button id="mode">Dark mode</button></div>. The preview shows plain black text and a grey button. That is the content and its structure, with no look and no behaviour yet. A screen reader or a search engine already gets everything it needs from this.

Now the CSS box. Type .card { padding: 16px; border-radius: 8px; background: white; color: black; } and then .card.dark { background: #222; color: #eee; }. The card gets padding and rounded corners at once, because CSS re-renders as you type. The second rule does nothing yet, because no element has the class dark. That is the idea to hold on to: the CSS describes both looks in advance, and the script only has to choose between them.

Last, the JavaScript box. Type const card = document.querySelector('.card'); and then document.getElementById('mode').addEventListener('click', () => { const on = card.classList.toggle('dark'); console.log('dark is', on); });. Press Run. Click the button in the preview and the card turns dark; click again and it turns back. The Console shows "dark is true" and then "dark is false", because classList.toggle returns whether the class is now present. Notice the script never sets a colour. It flips one class, and the CSS does the rest. Keeping the look in CSS like this means a designer can change both colours without touching the script.

A mistake teaches as much. Change getElementById('mode') to getElementById('moed') and press Run. The Console shows an Uncaught TypeError, because getElementById found nothing and returned null, and null has no addEventListener. The message names the line of your script it came from, which is the line to fix.

This playground has limits. It does not load anything from the network, so a framework from a CDN, a web font or an image by URL will not work; the Console says so when something is blocked. There is no npm and no build step, so TypeScript, JSX and import statements for packages do not work. The editor is a plain text box with no autocomplete or syntax colours. An endless loop can freeze the tab. Nothing is saved, so keep a copy of anything you want to keep.

Frequently asked questions

Can my code load a library from a CDN?

No. The sandbox blocks every script, stylesheet and font loaded from a URL, and blocks fetch too. The Console shows a "Blocked by the sandbox" line each time. Paste the library’s code into the JavaScript box instead, or use plain DOM APIs.

Is it safe to paste code I found online?

Safer than pasting it into a page you are logged in to. The code runs in an anonymous origin, so it cannot read this site’s data or your cookies for other sites, and the usual ways of sending data out (fetch, images, forms, WebSocket) are blocked. It can still use your processor, and an endless loop can freeze the tab.

Why does the preview not re-run my script as I type?

Code that is half typed is often broken or dangerous. Typing for (let i = 0; i < 10; ) is an endless loop for a moment before you add i++. So the script only runs when you press Run. HTML and CSS are safe to re-render, so they update straight away.

Is my code uploaded or saved anywhere?

No. The page is built in your browser and shown in a frame on this page. Nothing is sent to a server, and nothing is kept after you leave.

Why can I not use localStorage in the playground?

The sandbox gives your code an anonymous origin, and browsers do not give storage to an anonymous origin. Reading localStorage throws a SecurityError. Keep state in ordinary variables instead.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.