| name | charm-lipgloss |
| description | CSS-like terminal styling for Go with lipgloss v2 - styles, colors, borders, layout, tables, lists, and trees. Use when styling Go terminal output, lipgloss, terminal layout composition, or building styled tables/lists/trees in Go. |
Lip Gloss v2
CSS-like terminal styling for Go. Import: charm.land/lipgloss/v2
v1 (github.com/charmbracelet/lipgloss) is deprecated. See references/v1-to-v2-migration.md.
Quick Start
package main
import "charm.land/lipgloss/v2"
func main() {
style := lipgloss.NewStyle().
Bold(true).
Foreground(lipgloss.Color("#FAFAFA")).
Background(lipgloss.Color("#7D56F4")).
Padding(1, 2).
Width(30)
lipgloss.Println(style.Render("Hello, terminal!"))
}
Rules:
- Use
lipgloss.Println not fmt.Println for automatic color downsampling
Style is a value type. Assignment copies. No renderer, no pointers.
lipgloss.Color() is a function returning color.Color, not a type
Core API Reference
Style
Create: lipgloss.NewStyle(). All methods return new Style (immutable).
s := lipgloss.NewStyle().
Bold(true).Italic(true).Faint(true).Strikethrough(true).Reverse(true).Blink(true).
Underline(true).
UnderlineColor(lipgloss.Color("#FF0000")).
Foreground(lipgloss.Color("#FF0000")).
Background(lipgloss.Color("63")).
Width(40).Height(10).MaxWidth(80).MaxHeight(20).
Align(lipgloss.Center).
Padding(1, 2).PaddingChar('.').
Margin(1, 2).MarginBackground(c).
Border(lipgloss.RoundedBorder()).
BorderForeground(lipgloss.Color("63")).
Inline(true).
Transform(strings.ToUpper).
Hyperlink("https://example.com")
output := s.Render("text", "more")
Position constants: Left/Top (0.0), Center (0.5), Right/Bottom (1.0).
Padding/Margin shorthand follows CSS: 1 arg = all, 2 = vert/horiz, 3 = top/horiz/bottom, 4 = clockwise.
Underline styles: UnderlineNone, UnderlineSingle, UnderlineDouble, UnderlineCurly, UnderlineDotted, UnderlineDashed.
Inheritance: child.Inherit(parent) copies unset rules. Margins/padding are NOT inherited.
Copying: copy := style (value type). .Copy() is deprecated.
Getters/Unsetters: every property has Get*() and Unset*() variants. Key sizing getters: GetHorizontalFrameSize(), GetVerticalFrameSize() (border + margin + padding). See references/api-details.md.
Color
All implement image/color.Color.
lipgloss.Color("#FF0000")
lipgloss.Color("#F00")
lipgloss.Color("21")
lipgloss.Color("5")
lipgloss.Magenta
lipgloss.NoColor{}
lipgloss.RGBColor{R: 255}
lipgloss.ANSIColor(134)
Named ANSI 16: Black, Red, Green, Yellow, Blue, Magenta, Cyan, White, BrightBlack through BrightWhite.
Utilities: Darken(c, 0.5), Lighten(c, 0.35), Complementary(c), Alpha(c, 0.5), Blend1D(steps, colors...), Blend2D(w, h, angle, colors...).
Adaptive colors:
hasDark := lipgloss.HasDarkBackground(os.Stdin, os.Stdout)
ld := lipgloss.LightDark(hasDark)
fg := ld(lipgloss.Color("#333"), lipgloss.Color("#EEE"))
case tea.BackgroundColorMsg:
ld := lipgloss.LightDark(msg.IsDark())
complete := lipgloss.Complete(colorprofile.Detect(os.Stdout, os.Environ()))
c := complete(lipgloss.Color("1"), lipgloss.Color("124"), lipgloss.Color("#ff34ac"))
Border
s.Border(lipgloss.RoundedBorder())
s.Border(lipgloss.NormalBorder(), true, false)
s.BorderStyle(lipgloss.RoundedBorder()).BorderTop(true).BorderLeft(false)
s.BorderForeground(lipgloss.Color("63"))
s.BorderTopForeground(c).BorderBackground(c)
s.BorderForegroundBlend(c1, c2, c1)
If BorderStyle() is set without any side booleans, all 4 sides render. Setting any side explicitly means only those render.
Layout
lipgloss.JoinHorizontal(lipgloss.Top, a, b, c)
lipgloss.JoinVertical(lipgloss.Center, a, b)
lipgloss.Place(80, 30, lipgloss.Right, lipgloss.Bottom, content)
lipgloss.PlaceHorizontal(80, lipgloss.Center, content)
lipgloss.PlaceVertical(30, lipgloss.Bottom, content,
lipgloss.WithWhitespaceStyle(lipgloss.NewStyle().Background(c)),
lipgloss.WithWhitespaceChars("."),
)
w, h := lipgloss.Size(rendered)
a := lipgloss.NewLayer(content).X(4).Y(2).Z(1)
lipgloss.Compose(a, b).Render()
lipgloss.Wrap(text, 40, " ")
Table
import "charm.land/lipgloss/v2/table"
t := table.New().
Headers("NAME", "AGE").
Row("Alice", "30").
Rows([][]string{{"Bob", "25"}}...).
Border(lipgloss.RoundedBorder()).
BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("99"))).
BorderHeader(true).BorderColumn(true).BorderRow(false).
Width(60).Height(20).Wrap(true).
StyleFunc(func(row, col int) lipgloss.Style {
if row == table.HeaderRow {
return lipgloss.NewStyle().Bold(true).Align(lipgloss.Center)
}
return lipgloss.NewStyle().Padding(0, 1)
})
lipgloss.Println(t)
List
import "charm.land/lipgloss/v2/list"
l := list.New("A", "B", "C")
l := list.New("Fruits", list.New("Apple", "Banana"), "Veggies", list.New("Carrot"))
l.Enumerator(list.Arabic)
l.EnumeratorStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("99")).MarginRight(1))
l.ItemStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("212")))
l.ItemStyleFunc(func(items list.Items, i int) lipgloss.Style { ... })
l.Item("incremental").Offset(1, -1)
Tree
import "charm.land/lipgloss/v2/tree"
t := tree.Root("Project").
Child("src", tree.Root("cmd").Child("main.go")).
Child("README.md")
t.Enumerator(tree.RoundedEnumerator)
t.RootStyle(s).ItemStyle(s).EnumeratorStyle(s)
t.ItemStyleFunc(func(children tree.Children, i int) lipgloss.Style { ... })
t.Width(40).Hide(true)
Common Patterns
1. Styled card
func Card(title, body string, w int) string {
head := lipgloss.NewStyle().Bold(true).
Foreground(lipgloss.Color("#FAFAFA")).Background(lipgloss.Color("#7D56F4")).
Padding(0, 1).Width(w)
frame := lipgloss.NewStyle().Padding(1, 2).Width(w).
Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("#7D56F4"))
return lipgloss.JoinVertical(lipgloss.Left, head.Render(title), frame.Render(body))
}
2. Two-column layout
func Columns(left, right string, total int) string {
col := lipgloss.NewStyle().Width(total / 2).Padding(1, 2)
return lipgloss.JoinHorizontal(lipgloss.Top, col.Render(left), col.Render(right))
}
3. Adaptive theme
func NewTheme(hasDark bool) Theme {
ld := lipgloss.LightDark(hasDark)
return Theme{
Primary: ld(lipgloss.Color("#5A56E0"), lipgloss.Color("#7571F9")),
Subtle: ld(lipgloss.Color("#999"), lipgloss.Color("#666")),
}
}
4. Alternating-row table
t := table.New().Headers(headers...).Rows(rows...).
Border(lipgloss.RoundedBorder()).
BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("99"))).
StyleFunc(func(row, col int) lipgloss.Style {
base := lipgloss.NewStyle().Padding(0, 1)
if row == table.HeaderRow { return base.Bold(true) }
if row%2 == 0 { return base.Foreground(lipgloss.Color("245")) }
return base.Foreground(lipgloss.Color("241"))
})
Integration Patterns
Bubble Tea
func (m model) Init() tea.Cmd { return tea.RequestBackgroundColor }
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.BackgroundColorMsg:
m.styles = newStyles(msg.IsDark())
}
return m, nil
}
func (m model) View() string {
return m.styles.title.Render("My App")
}
Glamour (Markdown)
md, _ := glamour.Render(content, "dark")
frame := lipgloss.NewStyle().Border(lipgloss.RoundedBorder()).Padding(1, 2).Width(80)
lipgloss.Println(frame.Render(md))
Common Mistakes
fmt.Println instead of lipgloss.Println - no color downsampling. Always use lipgloss writers for standalone apps.
- Width includes padding and borders -
Width(40) is 40 total cells, not content width.
Color() is a function in v2 - returns color.Color, not a type literal.
Inherit() skips margins/padding - only text formatting and colors are inherited.
- v1/v2 import mixing - v2 is
charm.land/lipgloss/v2. Sub-packages: charm.land/lipgloss/v2/{table,list,tree}.
table.HeaderRow is -1 - not 0. Data rows start at 0.
- Border side defaults -
BorderStyle() alone renders all 4 sides. Setting any BorderTop/Right/Bottom/Left explicitly means only those render.
- Renderer usage -
*Renderer does not exist in v2. Remove all renderer references.
Checklist