Skip to content

Instantly share code, notes, and snippets.

@maxsei
Last active June 18, 2026 05:02
Show Gist options
  • Select an option

  • Save maxsei/7f2c5dce59f23df5a561ee975ba33e8a to your computer and use it in GitHub Desktop.

Select an option

Save maxsei/7f2c5dce59f23df5a561ee975ba33e8a to your computer and use it in GitHub Desktop.
CSS page transitions API
<!-- templates/index.html -->
{{ template "layout" . }}
{{ define "title" }}Home{{ end }}
{{ define "content" }}
<h1>Home</h1>
<!-- templates/layout.html -->
{{ define "layout" }}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ block "title" . }}{{ end }}</title>
<link rel="stylesheet" href="/static/style.css" />
</head>
<body>
<nav>
<a href="/one">One</a>
<a href="/two">Two</a>
<a href="/three">Three</a>
</nav>
<main>
{{ block "content" . }}{{ end }}
</main>
</body>
</html>
{{ end }}
package main
import (
"html/template"
"log"
"net/http"
"time"
)
func main() {
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
render(w, "index.html")
})
http.HandleFunc("/one", func(w http.ResponseWriter, r *http.Request) {
render(w, "one.html")
})
http.HandleFunc("/two", func(w http.ResponseWriter, r *http.Request) {
render(w, "two.html")
})
http.HandleFunc("/three", func(w http.ResponseWriter, r *http.Request) {
render(w, "three.html")
})
log.Println("listening on http://localhost:8080")
log.Fatal(http.ListenAndServe(":8080", nil))
}
func render(w http.ResponseWriter, page string) {
time.Sleep(500 * time.Millisecond)
tmpl := template.Must(template.ParseFiles("templates/layout.html", "templates/"+page))
tmpl.ExecuteTemplate(w, "layout", nil)
}
<!-- templates/one.html -->
{{ template "layout" . }}
{{ define "title" }}Page One{{ end }}
{{ define "content" }}
<h1>Page One</h1>
<p>Hello from page one!</p>
{{ end }}
/* static/style.css */
@view-transition {
navigation: auto;
}
::view-transition-old(main),
::view-transition-new(main) {
animation-duration: 300ms;
}
<!-- templates/three.html -->
{{ template "layout" . }}
{{ define "title" }}Page Three{{ end }}
{{ define "content" }}
<h1>Page Three</h1>
<p>Hello from page three!</p>
{{ end }}
<!-- templates/two.html -->
{{ template "layout" . }}
{{ define "title" }}Page Two{{ end }}
{{ define "content" }}
<h1>Page Two</h1>
<p>Hello from page two!</p>
{{ end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment