Skip to main content
In this tutorial, you’ll build a blog website with server-rendered pages, layouts, forms, and static assets.

What We’ll Build

A blog website with:
  • Homepage listing posts
  • Individual post pages
  • Create post form
  • Shared layout and navigation
  • CSS styling

Prerequisites

  • Go 1.22 or later
  • Basic HTML/CSS knowledge
  • Completed the First API tutorial (helpful but not required)

Step 1: Create the Project

Create the directory structure:

Step 2: Create the Layout

Create templates/layouts/main.html:

Step 3: Create Page Templates

Create templates/home.html:
Create templates/post.html:
Create templates/new-post.html:

Step 4: Add CSS

Create static/css/style.css:

Step 5: Create the Server

Create main.go:

Step 6: Run and Test

Open http://localhost:3000 in your browser. Try:
  1. Click β€œNew Post” to create a post
  2. Fill in the form and submit
  3. View the post
  4. Go back to see it on the homepage

Step 7: Add Sample Data

Add some initial posts in main():

What You Learned

  • Using Go templates with layouts
  • Serving static files (CSS, images)
  • Handling form submissions
  • Redirecting after form submission
  • Template composition

Project Structure

Next Steps

Build Full-Stack App

Add a React frontend.

View Engine

Advanced template features.