How to Run HTML, CSS and JavaScript Online Without Installing Anything
By Durim Hoti · Last updated
How HTML, CSS and JavaScript fit together
The editor has one tab per language and builds a single page from them: the CSS goes into the page's <head>, and the JavaScript runs at the end of the <body>, after the HTML elements exist. That's why a script in the JS tab can find elements from the HTML tab. If you paste a complete document with its own <html>, <head> and <body>, the editor keeps that structure.
Run your code step by step
- Open the HTML editor. It starts with a small example you can overwrite.
- Write your markup in the HTML tab, your styles in CSS and your script in JS.
- Watch the preview update. With Auto preview off, press Run or Ctrl+Enter (Cmd+Enter on a Mac).
- Open the Console under the preview to see
console.logoutput and errors. - Use Open preview to see the page in its own tab, Fullscreen for a larger view, or Download HTML to save everything as one file.
Example: reading a console error
This small shop page has a button and a script that should react to clicks on it:
<button id="buy">Buy now</button>
<p id="total">Total: 0</p>console.log("Total:", 2 + 3);
document.querySelector("#by").addEventListener("click", () => {});The preview shows the button, and the console shows:
Total: 5
Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')
The first line worked, so the script did run. The error says that addEventListener was called on null: querySelector("#by") found nothing, because the button's id is buy. Fix the selector to #buy and the error disappears.
Common problems
Cannot read properties of null
A selector found no element, as in the example above. Check the spelling of ids and classes. In a complete document, a script in the <head> runs before the body exists; move it to the end of the body or add defer.
The page stops responding to a loop
An endless loop would freeze a normal browser tab. The editor stops any loop that runs for more than a second without a break and reports the line:
let i = 0;
while (true) {
i++;
}Stopped the loop on line 2: it ran for more than 1 second without a break (possible infinite loop).localStorage throws a SecurityError
The preview has no access to storage. In our test, localStorage.setItem() failed with:
localStorage: SecurityError - Failed to read the 'localStorage' property from 'Window': The document is sandboxed and lacks the 'allow-same-origin' flag.Wrap storage calls in try…catch while testing here, and try them in a file opened directly in your browser.
Images, stylesheets or fetch() requests fail
Relative paths such as img/logo.png point to files the editor doesn't have; use full https:// addresses. The same applies when you open a file elsewhere, as our guide on opening HTML files shows. fetch() calls to other sites only work if that site allows requests from any origin, because the sandboxed preview has no origin of its own.
Editor or compiler?
Both run HTML, CSS and JavaScript the same way. The HTML editor is the place for everyday editing. The HTML compiler adds starter templates and share links that keep the code in the URL. Both save your work in the browser. When the page is done, you can turn it into a document; see how to convert HTML to PDF.
FAQ
- Do I need to install anything to run HTML code?
- No. The editor runs in your browser and shows the result in a preview frame on your device. Your code is not uploaded to a server.
- Is my code saved?
- Yes, in your browser's local storage on this device, so it is still there when you come back. It is not stored online. Use Download HTML to keep a copy as a file.
- Can I use libraries such as jQuery from a CDN?
- Yes. Add a script tag with the library's full https:// address in the HTML panel. In our test, jQuery 3.7.1 from cdnjs loaded and ran in the preview.
- Why does localStorage throw an error in the preview?
- The preview is a sandboxed frame without access to this site's storage, so the browser blocks localStorage there. Test code that needs storage in a file opened directly in your browser.
- How do I share my code with someone?
- The HTML compiler can create a link that contains your HTML, CSS and JavaScript. Whoever opens it gets their own copy. In the editor, use Download HTML and send the file.
- Does it work on a phone?
- Yes. On small screens the code and the preview are separate tabs, so you switch between writing and looking at the result.
Try it and keep reading
- Open the Online HTML editorEdit HTML, CSS and JavaScript with a live preview.
- How to Open an HTML File on Any DeviceSee the page or the code of an .html file on a computer or a phone, and fix missing images.
- How to Convert HTML to PDF and Keep the CSSTurn an HTML file or code into a PDF that keeps its backgrounds, fonts and images.