HOW-TO

How to run an HTML file (in a browser, VS Code, or a local server)

An HTML file does not need compiling: a browser runs it. How to open it, when you need a local server instead, the errors that mean you do, and how to let someone else run it from a link.

4 min read·

HTML is not compiled or installed. "Running" an HTML file means opening it in a web browser, which reads the HTML, applies the CSS and runs the JavaScript inside it. Most files work with a double-click. Some need a small local server, covered below.

Open it in a browser

If it opens in Notepad or a code editor instead, the file association is wrong. See opening an HTML file on Windows or on a Mac.

  • ✓Double-click the .html file. It opens in your default browser.
  • ✓Or drag the file onto an open browser window.
  • ✓Or right-click it, choose Open with, and pick Chrome, Edge, Safari or Firefox.
  • ✓The address bar then starts with file:///, which means the browser is reading the file straight from your disk.

Run it from VS Code

  • ✓Open the folder that holds the file with File > Open Folder.
  • ✓Install the Live Server extension from the Extensions panel.
  • ✓Open the .html file and click Go Live in the status bar at the bottom.
  • ✓The page opens at an address like http://127.0.0.1:5500 and reloads each time you save.

When a double-click is not enough

Browsers restrict pages opened from file:// for security. A page that works fine on a server can break locally if it does any of these:

  • ✓Loads a .json or .csv file with fetch(). Chrome and Edge block it with a CORS error in the console.
  • ✓Uses <script type="module"> or import statements. Modules do not load from file:// in Chrome.
  • ✓Is a built app (React, Vue, Vite) whose dist/index.html loads files from /assets/. The leading slash points at the root of your disk, not the folder.

Start a local server

A local server serves the folder over http:// so these restrictions no longer apply. If Python is installed (it is on most Macs and Linux machines), open a terminal in the folder and run:

python3 -m http.server 8000

Then visit http://localhost:8000 in the browser. On Windows the command may be python instead of python3. With Node.js installed, npx serve does the same job. Press Ctrl+C in the terminal to stop it.

Check for errors

If the page is blank or a button does nothing, open the browser console: F12 on Windows, Cmd+Option+J in Chrome on a Mac. Red lines name the file and line that failed. "Failed to load resource" usually means a wrong path or file name; "blocked by CORS policy" on a file:/// address means you need the local server above.

Let someone else run it

A local server only works on your machine. Sent as an attachment, the file often arrives as a download, opens without its images, or hits the same file:// limits on the other person's computer. A hosted copy runs at an https:// address on any phone or computer.

With FileShare Pro: upload the .html file from the dashboard, copy the link and send it. It is served over https, so fetch and modules behave as they do on a normal website, and the person opening it needs no account. Sign up free to share your first page.

Frequently asked

How do I run an HTML file?

Double-click it or drag it into a browser window. The browser runs the HTML, CSS and JavaScript; nothing needs to be compiled or installed.

Why does my HTML file work in VS Code Live Server but not when I double-click it?

Opened from file://, browsers block fetch() requests for local files and JavaScript modules. Live Server serves the folder over http://, where those work.

How do I run an HTML file with Python?

Open a terminal in the folder and run python3 -m http.server 8000, then visit http://localhost:8000 in your browser.

How can someone else run my HTML file?

Host it and send the link. The page then runs over https in their browser, on any device, without downloading anything.

Got a page to share?

Drop the file, copy the link — live in seconds, free plan included.

Start sharing free