How to Deploy a Static Website with Netlify

Deploy a static website on Netlify's free plan by drag and drop or from a Git repo, then add a custom domain with free HTTPS.

Hosting a static website on your own domain meant renting a Virtual Private Server (VPS), and jumping through a few hoops. Today, several web app hosting platforms do it in minutes. In a previous post, I covered Railway, which runs your site in a container. Netlify takes a different approach. It is built for static sites and front-end apps: it serves your files from a global CDN, rebuilds the site whenever your repository changes, and handles HTTPS for you.

Netlify homepage
Image source: Netlify.com

This guide covers two ways to publish a site on Netlify: dragging a folder into the browser, or connecting a Git repository.

Option 1: Drag and Drop with Netlify Drop

This is the fastest route, and you don't need Git.

  1. Put your site in a folder with an index.html file at the top level. Netlify serves that file as the home page.
  2. Sign in to Netlify, then open Netlify Drop.
  3. Drag the folder, a zip file, or a single HTML file onto the page.
Upload a site folder to Netlify
Upload a site folder to Netlify

Within seconds the site is live at a random xxx.netlify.app address. To change it, select Customize under the URL and give the project a name. To update the site later, drag the updated folder onto the project's Production deploys area.

Option 2: Deploy from a Git Repository

If your site lives on GitHub, GitLab, Bitbucket or Azure DevOps, connect the repository so that every push deploys automatically.

  1. In the Netlify dashboard, select Add new project → Import an existing project.
  2. Choose your Git provider and authorize Netlify to read your repositories. On GitHub, this installs the Netlify app on your account, and you can limit it to the repositories you choose.
Install Netlify app to Git environment
Install Netlify app to Git environment

Next, pick the repository and the branch to deploy. For a plain HTML site, leave the build command empty and set the publish directory to the folder that contains index.html (often the repository root). For a static site generator such as Hugo or Astro, Netlify usually detects the build settings for you. Then select Deploy.

From then on, each push to that branch publishes a new version. Pull requests get their own preview URL, so you can check a change before it goes live.

Adding a Custom Domain

If you don't have a domain yet, see my comparison of domain registrars for what each one charges at renewal.

In your project, go to Domain management → Add a domain → Add a domain you already own, enter the domain and confirm. Then point the domain at Netlify in one of two ways:

  • Netlify DNS: change your domain's name servers at your registrar to the ones Netlify shows you. Netlify then manages all the records.
  • Keep your current DNS provider: add the records yourself. For www, create a CNAME pointing to your xxx.netlify.app address. For the bare domain (example.com), create an A record pointing to 75.2.60.5, or an ALIAS/ANAME record pointing to apex-loadbalancer.netlify.com if your provider supports one. Netlify shows the exact values for your domain under Pending DNS verification.
DNS configuration for custom domain
DNS configuration for custom domain

If your DNS is on Cloudflare, set these records to DNS only (grey cloud), not proxied, or Netlify can't issue the certificate. DNS changes can take anywhere from minutes to a day to show up everywhere. To check from a terminal:

dig +short www.example.com CNAME
dig +short example.com A

Once the records resolve to Netlify, it issues a free Let's Encrypt certificate and renews it automatically. You can follow its status under Domain management → HTTPS.

Frequently Asked Questions

Is Netlify free for static websites? Yes, for most personal sites. The Free plan includes custom domains and HTTPS, and 300 credits a month for deploys, bandwidth and requests. If you use them up, the site pauses until the next month rather than charging you.

Do I need Git to use Netlify? No. Netlify Drop publishes a folder, zip file or single HTML file from your browser. Git is only needed if you want every push to deploy automatically.

Why won't Netlify issue an HTTPS certificate for my domain? Usually because the DNS records haven't propagated yet, or they point somewhere else. Other common causes are a Cloudflare record left on proxied, and a CAA record that doesn't allow Let's Encrypt.

What are the alternatives? If you'd rather run your site in a container, I've covered static hosting on Railway with NGINX and Railway with Caddy. DigitalOcean App Platform also hosts static sites for free, up to three apps with 1 GiB of outbound data each. I’ve covered running Caddy on DigitalOcean App Platform too.

Subscribe to alphasec

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe