colors ={reset:'33[0m',//text colorblack:'33[30m',red:'33[31m',green:'33[32m',yellow:'33[33m',blue:'33[34m',magenta:'33[35m',cyan:'33[36m',white:'33[37m',//background colorblackBg:'33[40m',redBg:'33[41m',greenBg:'33[42m',yellowBg:'33[43m',blueBg:'33[44m',magentaBg:'33[45m',cyanBg:'33[46m',whiteBg:'33[47m'}console.log('33[31m this is red color on text');console.log('33[0m this is reset');console.log('33[41m this is red color on background');
how to change the color of a console.log in javascript
// Download the npm package "colors"// npm i colorsvar colors =require("colors");console.log("Hello World".blue);// output: Hello World (Its blue btw lmao)
const styles =['color: green','background: yellow'].join(';');const message ='Some Important Message Here';// 3. Using the styles and message variableconsole.log('%c%s', styles, message);
// 1. Pass the css styles in an arrayconst styles =['color: green','background: yellow','font-size: 30px','border: 1px solid red','text-shadow: 2px 2px black','padding: 10px',].join(';');// 2. Concatenate the individual array item and concatenate them into a string separated by a semi-colon (;)// 3. Pass the styles variableconsole.log('%cHello There', styles);