Charm Bracelet
Styling

Formatting

Lip Gloss supports ANSI text formatting and block-level styling for your terminal apps.

Format Your Terminal Output

Lip Gloss supports the usual ANSI text formatting options and block-level styling to create polished, structured terminal output. Whether you’re enhancing a CLI or a Bubble Tea TUI, Lip Gloss makes it easy to apply bold, italic, padding, margins, and more, with a CSS-like approach.

Combine formatting with Lip Gloss colors for vibrant, professional terminal apps.

Formatting Options

Lip Gloss offers a range of formatting techniques for text and layouts:

Apply ANSI text formatting options for styling individual text elements:

var style = lipgloss.NewStyle().
    Bold(true).
    Italic(true).
    Faint(true).
    Blink(true).
    Strikethrough(true).
    Underline(true).
    Reverse(true)

Use padding and margins to control spacing around text blocks:

// Padding
var style = lipgloss.NewStyle().
    PaddingTop(2).
    PaddingRight(4).
    PaddingBottom(2).
    PaddingLeft(4)

// Margins
var style = lipgloss.NewStyle().
    MarginTop(2).
    MarginRight(4).
    MarginBottom(2).
    MarginLeft(4)

Simplify padding and margins with CSS-like shorthand syntax:

// 2 cells on all sides
lipgloss.NewStyle().Padding(2)

// 2 cells on the top and bottom, 4 cells on the left and right
lipgloss.NewStyle().Margin(2, 4)

// 1 cell on the top, 4 cells on the sides, 2 cells on the bottom
lipgloss.NewStyle().Padding(1, 4, 2)

// Clockwise, starting from the top: 2 cells on the top, 4 on the right, 3 on the bottom, and 1 on the left
lipgloss.NewStyle().Margin(2, 4, 3, 1)

How It Works

Apply formatting to enhance your terminal output:

Choose Formatting Options

Select inline formatting (e.g., bold, italic) or block-level formatting (e.g., padding, margins) based on your design needs.

Apply Styles

Use lipgloss.NewStyle() to define formatting and apply it to text:

style := lipgloss.NewStyle().Bold(true).Padding(1, 2)
fmt.Println(style.Render("Styled text!"))

Use Shorthand Syntax

For concise padding and margins, use CSS-like shorthand (e.g., Padding(1, 2) for top/bottom and left/right).

Ensure your terminal supports ANSI formatting for features like bold or italic to render correctly. Modern terminals like iTerm2 or Alacritty are recommended.

How is this guide?