Home > Article > Web Front-end > How Can I Add Color to My JavaScript Console Output?
In modern web browsers like Chrome and Firefox, it's possible to add styling to the text displayed in the JavaScript console. This can be useful for visually differentiating different types of messages, such as errors, warnings, and regular console.log() calls.
To style console output, you can use the following syntax:
console.log('%c Styled Text', 'color: #color-code; background: #background-color-code');
For example, to display errors in red, warnings in orange, and console.log() outputs in green, you can use the following code:
console.log('%c Error message', 'color: #ff0000; background: #ff9999'); console.log('%c Warning message', 'color: #ff9900; background: #ffdd99'); console.log('%c Regular message', 'color: #008000; background: #99ff99');
This will output the following colored text in the console:
The above is the detailed content of How Can I Add Color to My JavaScript Console Output?. For more information, please follow other related articles on the PHP Chinese website!