ANSI Strikethrough Text - Escape Code 9 for Crossed-Out Text
Create strikethrough (crossed-out) text in the terminal using ANSI escape code 9. Useful for showing deprecated items, removed content, or completed tasks in CLI output.
Detailed Explanation
Strikethrough Text with ANSI Code 9
Strikethrough (also called "crossed-out") draws a horizontal line through the middle of text. It is activated with SGR code 9 and reset with code 29.
Basic Usage
# Bash
echo -e "\033[9mThis text is struck through\033[0m"
# Python
print("\033[9mThis text is struck through\033[0m")
# Node.js
console.log("\x1b[9mThis text is struck through\x1b[0m");
Practical Examples
# Showing before/after in a migration
echo -e "Config changes:"
echo -e " \033[9;31m- old_setting: true\033[0m"
echo -e " \033[32m+ new_setting: false\033[0m"
# Todo list with completed items
echo -e "Tasks:"
echo -e " \033[9;90m[x] Set up database\033[0m"
echo -e " \033[9;90m[x] Write API routes\033[0m"
echo -e " [ ] Deploy to production"
# Deprecated API notice
echo -e "\033[33mWarning:\033[0m \033[9mgetUser()\033[0m is deprecated. Use \033[1mfetchUser()\033[0m instead."
Combining with Other Styles
# Strikethrough + dim (very subtle)
echo -e "\033[9;2mBarel visible struck text\033[0m"
# Strikethrough + red (deleted)
echo -e "\033[9;31mDeleted line\033[0m"
# Strikethrough + color + replacement
echo -e "Price: \033[9;31m$99\033[0m \033[1;32m$49\033[0m"
Terminal Support
Strikethrough is supported in most modern terminals including iTerm2, GNOME Terminal, Konsole, Windows Terminal, Alacritty, and Kitty. Some older terminals may not render it, but the text content remains visible even without the visual effect.
Reset Code
Use code 29 to reset only strikethrough while keeping other formatting:
echo -e "\033[9;1mBold struck\033[29m Bold only\033[0m"
Use Case
Strikethrough text is used for showing removed or deprecated items in diff output, completed items in task lists, old values being replaced by new ones (e.g., price changes), and deprecated API method names. It provides a visual cue that something has been superseded or is no longer relevant.