promotion

Monday, February 23, 2015

Change console.log display(color/font/background color)

You can apply your own styling to log message, by prefixing the message with %c, and provide the css styles as second parameter to the log message. Here is the simple example:
console.log("%cThis is green color text", "color: green;");
Here is the output:
Bold text:
console.log("%cThis is green color text", "color: green;font-weight: bold;");
Background color:
console.log("%c Hello world ", "color: #FFFFFF;font-weight: bold;background-color: red;");
Multiple colors:
console.log("%c Hello world, %c Hello world ", "color: green;", "color: red;");

No comments:

Post a Comment