HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptCritical

Colors in JavaScript console

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
consolejavascriptcolors

Problem

Can Chrome's built-in JavaScript console display colors?

I want errors in red, warnings in orange and console.log's in green. Is that possible?

Solution

In Chrome & Firefox (+31) you can add CSS in console.log messages:



console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');



The same can be applied for adding multiple CSS to same command.

References

  • MDN: Styling console output



  • Chrome: Console API Reference



  • WebKit: Console Object API

Context

Stack Overflow Q#7505623, score: 1891

Revisions (0)

No revisions yet.