Create a stylized console message and say hello to your fellow developers.
Let's get started
First you should know that a console message, which is the first argument of a console.log
, can be formatted using other arguments.
console.log("I'm the message");
There are different ways to format a console message but the only one that is useful in this specific case is the %c
formatter.
console.log("%cI'm the message");
%c
applies to the console message CSS rules that are defined by the second argument.
console.log("%cI'm the message", "background: red;");
And that's already all you need to know to create your own console signature.
Example
var consoleSignatureStyle = "font-size: 16px;" +
"background: linear-gradient(to right, #e66465, #9198e5);" +
"color: white;" +
"text-align: center;" +
"padding: 10px 15px;" +
"width: 100%;" +
"border-radius: 20px;";
var consoleSignatureText = "%cDon't steal my cookies! 🍪";
console.log(consoleSignatureText, consoleSignatureStyle);
Note: It is also possible to print images into the console by using the background-image
CSS property.
Top comments (16)
This is a cool gimmick, but the console is meant for debugging and utility. Keep the fancy in the web page please.
I have to disagree. I've seen a lot of useful examples of fancy console logs:
Yup. Anything that can be programmed will be programmed. The console is something web devs are allowed to code against, so you sort of have to accept that they'll want to do so with the full extent of their creativity, regardless of the main intent of the feature.
LOL. True.
You have some good points. But they should still be an exception. This just reminds me of the days of blinking status bar and title bar text. :o)
I do not see why the fancy can’t help with debugging and utility and still be fancy and fun.
I'd probably use something like this for Easter eggs
I like using console.table([1, 2, 3]) to group related values.
Great Tips. especially for Hiring New developers just like Medium did 😀
How did you set this cookie icon?
Hi Luis, the cookie is an emoji.
Chrome supports emojis since version 41.
Here is a list of all supported emojis.
Thanks ;)
This is fun. I'll use it to make important debugging messages pop but also as you described. No harm and plenty of fun.
Haha
That's funny
Going to implement that om my portfolio
this be useful by using different colors for each section of your code, for example, red for the API query code, blue for the animations
It's funny, thank you