0

I'm trying to help my colleagues by creating usefull and easy to read console messages. Therefore I dived into colorizing them based on how important the information is I want to convey. I got the basics already, like colorizing the whole line with

console.log('%cThis will be red', 'color: red')

But I wanted to take things one step further and highlight specific words with different colors. But I can't find a way colorize only a single word, without affecting the rest of the sentence.

I know about

console.log('%cThis will be red, %cbut this will be blue', 'color: red', 'color: blue')

but I want to just colorize a single keyword. Is it possible to reset the color at a specific position in the string? Can I scope the css to a specific part of the string?

Alexander Moser
  • 397
  • 3
  • 16
  • I think the answer on this page is what you need. https://stackoverflow.com/questions/7505623/colors-in-javascript-console – Jón Ólafsson Jun 05 '19 at 10:13
  • Can you maybe tell me where? I already looked through that question many times but couldn't find an answer to my specific problem of stylizing a specific party of my string. Maybe I just overlooked it... – Alexander Moser Jun 05 '19 at 10:31
  • you can use third-party library like chalk https://github.com/chalk/chalk – Hachimi Ahmed Amine Jun 05 '19 at 12:07

0 Answers0