HTML Code Editor

Online HTML editor with live preview. Free HTML code editor.

HTML

Preview

Rate this tool

How useful was this tool?

HTML Code Editor

Write or paste HTML in the HTML panel, and the Preview beside it shows the page as you type. CSS goes in <style> tags and JavaScript in <script> tags, all in the same panel. The preview runs them as a browser would.

  • Example loads a small working page.
  • Format tidies the HTML, CSS and JavaScript in one click.
  • Copy and Download take your work out, the download as an .html file.
  • Clear starts over.
  • Update as you type keeps the preview live. Run again reloads it from scratch.

Paste a short snippet or a whole document: the editor tells you which it sees and handles both. Mistakes such as a tag closed too early are listed with their line number. Your work stays in your browser, so it’s still there when you come back.

Example

The Example is a heading, a paragraph and a small card with a click counter:

<h1>Hello, world!</h1>
<p>Edit the code on the left; the preview updates as you type.</p>

<style>
  .card {
    max-width: 320px;
    padding: 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
  }

  button {
    padding: 0.4rem 0.8rem;
  }
</style>

<div class="card">
  <p>Clicked <strong id="count">0</strong> times.</p>
  <button onclick="count.textContent = Number(count.textContent) + 1">Click me</button>
</div>

The preview shows “Hello, world!” as a heading, the paragraph, and a rounded card reading “Clicked 0 times.” with a Click me button. Each click adds one. Change max-width: 320px to 500px, or the border-radius, and the card changes as you type.

The button uses a shortcut worth knowing about: an element with an id becomes a global variable of the same name, so count refers to <strong id="count">. It’s handy in a quick demo. In real code, document.getElementById('count') is safer, because the shortcut breaks as soon as a variable or another element has the same name.

Snippet or whole document

You don’t need to write a complete page. A snippet, like the example, is placed into a page of its own for the preview: no <!DOCTYPE>, <html> or <head> needed. A whole document, from <!DOCTYPE html> to </html>, is previewed exactly as written, with its own head, title and meta tags. The editor says which of the two it sees, so you know what the preview is based on.

Mistakes, with their line

Browsers are forgiving: they quietly repair broken HTML, so a page can look right in the preview while its code is wrong. Elsewhere, the same code may behave differently. The editor lists such mistakes with the line they’re on. Typical ones:

  • A tag closed too early. In <p>Some <strong>bold</p></strong>, the </p> closes the paragraph while <strong> is still open.
  • An element that’s never closed, such as a <div> without its </div>. Everything after it ends up inside it.
  • A closing tag with nothing to close, often left over after a deletion.

Fix the line named, and the entry disappears.

Format

Format lays out the whole panel at once: indentation for the HTML, one declaration per line for the CSS, and readable JavaScript. It’s the quickest way to make pasted, minified or messy code readable. To format code without a preview, or to shrink it again for production, there are separate tools: the HTML Formatter, the JS Formatter, the HTML Minifier and the CSS Minifier.

Update as you type, or Run again

With Update as you type on, the preview reloads as you edit. That’s ideal for HTML and CSS. With JavaScript, every reload runs your script again from the start, so a half-typed line can show an error for a moment. Untick it while you write longer scripts, and click Run again when you’re ready.

Run again is also how you reset a page. In the example, the counter goes back to 0, and any timers or changes your script made are gone.

The preview is a page of its own

The preview runs in a separate, sandboxed frame. It’s a real page, not part of this site, and this site’s light or dark theme doesn’t spill into it, so what you see is what your code looks like in a browser.

To make your page follow the visitor’s light or dark setting, add this to the <head> of a whole document, or at the top of a snippet:

<meta name="color-scheme" content="light dark">

The browser then uses its own dark colours for the background, text and form controls when the visitor’s system is set to dark. For your own colours, use a media query:

@media (prefers-color-scheme: dark) {
  .card { border-color: #444; }
}

Using libraries

You can load stylesheets and scripts from a CDN, such as Bootstrap, a font from Google Fonts, or a charting library, with ordinary <link> and <script src> tags. The preview loads them like any page would.

Relative links are different. images/logo.png or style.css won’t load, because the preview has no folder of files behind it. Use full https:// addresses instead.

Your work stays in your browser

The editor keeps your code in your browser’s storage, not on our server, so it’s there when you come back to the page. That also means it lives only in this browser on this device. It’s gone if you clear your browsing data, and it won’t appear on another computer. Use Download to keep a copy as an .html file you can open anywhere.

FAQ

Is this a visual (WYSIWYG) editor?

No. You write the code and the preview shows the result. That’s the point: you see exactly what each line does.

Can I use JavaScript?

Yes. Put it in <script> tags. Events, DOM changes and most browser features work as they would on a normal page.

Why does my page look different here than on my website?

Usually because your website adds things the snippet doesn’t have: your site’s own stylesheet, fonts, or files loaded by relative paths. Include the CSS in a <style> tag, and use full addresses for images and other files.

Can it run PHP or other server code?

No. The preview is a browser, so it runs HTML, CSS and JavaScript only. Anything that needs a server, such as PHP, a database or form submissions, won’t work here.

Is my code private?

Yes. Everything runs in your browser tab, and your code isn’t sent to or stored on our server.

Note: All processing is done client-side. We do not store or see your data.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us