Styling Go terminal output with Lip Gloss: colors, padding and layouts

Lip Gloss is a Go library from Charm for styling terminal text. You describe a style once (colors, bold, padding, borders, width, alignment) and call Render on strings to get ANSI-styled output. It is the styling layer used by Bubble Tea apps, but it works fine in a plain CLI too.
The examples below use Lip Gloss v2 (v2.1.0 at the time of writing). The original version of this post targeted v1; the differences are noted at the end.
Install
Section titled “Install”go get charm.land/lipgloss/v2v2 lives under the charm.land vanity import path, not github.com/charmbracelet/lipgloss.
Styling text
Section titled “Styling text”A style is a value you build with chained methods, then apply with Render:
package main
import "charm.land/lipgloss/v2"
func main() { style := lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("46")). // ANSI 256: bright green Background(lipgloss.Color("0")) // ANSI 16: black
lipgloss.Println(style.Render("Hello, World!"))}lipgloss.Color accepts ANSI 16 codes ("5"), ANSI 256 codes ("201") or hex true color ("#0000FF"). Print with lipgloss.Println (or Print, Printf, Fprint, and so on) rather than fmt.Println: the Lip Gloss writers downsample colors to what the terminal supports and strip escape codes entirely when output isn’t a TTY, so piping to a file doesn’t fill it with \x1b[...] noise.
A header, body and footer that fit the terminal
Section titled “A header, body and footer that fit the terminal”Lip Gloss doesn’t detect the terminal size itself. Get it from golang.org/x/term (go get golang.org/x/term), fall back to a fixed width when stdout isn’t a terminal, and stack the blocks with JoinVertical:
package main
import ( "os"
"charm.land/lipgloss/v2" "golang.org/x/term")
func main() { width, _, err := term.GetSize(int(os.Stdout.Fd())) if err != nil { width = 80 // not a terminal, e.g. output piped to a file }
bar := lipgloss.NewStyle(). Foreground(lipgloss.Color("15")). Bold(true). Width(width). Align(lipgloss.Center)
header := bar.Background(lipgloss.Color("4")).Render("Lip Gloss in Go") footer := bar.Background(lipgloss.Color("1")).Render("Press q to quit")
body := lipgloss.NewStyle(). Padding(1, 2). Width(width). Render("Width wraps long text to the given number of cells, so this paragraph folds at the edge of the terminal instead of overflowing it.")
lipgloss.Println(lipgloss.JoinVertical(lipgloss.Left, header, body, footer))}A few things worth knowing from this example:
- Styles are values.
bar.Background(...)returns a modified copy, soheaderandfootershare the base settings without affecting each other. Widthsets a minimum width and wraps text that is longer. Combined withAlign(lipgloss.Center)it gives you full-width centered bars.JoinVerticalandJoinHorizontalcombine already-rendered blocks;Place,PlaceHorizontalandPlaceVerticalposition a block inside a larger area.- In a Bubble Tea program, don’t call
term.GetSizeyourself: use the width fromtea.WindowSizeMsg, which also updates when the window is resized.
Coming from v1
Section titled “Coming from v1”If you have v1 code (github.com/charmbracelet/lipgloss), the style API (NewStyle, Bold, Foreground, Width, Render) looks the same, but v2 changes how colors and terminal detection work. The v1 Renderer is gone: Render always emits full-color ANSI, and downsampling happens when you print through lipgloss.Println and friends (Bubble Tea v2 does this for you). lipgloss.Color now returns a standard color.Color, and v1’s AdaptiveColor moved to a compat package, with lipgloss.LightDark as the recommended replacement. Read the upgrade guide before switching.
Note also that there is no lipgloss.TerminalSize function in either version; use golang.org/x/term as shown above.
Further reading
Section titled “Further reading”© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)