Deploying Static Sites with Netlify

Discover how to deploy your static sites effortlessly with Netlify. Learn step-by-step setup, custom domains, CI/CD features, and deployment tips for web developers.


Back to Home

Table of content

Why Choose Netlify for Static Site Deployment?

Netlify is a popular platform among web developers for hosting static websites due to its ease of use, seamless integration with Git, and extra features like Continuous Deployment, custom domains, and serverless functions. For web projects built with frameworks like React, Vue, Hugo, or plain HTML/CSS/JS, Netlify offers a powerful free tier and rapid deployment workflow.

Prerequisites

  • GitHub, GitLab, or Bitbucket account (for repository hosting)
  • A static site ready for deployment (e.g., built with HTML, Gatsby, Next.js static export, etc.)
  • Netlify account (free registration)

Step-by-Step Guide: Deploying Your Static Site

1. Prepare Your Project

Ensure your site is static (no server-side code). If you use a static site generator (e.g., Hugo, Jekyll), run the build process locally to verify it produces the expected dist, build, or public folder.

2. Push Your Code to a Git Repository

Netlify integrates directly with Git hosting platforms. Clone your repo locally and commit your latest changes:

git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/yourusername/your-repo.git
git push -u origin main

3. Connect to Netlify

  1. Login at Netlify.
  2. Click New site from Git.
  3. Select your Git provider and authenticate.
  4. Choose your project repository.
  5. Configure build settings (e.g., build command npm run build and publish directory dist or build).
  6. Click Deploy site.

Your site is deployed in minutes at a Netlify subdomain (e.g., amazing-site-12345.netlify.app).

4. Configure Custom Domain (Optional)

  1. Go to your site settings in Netlify.
  2. Click Domain managementAdd custom domain.
  3. Enter your domain and follow DNS setup instructions.
  4. Netlify provides free automatic SSL certificates via Let’s Encrypt.

5. Continuous Deployment (CI/CD)

Every time you push changes to your selected branch, Netlify will automatically rebuild and redeploy your site. This ensures your deployment stays in sync with your Git repository.

Adding Environment Variables

If your static site needs API keys or other configuration, add environment variables in Site settingsBuild & deployEnvironment section.

Advanced Features Worth Exploring

  • Redirects/Rewrites: Fine-tune routing using _redirects file.
  • Form Handling: Add forms using Netlify’s built-in form detection feature.
  • Serverless Functions: Run backend code with Netlify Functions.
  • Plugin Ecosystem: Enhance builds with Netlify Build Plugins.

Sample netlify.toml Configuration

For complex setups, include a netlify.toml file at your project root:

[build]
  command = "npm run build"
  publish = "dist"

[[redirects]]
  from = "/api/*"
  to = "https://api.example.com/:splat"
  status = 200
  force = true

Conclusion

Deploying static sites with Netlify is a straightforward process that empowers web developers to go live quickly, with minimal configuration. With Git integration, CI/CD, custom domains, and extra features, Netlify stands out as an excellent choice for modern web projects.

"dashboard"
a11y
Accessibility
Angular
Angular Hooks
Express
Frontend
netlify
Node.js
React
static site deployment
static sites
Tutorial