Skip to content
← Back to Community
how do i put color in my text?
Profile icon
adsarebbbad

i searched it up but none of the results worked. please help me figure out how to color my text. i put a random repl because i just wanted to figure out

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
dabs364
Profile icon
adsarebbbad
Comments
hotnewtop
Profile icon
Coder100

Hello, I have put most of the commonly-used colors (escape codes) inside here. They are inside an object as to not pollute the global scope.

const colors = { reset: "\x1b[0m", bold: "\x1b[1m", italic: "\x1b[3m", underline: "\x1b[4m", inverse: "\x1b[7m", black: "\x1b[30m", red: "\x1b[31m", green: "\x1b[32m", yellow: "\x1b[33m", blue: "\x1b[34m", magenta: "\x1b[35m", cyan: "\x1b[36m", white: "\x1b[37m", gray: "\x1b[90m", bright_red: "\x1b[91m", bright_green: "\x1b[92m", bright_yellow: "\x1b[93m", bright_blue: "\x1b[94m", bright_magenta: "\x1b[95m", bright_cyan: "\x1b[96m", bright_white: "\x1b[97m", bg_black: "\x1b[40m", bg_red: "\x1b[41m", bg_green: "\x1b[42m", bg_yellow: "\x1b[43m", bg_blue: "\x1b[44m", bg_magenta: "\x1b[45m", bg_cyan: "\x1b[46m", bg_white: "\x1b[47m", bg_gray: "\x1b[100m", bg_bright_red: "\x1b[101m", bg_bright_green: "\x1b[102m", bg_bright_yellow: "\x1b[103m", bg_bright_blue: "\x1b[104m", bg_bright_magenta: "\x1b[105m", bg_bright_cyan: "\x1b[106m", bg_bright_white: "\x1b[107m" }; print(`${colors.red}Red Text${colors.reset} ${colors.bg_blue}text with blue background${colors.reset} normal text`)

You can check out the wikipedia page for more information!

Profile icon
EpicGamer007

Text in the console? you could put ansi escape codes.

Profile icon
adsarebbbad

can you gave an example? @AbhayBhat

Profile icon
EpicGamer007

@adsarebbbad, ummm, which language are you gonna use?

Profile icon
adsarebbbad

JavaScript @AbhayBhat

Profile icon
EpicGamer007

@adsarebbbad, ok Try these links:

https://stackoverflow.com/questions/7505623/colors-in-javascript-console

https://coderwall.com/p/yphywg/printing-colorful-text-in-terminal-when-run-node-js-script

If it was another language, you could have used ansi escape code but you cannot for js.(i think)

Profile icon
adsarebbbad

im looking for colored text that works in replit @AbhayBhat

Profile icon
adsarebbbad

those dont work in replit @AbhayBhat

Profile icon
EpicGamer007

@adsarebbbad , ok srry :(

Profile icon
QuentinRedden

Actually these do in fact work on replit as i have tried. implementation is as such:

syntax: cout << " txt " << endl;,[object Object], cout << "\x1b[36mHello There!" << endl;

,[object Object], ,[object Object], ,[object Object], ,[object Object]