Saved

Press the star next to a tool's name to save it.

All my tools

Online Code Editor

Write HTML, CSS and JavaScript in one place, press Run, and this online code editor shows the result in a sandboxed preview. Your work is saved in your browser.

Press Run to see your page. Your code is saved in this browser whenever you run it.

Your code stays in your browser and runs in an isolated frame.

Preview

Write some code and press Run.

An online code editor lets you try out an idea in seconds, with nothing to install. Write your HTML, CSS and JavaScript in three separate tabs, press Run, and this online code editor shows the finished page in a live preview right beside your code. It's useful for learning web development, testing a small snippet, reproducing a bug, or building a quick prototype. Your code is saved in your browser each time you run it, and you can download the whole thing as a single HTML file when you're done.

How to use the online code editor

  1. Choose the HTML tab and write your page's content.
  2. Add styles in the CSS tab.
  3. Add behavior in the JavaScript tab.
  4. Press Run to see the result.
  5. Download your page as one file, or copy it.

A first example

In the HTML tab, type a heading and a button: an h1 element saying Hello, and a button with the id “go.” In the CSS tab, set the heading's color to tomato. In the JavaScript tab, find the button with document.querySelector and add a click listener that changes the heading's text. Press Run, click the button in the preview, and you'll see your program respond. Change a value and press Run again to see the difference right away.

What each language does

LanguageJob
HTMLThe structure and content of the page
CSSColors, layout, fonts and spacing
JavaScriptBehavior and interactivity

You only need to write the content of the page in the HTML tab. The editor wraps your code in a complete document, placing your CSS in the head and your JavaScript at the end of the body, so that your script can find the elements above it.

Is it safe to run code here?

The preview runs in a sandboxed iframe. The sandbox attribute applies extra restrictions to the content in a frame. This tool allows scripts to run, but it doesn't grant the same-origin permission, so code in the preview can't read this website's data or your stored information. MDN warns that combining allow-scripts with allow-same-origin on a same-origin frame would defeat the sandbox, which is why that permission is deliberately left out. You should still be cautious about pasting code that you don't understand from people you don't know.

What it's good for

  • Learning: experiment with tags, selectors and functions.
  • Teaching: demonstrate a concept without any setup.
  • Debugging: strip a problem down to a tiny example.
  • Prototyping: sketch a layout or an interaction quickly.
  • Email and embed snippets: check that a small piece of HTML looks right.

Limits of the preview

Because the preview is isolated, some features won't work as they would on a real website. Code in the frame can't store cookies or use local storage, since it has no origin of its own. Requests to other websites may be blocked by those sites' security rules. There's no built-in package manager or file system. For a larger project, use a full editor on your own computer, with a local development server.

Saving your work

Whenever you press Run, your code is saved to this browser's local storage, and it's restored the next time you visit. It isn't uploaded to our server, and it doesn't sync across devices. To keep a permanent copy, press Download as HTML, which gives you a single file that you can open in any browser or upload to a web host. Clearing your browser data will remove the saved version.

Tips for writing better code

  • Make small changes and run often, so that you can spot what caused a problem.
  • Check your closing tags. A missing one can affect everything that follows.
  • Read error messages in your browser's developer console.
  • Use meaningful names for classes and variables.
  • Format your code so that it's easy to read later.

Where to go next

Once you're comfortable with the basics, try building something small from start to finish, such as a calculator, a to-do list or a quiz. Finishing a tiny project teaches you more than reading about a large one. When your page grows beyond a single file, move it into a code editor on your computer, and use a version control system to keep track of your changes.

Sharing your work

Copy full page puts the complete document on your clipboard, ready to paste into a message or a new file. The downloaded file needs no other files to run, so you can email it to a friend or open it on another computer.

Common mistakes

  • Forgetting to press Run. The preview only updates when you ask.
  • Putting CSS in the HTML tab without a style element.
  • Expecting local storage to work inside the preview.

Tidy your markup with the HTML formatter, shrink your files with the CSS and JavaScript minifier, and test a pattern with the regex tester.

What next

Use this often? Add Online Code to your Home screen.

Frequently asked questions

How does the online code editor work?

You write HTML, CSS and JavaScript, and it combines them into a page that runs in a preview frame.

Is my code saved?

Yes, in this browser, each time you press Run.

Is the preview safe?

It runs in a sandboxed frame with no access to this site's data.

Can I download my page?

Yes. You can download it as a single HTML file.

Can I use local storage in the preview?

No. The sandboxed frame has no storage of its own.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Developer Tools