Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
communitycreator

How to make console.log text colorful in JavaScript

Chibuike Nwachukwu

In programming, logging has always been a useful tool for debugging purposes, as well as to make hints and suggestions. Adding color to logging can make it more effective. However, the default console.log in JavaScript doesn’t come with a color display.

Here, we will learn how to implement color displays in the console without using any package or external tool.

Syntax

console.log('message goes here');

Example

Let’s demonstrate the use of a console.log by styling the message that would be displayed:

console.log("%c Welcome to Educative.io", "background: red; color: white; padding: 5px;")

Output

widget

Example with multiple styles

We can also have multiple styles applied to a single console.log statement:

console.log("%c Welcome to Educative.io %c You are reading Edpresso shots","background: red; color: white; padding: 5px;", "background: green; color: white; padding: 5px;")

Output

With multiple styles
With multiple styles

RELATED TAGS

javascript
communitycreator
RELATED COURSES

View all Courses

Keep Exploring