DEV Community

Dhairya Shah
Dhairya Shah

Posted on

How to style console.log();

I guess that your first code of JS was

console.log('Hello World')
Enter fullscreen mode Exit fullscreen mode

even, mine was the same 🤏
same

So, have you wondered about styling it? 🤔

nevermind...

I am going to take the Discord warning message into account as an example

Discord Console Warning Message

Discord warning msg

  • If you have ever opened developer tools in Discord, you will find this warning msg from Discord... Check it out right now if you haven't (and listennn, don't paste any malicious code there)
  • So let's recreate the same warning message
  • Write some necessary HTML to link a JS file to it
  • Create a JS file and name it whatever you want
  • Now follow the steps below
console.log(text, styling)
Enter fullscreen mode Exit fullscreen mode

When you style there will be two things you need to take note of.

  • text - Every text message starts with a prefix - %c; and it is a very important thing and without it, styling will not apply to the text
  • styling - Simple CSS

Let's head up to the code,

console.log('%cHold Up', 'color: #404EED; font-size: 60px; font-weight: bold;-webkit-text-stroke: 1px black;');
console.log("%cIf someone told you to copy/paste something here you have an 11/10 chance you're being scammed", "color: black; font-size: 18px;")
console.log("%cPasting anything in here could give attackers access to your Discord account.", "color: red; font-size: 18px; font-weight: bold;")
Enter fullscreen mode Exit fullscreen mode

So, found this simple? If not you can dive into comments to ask questions...

Why not share your styling to the console.log(), I am very excited to see yours

Make sure to subscribe to my YouTube Channel I regularly upload some amazing web development videos...

Your support gives me motivation 💪

Top comments (3)

Collapse
 
deepakjaiswal profile image
Sandeep

That's good👍

Collapse
 
dhairyashah profile image
Dhairya Shah

Thank you 🙂

Collapse
 
ironcladdev profile image
Conner Ow

Nice! I'll have to start using this!