Colors in JavaScript console

前端 未结 27 2677
说谎
说谎 2020-11-22 11:42

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?

27条回答
  •  面向向阳花
    2020-11-22 12:04

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

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

    Console color example in Chrome

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

    References

    • MDN: Styling console output
    • Chrome: Console API Reference

提交回复
热议问题