Searches for golang multiline string, go multiline string, multiline string golang, golang multiline strings, golang multi line string, multiline string go, go multi line string, golang multiline string literal, multiline string in golang, or golang multiline string with variables all map to the same language rules: Go has raw string literals (backticks) that can span lines without escape processing, and interpreted string literals (double quotes) where you use \n and break source lines with concatenation or tools like fmt.Sprintf and strings.Builder. Other languages allow multi-line "..." text blocks; Go does not—use backticks or +. For Python-style triple quotes see multiline comments / strings in Python.
Tested with Go 1.24 on Linux.
golang multiline string literal: raw strings (backticks)
The Go spec — String literals defines raw string literals: text between backticks `...`. Inside them, backslashes are not escapes (so \n is a backslash and n), and newlines are real newlines in the string value. The only character that cannot appear inside is a backtick itself (close the literal, use concatenation, or use an interpreted string).
package main
import "fmt"
func main() {
s := `line 1 \n \t literal
"quotes are fine"
line 3`
fmt.Print(s)
}line 1 \n \t literal
"quotes are fine"
line 3Carriage returns (\r) inside raw literals are dropped from the value (spec). Leading and trailing spaces on each physical line are kept—format carefully.
go multiline string with interpreted literals and +
Double-quoted strings cannot contain raw newline characters in source. Split long text across lines with +, and use \n, \t, \" where you need escapes:
package main
import "fmt"
func main() {
s := "line one\n" +
"line two\n" +
"line three"
fmt.Print(s)
}line one
line two
line threeThis is the usual go multi line string style when you need escape processing but readable source layout.
golang multiline string with variables
Backticks cannot interpolate identifiers. Common patterns:
Concatenation (simple):
name := "Ada"
body := "Hello " + name + ",\n" +
"your build finished.\n"fmt.Sprintf (formatting):
user, score := "Bob", 98
msg := fmt.Sprintf("%s scored %d\nnext line", user, score)strings.Builder (many pieces, efficient):
package main
import (
"fmt"
"strings"
)
func main() {
name := "Ada"
var b strings.Builder
b.WriteString("# Report\n")
b.WriteString("user: ")
b.WriteString(name)
b.WriteByte('\n')
fmt.Print(b.String())
}For many fixed lines stored as data, build a []string and use strings.Join(lines, "\n").
Choosing a style
| Need | Prefer |
|---|---|
SQL, JSON templates, regex with lots of \ |
Raw `...` |
Escapes like \n, \t, \" |
Interpreted "..." with + |
| Dynamic values | +, Sprintf, or strings.Builder |
| HTML or mail bodies | text/template or html/template (not shown here, but better than giant literals) |
Summary
A golang multiline string is usually either a raw literal in backticks (golang multiline string literal with real newlines, no escapes) or a concatenated interpreted string for go multiline string style with \n. golang multiline string with variables requires concatenation, fmt.Sprintf, or a strings.Builder—not backtick interpolation. Watch invisible spaces at line ends in raw literals, and remember \r stripping in raw values.
References
- The Go Programming Language Specification — String literals
fmtpackage —Sprintfstringspackage —Join,Builder

