Course contentsShow
← Web Development
Lesson 2251 of 2,98241. Debugging TechniquesFree lesson

String Substitution and Styling

Use format specifiers and CSS styles in console messages to highlight important information.

String Substitution and Styling

You'll learn how to use format specifiers and CSS styles in console messages to make critical debugging information stand out visually.

When debugging complex applications, not all console output deserves equal attention. Just as a highlighter pen draws your eye to key passages in a textbook, styling your console messages helps you instantly spot the information that matters most amid hundreds of log entries.

Format Specifiers for String Substitution

You've already seen console.log() for basic output. Now you can use format specifiers — special placeholders that get replaced with values you provide:

const userName = "Alice";
const loginCount = 42;

console.log("User: %s, Logins: %d", userName, loginCount);
// Output: User: Alice, Logins: 42

Common specifiers:

  • %s for strings
  • %d or %i for integers
  • %f for floats
  • %o for objects
  • %c for CSS styling (the powerful one!)

Adding CSS Styles

The %c specifier lets you apply CSS directly to console text. Everything after %c gets styled by the CSS string you provide as the next argument:

console.log("%cCRITICAL ERROR", "color: red; font-weight: bold; font-size: 16px;");

console.log(
  "%cSuccess: %cData loaded",
  "color: green; font-weight: bold;",
  "color: gray; font-style: italic;"
);

You can use multiple %c markers to style different parts of the same message differently — perfect for creating visual hierarchies like highlighting variable names in one color and their values in another.

Key Takeaway: Use %c format specifiers with CSS strings to add colors, fonts, and emphasis to console messages, making critical debugging information instantly recognizable in crowded console output.