InterviewHubPRO
Section Overview
Q431

Question 431 of 521

Part 7: Execution Context, Functional JS & V8 Engine (404 - 463)

83%
JavaScript Internals (521 Qs)•Part 7: Execution Context, Functional JS & V8 Engine (404 - 463)

How do style the console output using CSS?

You can add CSS styling to the console output using the CSS format content specifier %c. The console string message can be appended after the specifier and CSS style in another argument. Let's print the red color text using console.log and CSS specifier as below,

js
 console.log("%cThis is a red text", "color:red");

It is also possible to add more styles for the content. For example, the font-size can be modified for the above text

js
 console.log(
   "%cThis is a red text with bigger font",
   "color:red; font-size:20px"
 );