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
- Open your project folder in Visual Studio Code.
- Install the Live Server extension if it is not already installed.
- In the Explorer, right-click your HTML file and select Open with Live Server, or select Go Live in the status bar.
- 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?
- Python: A quick, no-extra-package option for a one-off preview.
- VS Code Live Server: Convenient while editing, especially when you want automatic browser refreshes.
- Node.js: Useful if Node.js is already part of your workflow.
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.