Code Playground
Write HTML, CSS, and JavaScript with live preview. Like a mini CodePen — entirely in your browser.
Related Tools
How to Use
- Write Your Code — Switch between the HTML, CSS, and JS tabs to write your code. Each tab has a dedicated editor with tab-key indentation (press Esc, then Tab, to move focus out) and monospace font. The preview updates automatically as you type (500ms debounce).
- See Live Preview — The preview panel shows your rendered output in a sandboxed iframe. HTML structure, CSS styling, and JavaScript interactions all work together in real-time. Open the Console to see console.log output and any errors.
- Export Your Work — Click Download to save your project as a single HTML file with embedded CSS and JS. Click Copy to copy all three sections to your clipboard. The exported file works standalone in any browser.
About the Code Playground
The Code Playground is a small HTML, CSS and JavaScript editor with a live preview and a console, in the spirit of CodePen or JSFiddle but without accounts or saved projects. It is for trying a layout idea, testing a snippet from a tutorial, reproducing a bug in isolation, or teaching the basics of the web. Your code runs only in your own browser.
How the preview is built
Every run combines the three tabs into one HTML document. Your CSS goes into a <style> in the head, after a small default style for the body (system font, 16px margin, dark gray text). Your HTML goes into <body>, and your JavaScript into a <script> at the end of the body, so every element already exists when your script runs. The document is loaded into the preview with srcdoc, so no server is involved. With Auto-run on, the preview rebuilds 500 ms after you stop typing. Switch it off to run only when you press Run.
The preview iframe has sandbox="allow-scripts allow-modals". In practice:
- Scripts, timers, events, DOM changes, canvas and
alert()/confirm()/prompt()work. - Without
allow-same-origin, the preview runs in an isolated origin. It cannot read this page, its cookies or its storage, and its ownlocalStorage,sessionStorageand IndexedDB are unavailable (accessing them throws a security error). - Forms cannot submit, and popups and new tabs are blocked. The preview also cannot navigate the page around it.
- The site's security policy applies inside the preview.
fetch()calls to other websites, scripts and stylesheets from CDNs and external web fonts do not load, while images from https addresses anddata:URLs do.
Worked example
| Tab | Code |
|---|---|
| HTML | <h1 id="t">Hi</h1> |
| CSS | h1 { color: teal; } |
| JS, line 1 | const t = document.getElementById("t"); |
| JS, line 2 | t.textContent += "!"; |
| JS, line 3 | console.log(t.textContent); |
| JS, line 4 | sayHi(); |
The preview shows a teal heading reading "Hi!". The Console shows > Hi!, then the browser's error for the undefined function (for example sayHi is not defined) followed by (JS line 4), and it opens automatically because an error occurred. The console hook runs in its own script before yours, so it catches syntax errors as well as runtime errors, and it reports line numbers relative to your JS or HTML tab rather than the combined document.
Limitations
- Nothing is saved. Reloading or closing the tab loses your code, so use Download or Copy first. There are no share links.
- The editors are plain text areas, with no syntax highlighting or autocomplete. Tab inserts two spaces; press Esc, then Tab, to move focus out.
- No preprocessors or packages: Sass, TypeScript, JSX and npm imports are not compiled. Paste library code into the JS tab if you need it.
- The Console captures
console.log,info,warnanderror, plus uncaught errors and rejected promises. Other console methods such asconsole.tableappear only in your browser's developer tools. Objects are shown as indented JSON, and each message is cut off at 10,000 characters. - An endless loop can freeze the preview and possibly the whole tab. Turn off Auto-run while you write loops.
Practical tips
- Download saves
playground.html, the same document as the preview without the console hook. Opened from your computer, it runs without the preview's restrictions, so CDN libraries load and network requests are no longer blocked by the preview's rules. - Copy puts all three tabs on the clipboard as one block, labeled
<!-- HTML -->,/* CSS */and// JavaScript, which is handy for bug reports and forum questions. - To check a full HTML page or an email template, HTML Preview is simpler. To tidy a stylesheet, use the CSS Formatter & Minifier. To check data your script uses, try the JSON Formatter & Validator.
Your HTML, CSS and JavaScript are never uploaded: the preview is generated and run inside your browser.
Frequently Asked Questions
How does the live preview work?
When you type in any editor tab, the playground combines your HTML, CSS, and JavaScript into a complete HTML document and renders it in a sandboxed iframe using the srcdoc attribute. The preview updates automatically after 500ms of inactivity. You can also click the Run button for immediate execution. The iframe is isolated from the parent page for security.
Does JavaScript work in the preview?
Yes. JavaScript runs in the preview iframe: DOM manipulation, event listeners, timers, alert dialogs and most browser APIs work normally. For privacy and security, the preview cannot reach other websites: fetch() and other network requests to external servers are blocked, and external script or stylesheet files (for example libraries loaded from a CDN) do not load, so paste library code directly into the JS or CSS tab instead. Images from https URLs do display. console.log, console.error, and console.warn output is captured and displayed in the built-in Console panel below the preview.
Can I see console output and errors?
Yes. Click the Console toggle to show the console panel. Any console.log, console.warn, or console.error calls from your JavaScript are captured and displayed with color-coded output (gray for log, yellow for warn, red for error). Runtime and syntax errors are also caught and displayed with the line number in your JS or HTML tab.
Can I download my code as a file?
Yes. Click Download to save your project as a single, self-contained HTML file. The file includes your HTML in the body, CSS in a style tag, and JavaScript in a script tag, plus the same default page styles the preview uses. You can open the downloaded file in any browser and it will look and behave like the preview, except that external files and network requests blocked in the preview will load normally there.
Is this like CodePen?
It provides similar core functionality: separate HTML, CSS, and JS editors with a live preview panel. The key differences are that WritePadPro runs entirely in your browser with no account required, no server saves, and no data transmitted anywhere. Your code stays private on your device. It is designed for quick prototyping, testing snippets, and learning.
Is my code private?
Completely. All code editing and preview rendering happens in your browser. Your HTML, CSS, and JavaScript are never sent to any server, stored in any database, or processed by any API. The preview iframe uses srcdoc (not a server URL), so even the rendered output stays local.