Skip to content

Instantly share code, notes, and snippets.

@leommoore
Last active January 28, 2024 10:29
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save leommoore/4526808 to your computer and use it in GitHub Desktop.
Save leommoore/4526808 to your computer and use it in GitHub Desktop.
JavaScript - ANSI Escape Codes

JavaScript - ANSI Escape Codes

ANSI Escape Codes are special characters which can be used to control formatting, colors or other output preferences in a text terminal. Escape Codes are non-printing code and will not appear in the output directly.

  • \033 begins the escape sequence
  • [ indicates the color
  • 33 is the foreground color for yellow
  • m indicates the end of the setting

Note: \033[39m is used set the color back to the terminal defult

console.log('\033[33m Hello World \033[39m');

This will give a nice yellow color Hello World.

The complete table of ANSI Escape Codes is available at http://en.wikipedia.org/wiki/ANSI_escape_code

@adsarebbbest
Copy link

thanks

@adsarebbbest
Copy link

thanks

@ThePotatoChronicler
Copy link

This is very simplified, check out this blog post for a little more detail and this wikipedia article for a lot more detail

@Nomkid
Copy link

Nomkid commented Jan 18, 2021

thanks

@Oderjunkie
Copy link

thanks

@aggregate1166877
Copy link

This does not work in strict mode.

Use console.log('\x1b[33m Hello World\x1b[39m'); instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment