This HTML, CSS and JS playground is an online code editor with a live preview: write markup, styles and JavaScript in three editors and the page beside them updates as you type. A console underneath shows what your code logs and the errors it throws, with the line number in your JavaScript, so you can debug without opening the browser’s developer tools. It is meant for the moments when setting up a project is overkill: trying a CSS layout, reproducing a bug for a colleague, testing a snippet from a tutorial, or teaching someone their first web page.
Your code is autosaved in your browser, so a closed tab does not lose it. Share link compresses the three editors into the link itself; nothing is stored on a server, and anyone who opens the link gets an exact copy. Download gives you one .html file with the CSS and JavaScript inlined, which opens in any browser. The preview runs in a sandboxed frame, which is why shared links are safe to open but also why a few things, such as localStorage, do not work inside it; the details are below.
How to use
- Type or paste into the HTML, CSS and JavaScript editors. HTML is the body of the page; you can also paste a whole document with its own <head>.
- Watch the preview update. Turn off Auto-run if you are writing a loop and want to run only when ready, then press Run or Ctrl+Enter (⌘+Enter on Mac).
- Read console.log output, warnings and errors in the Console panel under the preview; errors show the JavaScript line they come from.
- Switch the layout between editors on top and editors on the left; on a phone the editors become tabs.
- Press Share link to copy a link containing your code, or Download .html to save one self-contained file.
Frequently asked questions
Is it safe to open a playground link someone sent me?
Safer than opening an unknown website, and it never runs on its own. A shared link shows the code first; it runs only when you press Run. When it does run, it is inside an iframe sandboxed without allow-same-origin, so the browser treats it as a separate, anonymous origin: it cannot read this site’s localStorage (where your own draft is kept), its cookies or the page around it. It can still do what any web page can do in a frame, such as show content or send requests to other sites, so treat code from strangers the way you would treat a link from them.
Why does localStorage or sessionStorage throw an error in the preview?
Because of the sandbox. The preview frame has an opaque origin, and browsers refuse storage, cookies and IndexedDB to opaque origins with a SecurityError. This is the price of being able to open shared code safely. To test code that relies on storage, download the .html file and open it from a local web server, or wrap the storage calls in try/catch so the rest of your code runs.
How do share links work, and is there a size limit?
The three editors are packed into JSON, compressed with the browser’s built-in deflate (CompressionStream) and written into the part of the link after #. That part is never sent to a server, so the code exists only in the link. Measured on real code, a link is about 85% of the code’s length for a 1 KB snippet, 60% for 8 KB and 35% for 40 KB, because compression gains more the more code there is. Browsers accept very long links, but chat apps, email clients and some URL shorteners cut them off; the tool warns you above 8,000 characters, and for bigger projects the .html download is the better way to share.
Can I use npm packages, React or ES modules?
Not through npm, because there is no build step. You can load any library that is published as a browser script or ES module from a CDN: put <script src="…"></script> in the HTML editor, or write a <script type="module"> block there and import from a URL such as esm.sh or jsDelivr. The JavaScript editor runs as a classic script, so an import statement there is a syntax error; put module code in the HTML editor instead. JSX and TypeScript are not compiled.
My code froze the page. What happened?
Almost always an infinite loop, such as a while loop whose condition never becomes false. JavaScript runs on one thread, so a loop that never ends stops the preview from responding, and in browsers that run sandboxed frames in the same process as the page, the whole tab with it. Close and reopen the tab: the playground autosaves, so your code is still there. Turn off Auto-run before writing loops so half-typed code is not run on every keystroke.
Does this playground upload or store my code?
No. The editors, preview and console all run in your browser, the autosave is in your browser’s local storage, and a share link carries the code inside the link. Nothing you type is sent to this site. The preview itself may load whatever your code asks for, such as fonts, images or a CDN script.
What the sandbox allows and blocks
The preview is an <iframe> whose content is set with srcdoc and whose sandbox attribute is "allow-scripts allow-modals allow-forms". Each flag is a deliberate choice:
• allow-scripts: your JavaScript runs.
• allow-modals: alert(), confirm() and prompt() work, because beginners use them constantly.
• allow-forms: a <form> can submit, so you can test form validation.
• No allow-same-origin: the frame gets a unique opaque origin. It cannot read this site’s storage or cookies, and the page cannot read into it either; the console works by the frame posting messages out, which the page accepts only from the current preview.
• No allow-popups and no allow-top-navigation: shared code cannot open windows or navigate you away from the page.
Each Run replaces the frame with a new one, so timers, event listeners and global variables from the previous run never leak into the next.
How the HTML, CSS and JavaScript are combined
If the HTML editor holds a fragment (no <html>, <head> or doctype), the playground wraps it in a standard HTML5 document with a UTF-8 charset and a mobile viewport tag, puts your CSS in a <style> element in the head, and your JavaScript in a <script> at the end of the body. Running the script last means the elements it looks up with querySelector already exist, which is why the starter code needs no DOMContentLoaded listener.
If you paste a complete document, your structure is kept: the CSS goes at the start of your <head> and the JavaScript just before </body>. The downloaded .html file is built the same way, minus the console bridge, so it behaves exactly like the preview.
A literal "</script>" inside your JavaScript, for example in a string, would end the script element early. The playground writes it as "<\/script>", which means the same thing to JavaScript, so such code works unchanged.
Playground vs CodePen, JSFiddle and a local editor
CodePen, JSFiddle and similar sites add accounts, saved collections, preprocessors (Sass, TypeScript, Babel), npm-style package search and a community feed. If you need any of those, use them. This playground is deliberately smaller: it opens instantly, needs no account, keeps your work in your own browser, and its share links do not depend on anyone’s server staying up.
For anything bigger than a page, a local editor such as VS Code with a dev server (Vite, or the Live Server extension) is the right tool: multiple files, real modules, a debugger, and version control. Download .html is the bridge between the two: it gives you a working file to drop into a project.
