Home > database >  how to force a line break inside a textarea?
how to force a line break inside a textarea?

Time:07-02

I want to force a line break inside the textarea like this <textarea>hello!\nbye<br>hello again\r\n i'm here</textarea> but this way the page only shows like this: hello!\nbye<br>hello again\r\n i'm here and it should appear something like:

bye
hello again
I'm here

it's something like &nbsp? which element should i use to make this line break?

CodePudding user response:

A literal new line.

<textarea>bye
hello again
I'm here</textarea>

CodePudding user response:

<!DOCTYPE html>
<html>
  <head>
    <title>Hello, World!</title>
    <link rel="stylesheet" href="styles.css" />
  </head>
  <body>
      <textarea id="message">Hello</textarea>
    
    <script type="text/javascript" charset="utf-8">
      const message = document.getElementById('message');

message.value = 'bye'   '\r\n'   'hello again'   '\r\n'   'Im here';

console.log(message.value);
    </script>
  
  </body>
</html>
  • Related