How to provide new line in JavaScript alert box?

To add a new line in JavaScript alert box, use the "
" escape character:

Syntax

alert("First line\nSecond line");

Basic Example



    


    


Multiple Line Breaks

You can use multiple "
" characters to create larger spacing between lines:



    


    


Practical Use Cases

Common scenarios where multi-line alerts are useful:



    


    
    


Key Points

  • Use "
    " to create line breaks in alert messages
  • Multiple "
    " characters create larger gaps between lines
  • Works consistently across all browsers
  • Useful for error messages, instructions, and formatted text

Conclusion

The "
" escape character is the standard way to add line breaks in JavaScript alert boxes. Use it to create more readable and organized alert messages for better user experience.

Updated on: 2026-03-15T22:08:37+05:30

812 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements