How to deploy a static website for free
A static site, meaning HTML, CSS, JavaScript and images with no server-side code, can be hosted for free on several platforms. It's a great first deployment.
What counts as static
- Hand-written HTML/CSS/JS sites
- Output from static site generators
- Many front-end apps built with tools like Vite, as long as they don't need a running server
Common free hosting options
- Git-based hosting platforms that build and deploy automatically when you push to a repository
- Code hosting pages features that publish a site straight from a repository branch or folder
- Object storage with a CDN for more control, though setup is more involved
General steps
- Put your project in a Git repository and push it to a code host.
- Connect the repository to your chosen platform.
- Set the build command and output folder if you use a build tool (for example,
npm run buildanddist). For plain HTML, there may be no build step. - Deploy. You'll get a free subdomain URL.
- Add a custom domain if you have one, and the platform will usually issue a free HTTPS certificate.
Things to check
- Single-page apps may need a rewrite rule so all routes serve
index.html, otherwise refreshing a page gives a 404. - Relative paths: assets may break if the site is served from a subfolder.
- Free tier limits on bandwidth or build minutes, which are usually generous for personal sites.
- Environment variables: anything in front-end code is public, so never include secret keys.
Where did you host your first static site? Did the 404-on-refresh problem catch you too?
Comments · 3
One thing worth doing early: test the deployed URL, not just localhost. Missing base paths and case-sensitive file names are the usual reasons a site works locally and breaks after deploy.
The single-page app rewrite rule is the detail that trips up beginners most often. Without it, refreshing on a nested route returns a 404 because the host looks for a real file at that path.
Free hosting is great, but buy your own domain if you can. It's often under $15 a year, and it lets you move hosts without changing the link.