<lightning:textarea value="line 1 \r \n line 2" label="" maxlength="300" /></td></tr>

How can I change the value to have different lines so that 'line 1' has its own line and 'line 2' is on its own line. Currently it looks like

enter image description here


1 Answer 1


Just put in multiple lines like this:I have used enter key in between line 1,2 and 3

<lightning:textarea value="line 1
                           line 2
                           line 3" label="" maxlength="300" />

for setting through javascript just add "\n"

var valz = "123"+"\n"+"456";

bind this attribute to textarea component

  • Oh I didn't expect that to work! Neat! What if the value is stored in an attribute though? How can I save the attribute value with the enter value if it's saved through the apex controller.
    – Peter Luo
    Nov 20, 2019 at 19:45
  • @PeterLuo, added code for attribute setting through javascript
    – RedDevil
    Nov 20, 2019 at 20:06
  • Thank you, I think my problem was I was trying to put the "\n" directly into the value parameter but I saved the value in my controller and it worked.
    – Peter Luo
    Nov 21, 2019 at 15:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.