I 'waddled' by the Console in Chrome on Facebook today.
Surprisingly I got this message in the console.
Now my question is:
How is this possible?
I know that there are a few 'exploit' methods for the console, but how can you make such font formatting in the console? (and is it console.log?)
log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user. Syntax: console. log(A);
Yes, you can format the console.log()
with something like this:
console.log("%cExtra Large Yellow Text with Red Background", "background: red; color: yellow; font-size: x-large");
Note the %c
preceding the text in the first argument and the style specifications in the second argument. The text will look like your example.
See Google's "Styling Console Output with CSS" or FireBug's Console Documentation for more details.
The documentation links also include some other neat tricks like including object links in a console log as well.
Try this:
console.log("%cThis will be formatted with blue text", "color: blue");
Quoting the docs,
You use the %c format specifier to apply custom CSS rules to any string you write to the Console with console.log() or related methods.
Source: https://developers.google.com/web/tools/chrome-devtools/console/console-write#styling_console_output_with_css
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With