Home >Web Front-end >JS Tutorial >Can You Colorize JavaScript Console Output in Chrome?
Colorizing Console Output in JavaScript
Can you enhance the JavaScript console in Chrome to display errors in red, warnings in orange, and console.log messages in green? Is this customization feasible?
Answer:
Chrome and Firefox (version 31 ) present a solution: you can incorporate CSS into console.log messages. Here's how:
console.log('%c Oh my heavens! ', 'background: #222; color: #bada55');
This approach utilizes CSS syntax within the console.log statement to control the appearance of the logged message. Specifically, the 'background' property defines the background color and the 'color' property sets the text color.
The above is the detailed content of Can You Colorize JavaScript Console Output in Chrome?. For more information, please follow other related articles on the PHP Chinese website!