How to use the playground
Write HTML, CSS and JavaScript side by side and see the result instantly. Save your work to get a link you can share. No sign-up needed.
Getting started
- Type in the HTML, CSS and JS panels. You only need the content of the page. There's no need for
<html>,<head>or<body>tags, and no need to link the CSS and JS yourself. - Watch the result update in the preview as you type.
- Check the console at the bottom of the preview for
console.log()output and errors. - Press Save to get a link you can share or come back to later.
Everything else is in the ⋯ menu at the top right.
Editors & running code
Running your code
- With Auto switched on, the preview refreshes a moment after you stop typing.
- Switch Auto off when you'd rather run code yourself, for example while writing a loop or an animation that restarts every time. Then press Run or Ctrl/⌘ + Enter.
- Every run starts the page fresh, so timers, event listeners and variables from the last run are cleared.
Editor features
- Tags, brackets and quotes close automatically, and matching tags and brackets are highlighted.
- Tab indents and Shift + Tab outdents. Both work on a selection of several lines.
- Ctrl/⌘ + / comments or uncomments the current line or selection.
How the panels are combined
Your CSS is placed in the page's <head>, your HTML in the <body>, and your JavaScript at the end of the body, so the HTML elements already exist when your script runs. You don't need to wait for DOMContentLoaded.
<!doctype html> or <html>, the playground keeps your document as it is and adds the CSS and JS panels into it.
The console
Click Console below the preview to open it. While it's closed, a badge shows how many messages are waiting, and turns red when there are errors.
- Shows
console.log,info,warn,error,tableandassert. Objects, arrays and elements are shown in a readable form. - Errors in your JS panel include the line number in the editor, e.g.
Uncaught ReferenceError: x is not defined (JS line 12). - Files from external resources that fail to load are reported too.
- Repeated identical messages are grouped with a counter instead of filling the list.
- Type JavaScript into the box at the bottom and press Enter to run it in the preview, for example
document.querySelectorAll('li').length. Use ↑ and ↓ to go back through what you've typed.
Loop protection
A loop that never ends, such as while (true) {} with a forgotten exit, would normally freeze the browser tab. The playground watches every loop in the JS panel and stops any loop that runs for more than 1 second. The console tells you which line it was on.
Loops that use await are never stopped, because they let the browser keep working between steps.
Turning it off
If you have a loop that genuinely needs longer, such as a heavy calculation:
- add the comment
// noprotectanywhere in your JS panel to turn it off for that playground, or - choose ⋯ → Loop protection to turn it off in your browser.
<script> tags in the HTML panel isn't protected.
Saving & sharing
Saving
Press Save (or Ctrl/⌘ + S). The first save gives your playground its own link, like https://playground.cssportal.com/s/Ab12Cd34. Give it a title by clicking Untitled at the top.
After that, Save updates the same link. The status next to the title shows Unsaved changes with an orange dot whenever there's something new to save.
Sharing
Press Share to copy the link. Anyone with the link can see and run your code, but only you can change it.
Opening someone else's playground
You can edit their code freely to experiment. To keep your changes, press Save copy. This creates a new playground with its own link, and the original stays as it was.
Forking your own work
To try a different idea without changing a playground you've already shared, press Fork. It saves a copy with a new link, and you carry on editing the copy.
Unsaved drafts
Until you save for the first time, your work is kept as a draft in this browser, so closing the tab by accident doesn't lose it. Drafts aren't shared or backed up, so save anything you want to keep.
My playgrounds
Choose ⋯ → My playgrounds… to see everything you've saved, newest first, with when it was last updated and how many times it's been viewed.
- Open any of them by clicking its title.
- Delete one with the bin icon. This removes it for everyone: its link will stop working. If it's the one you have open, your code stays on screen as an unsaved draft.
- Search by title once you have more than a handful.
No account needed, but it's tied to this browser
Your list is kept in this browser rather than in an account. That means:
- On another computer or browser, your playgrounds still open from their links, but you can't update or delete them there until you import your list.
- If you clear this site's browser data, the list is gone. The playgrounds themselves stay online, but you can no longer change them. Export your list now and then to be safe.
Moving your list to another device
- In My playgrounds…, press Export. A small
.jsonfile downloads. - On the other device, open the playground, go to My playgrounds…, press Import and choose that file.
External CSS & JS
Use this to bring in a library, framework, font or reset stylesheet from a CDN. Choose ⋯ → External CSS / JS… and paste one URL per line:
- Stylesheets are loaded in the
<head>, before your CSS panel, so your own rules can override them. - Scripts are loaded at the end of the page, before your JS panel, so the library is ready when your code runs. They load in the order you list them, so put a library before any plugin that needs it.
- URLs must start with
https://(orhttp://). Up to 10 of each are allowed. - They're saved with your playground and included when you download it.
Examples
Google Fonts (stylesheet)
https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap
Then use font-family: 'Inter', sans-serif; in your CSS.
A CSS reset (stylesheet)
https://cdn.jsdelivr.net/npm/modern-normalize@3.0.1/modern-normalize.min.css
An animation library (script)
https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.5/gsap.min.js
Then use gsap.to('.box', { x: 200 }) in your JS.
Good places to find these links are cdnjs and jsDelivr. Use a URL with a version number in it, so an update to the library can't suddenly break your playground.
import statements won't work there. Put module code in the HTML panel inside <script type="module">…</script> and import from a module CDN such as https://esm.sh/.
Layout & appearance
Switch layout
Choose ⋯ → Switch layout to swap between:
Resizing and collapsing
- Drag the divider between the editors and the preview to give either more room. While you drag, the preview's size in pixels appears in its corner, which is handy for testing media queries. You can also focus the divider and use the arrow keys.
- Collapse a panel you're not using (say, an empty JS panel) by clicking the arrow in its header, or by double-clicking the header. Click again to bring it back.
Light and dark
The playground follows your device's light or dark setting. To choose yourself, use ⋯ → Toggle light / dark. This only changes the editor. Your preview always looks the way your CSS says.
On a phone
On small screens the panels become tabs: HTML CSS JS Result.
Your layout, divider position, theme and console setting are remembered in this browser.
Downloading your work
Choose ⋯ → Download as HTML to get one .html file with your HTML, CSS and JS combined, plus links to any external files. Open it in any browser, or use it as the start of a real project. The file is named after your playground's title.
Keyboard shortcuts
On a Mac, use ⌘ wherever it says Ctrl.
| Ctrl + Enter | Run the code |
| Ctrl + S | Save |
| Ctrl + / | Comment or uncomment lines |
| Tab / Shift + Tab | Indent / outdent |
| Ctrl + Z / Ctrl + Shift + Z | Undo / redo (each editor has its own history) |
| ↑ / ↓ in the console box | Previous / next command |
| Esc | Close the menu or a dialog |
Limits & privacy
- Each panel can hold up to 150 KB of code, which is a lot for a demo.
- You can save up to 30 times an hour. This keeps spam bots out and won't affect normal use.
- There are no accounts and no public gallery. A playground can only be found by someone who has its link, and saved playgrounds don't show up in search engines.
- Your code runs in a sandboxed preview, separated from the rest of the site, so code you open from someone else's link can't reach your browser data for this site.
- Because of that sandbox,
localStorageandsessionStorageinside the preview work, but are emptied on every run. Cookies don't work there at all. - Old playgrounds that nobody has looked at in a long time may be removed during clean-ups. Download anything you want to keep forever.
Troubleshooting
The preview doesn't update
Check whether Auto is switched off. If it is, press Run. If the preview is blank, open the Console and look for a red error: one JavaScript error can stop the rest of your script.
A library from a CDN isn't working
Open the console. Failed to load resource means the URL is wrong or the file has moved, so try opening the URL in a new tab. If the file loads but you get … is not defined, check the order: the library must be listed before anything that uses it.
The button says “Save copy” instead of “Save”
This browser doesn't have the key for that playground, either because someone else made it or because you saved it on another device or browser. Import your list from My playgrounds… to edit it here, or press Save copy to make your own version.
“Possible infinite loop … it was stopped”
A loop ran for over a second. Check its exit condition. If it really does need longer, see Loop protection.
Submitting a form makes the preview go blank
The form is sending the page somewhere else. Stop that in your submit handler with event.preventDefault(), then handle the data in JavaScript.
Links in the preview open in a new tab
That's deliberate, so a link never replaces your preview. Links to #sections on the same page still work normally.
I closed the tab before saving
Open the playground again in the same browser: your unsaved draft is restored automatically. This only applies to work that has never been saved. For saved work, open it from My playgrounds….