Suresh Kamrushi
Practical guide · Local development

How to Preview an HTML Page on Your Computer

You can open an HTML file directly, but a small local web server is a better way to test pages that use scripts, stylesheets, or other assets. Choose one of these three simple options.

First, put your HTML page and any files it needs—such as CSS, JavaScript, and images—in a folder. Open a terminal in that folder, start a local server, then visit its local address in your browser. Keep the server running while you preview the page; press Ctrl+C in the terminal when you are finished.

Option 1: Use Python

Python includes a basic web server, so there is no extra package to install when Python is available. In a terminal, navigate to your project folder and run:

python -m http.server 8000 --bind 127.0.0.1

On Windows, py -m http.server 8000 --bind 127.0.0.1 may be the command to use. Open http://localhost:8000/ in your browser. If you use another port, replace 8000 in the address with that port.

Option 2: Use VS Code Live Server

  1. Open your project folder in Visual Studio Code.
  2. Install the Live Server extension if it is not already installed.
  3. In the Explorer, right-click your HTML file and select Open with Live Server, or select Go Live in the status bar.
  4. Use the local address opened in your browser. Live Server refreshes the page when you save changes.

Option 3: Use Node.js

If Node.js and npm are installed, run this from your project folder:

npx http-server -p 8080 -a 127.0.0.1

Then open http://localhost:8080/. The first run may ask to download the http-server package through npx.

Keep it local: These examples bind the server to your own computer so the preview is not intentionally made available to other devices on your network.

Which option should you choose?

All three let you test a local page in a browser before publishing it. They do not publish the page to the internet; for that, upload it to a web host or deploy it to a static hosting service.