Combining ANSI Styles - Multiple Codes in One Sequence

Combine multiple ANSI escape codes for bold colored underlined text. Learn semicolon-separated SGR parameters and the correct order for combining formatting attributes.

Practical Usage

Detailed Explanation

Combining Multiple ANSI Styles

ANSI SGR parameters can be combined by separating codes with semicolons within a single escape sequence. This lets you apply multiple formatting attributes simultaneously.

Syntax

\033[code1;code2;code3m

Common Combinations

# Bold + Red
echo -e "\033[1;31mBold Red\033[0m"

# Bold + Underline + Blue
echo -e "\033[1;4;34mBold Underlined Blue\033[0m"

# Italic + Green + Yellow Background
echo -e "\033[3;32;43mItalic Green on Yellow\033[0m"

# Bold + Underline + Strikethrough + Magenta
echo -e "\033[1;4;9;35mAll the styles\033[0m"

Order of Codes

The order of SGR codes within a sequence generally does not matter, but convention is:

  1. Formatting attributes (bold, italic, underline): 1, 2, 3, 4, 9
  2. Foreground color: 30-37, 90-97, or 38;5;N / 38;2;R;G;B
  3. Background color: 40-47, 100-107, or 48;5;N / 48;2;R;G;B

Stacking Sequences

You can also apply attributes incrementally with separate sequences:

# These produce the same result:
echo -e "\033[1;31;4mCombined\033[0m"
echo -e "\033[1m\033[31m\033[4mStacked\033[0m"

Partial Resets

Reset individual attributes while keeping others:

# Bold + underline + red, then remove underline only
echo -e "\033[1;4;31mBold underline red \033[24mBold red only\033[0m"

# Bold + italic + cyan, then remove bold only
echo -e "\033[1;3;36mBold italic cyan \033[22mItalic cyan only\033[0m"

256-Color Combinations

# Bold + 256-color foreground + 256-color background
echo -e "\033[1;38;5;208;48;5;17mBold orange on navy\033[0m"

True Color Combinations

# Underline + true color foreground + true color background
echo -e "\033[4;38;2;255;200;0;48;2;0;0;100mUnderline gold on navy\033[0m"

Practical Pattern

# Status line with multiple styles
printf "\033[1;97;44m STATUS \033[0m \033[32m%s\033[0m\n" "All systems operational"

Use Case

Combining styles is essential for creating visually rich CLI interfaces. Use it for status badges (bold white text on colored backgrounds), table headers (bold underlined), deprecation notices (strikethrough with dim), clickable-looking links (underlined cyan), and any terminal UI that needs visual hierarchy beyond simple color.

Try It — ANSI Color Code Reference

Open full tool