I would like to render HTML from a console.(log/info/warn):
console.html("<h1>Hello!</h1>");
would render…
Hello!
…into the console panel. Is it possible somehow?
ps.: for the record, I would like to have more coloring options than log/info/warn/error messages.
I would like to render HTML from a console.(log/info/warn):
console.html("<h1>Hello!</h1>");
would render…
Hello!
…into the console panel. Is it possible somehow?
ps.: for the record, I would like to have more coloring options than log/info/warn/error messages.
Share Improve this question asked Mar 22, 2016 at 19:57 blagusblagus 2,3554 gold badges21 silver badges22 bronze badges 3- 1 why dont you use console.log(document.body); – Rajat Bhadauria Commented Mar 22, 2016 at 20:02
- Is console.html exist even ? – Rajat Bhadauria Commented Mar 22, 2016 at 20:05
- you can also use console.table to render an array or array of objects: developer.mozilla/en-US/docs/Web/API/Console/table – Clay Commented Mar 25, 2021 at 19:06
1 Answer
Reset to default 18In a way it's possible using the CSS format specifier.
Example:
console.log("%cThis will be formatted with large, blue text", "color: blue; font-size: x-large");
The CSS format specifier allows you to customize the display in the console. Start the string with the specifier and give the style you wish to apply as the second parameter.
This feature is supported by all main browser developer tools. See the reference for the Chrome DevTools, the one for the Firefox DevTools or the one for Firebug.
So while you can't use HTML per se, you can style whatever text you want using CSS to mimic many HTML elements:
console.log("%cHello!", "font-size: 3em");