Skip to content Skip to sidebar Skip to footer

Is It Possible To Render HTML Into Javascript Console?

I would like to render HTML from a console.(log/info/warn): console.html('

Hello!

'); would render… Hello! …into the console panel. Is it possible somehow?

Solution 1:

In 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");

Post a Comment for "Is It Possible To Render HTML Into Javascript Console?"