Ask coding questions

← Back to all posts
JS console colors
neodymium

Just wondering if there is a way to change the text color using console.log in the Javascript console.

Answered by mat1 [earned 5 cycles]
View Answer
Voters
JamesChan4
GAIKCHINGCHING
neodymium
Comments
hotnewtop
mat1

You can change the color of a console.log by adding %c to the beginning of your message and adding css as the second argument.
Example:

Please mark this comment as the answer if it helped. Thanks!

Pythonier

@mat1 I'm not sure that works.

mat1

@Pythonier It works, try it. (Doesn't work on the Repl.it terminal, though. Only in the browser terminal)
https://storage.googleapis.com/replit/images/1557092960512_e49e6239356ceb909f628b36d9d9b7db.pn

Pythonier

@mat1 I have tried.

Steven_The_GuyT

@mat1 Yeah, I don't think it works

mat1

@Pythonier Doesn't work on the Repl.it terminal, though. Only in the browser terminal
Press f12 and select console

Pythonier

@mat1 That makes sense.

eankeen

https://storage.googleapis.com/replit/images/1557090678120_1e113fe3651ba89f428d97dc41edfabe.pn
One of the most popular libraries to add colored text is called chalk.
However, it doesn't seem to be supported on replit at the moment. (see screenshot) :P

However
There is a way to do it.
Checkout this StackOverflow post. Basically, you can write something like this:

And have the output be red :)

I made a repl here if you want to check it out.

xdcoledabeast

how do you put in JS text or print I'm new to coding JS plz help

neodymium

@xdcoledabeast console.log("text");

TalesK

Its WORKS! :D
Repl.it supports colors in the terminal.
You can use my repl.it as example for usage:
https://repl.it/@TalesK/chalk-test

Thanks to @eankeen for usage demo!