# Newline characters not working

**URL:** <https://forum.code.org/t/newline-characters-not-working/14735>\
**Category:** Unit and Lesson Discussion\
**Tags:** csp-unit-5, csp-unit-5-lesson-6\
**Created:** [February 27, 2018, 11:33pm UTC](https://forum.code.org/t/newline-characters-not-working/14735 "2018-02-27T23:33:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![asalas](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@asalas](https://forum.code.org/u/asalas)\
**Post date:** [February 27, 2018, 11:33pm UTC](https://forum.code.org/t/newline-characters-not-working/14735/1 "2018-02-27T23:33:34Z")

</div>

Hi, is anyone else experiencing the newline characters “\n” not working? I have several kids where this is happening, and I can’t find any problems with their code.

Thanks!

---

<div class="post-metadata">

**Author:** ![asalas](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@asalas](https://forum.code.org/u/asalas)\
**Post date:** [February 27, 2018, 11:40pm UTC](https://forum.code.org/t/newline-characters-not-working/14735/2 "2018-02-27T23:40:33Z")

</div>

Nevermind. I figured out the problem. The kids MUST create a text area box first.  
The newline character doesn’t format onto the background.

---

<div class="post-metadata">

**Author:** ![dzulkiewski](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/dzulkiewski/32/84_2.png) [@dzulkiewski](https://forum.code.org/u/dzulkiewski)\
**Post date:** [February 28, 2018, 2:50pm UTC](https://forum.code.org/t/newline-characters-not-working/14735/3 "2018-02-28T14:50:35Z")

</div>

We are having problems with the new line characters. We either receive an error in the cosole.log or the message prints /n

Any help you can provide is appreciated?

---

<div class="post-metadata">

**Author:** ![baker](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/baker/32/1229_2.png) [@baker](https://forum.code.org/u/baker)\
**Post date:** [February 28, 2018, 3:43pm UTC](https://forum.code.org/t/newline-characters-not-working/14735/4 "2018-02-28T15:43:52Z")

</div>

I wonder if the issue is forward slash v. backslash?

In your message above you are using a forward slash `/`. The character for newline requires a backslash `\`

Test it out: this statement should display `foo` on 3 separate lines the console.

`console.log("foo\nfoo\nfoo");`

---

<div class="post-metadata">

**Author:** ![asalas](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@asalas](https://forum.code.org/u/asalas)\
**Post date:** [February 28, 2018, 6:41pm UTC](https://forum.code.org/t/newline-characters-not-working/14735/5 "2018-02-28T18:41:01Z")

</div>

Hi DZulkiewski,

I’m sure Baker’s answer fixed your problem. But just also letting you know that if the kids don’t actually drag a ‘text area’ element onto the background to set the text to, the newline characters won’t work. In other words, we found that newline characters don’t work when setting text directly to the app screen.

---

<div class="post-metadata">

**Author:** ![squible](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@squible](https://forum.code.org/u/squible)\
**Post date:** [February 18, 2019, 11:03pm UTC](https://forum.code.org/t/newline-characters-not-working/14735/6 "2019-02-18T23:03:30Z")

</div>

It didn’t work for my students unless they used single quote marks and “added” it to the lines of text:  
Example: + ‘\n’ +  
It NEVER worked without quotes, and it didn’t work with double quotes as shown in the reading.

---

<div class="post-metadata">

**Author:** ![zsawyer](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/zsawyer/32/4302_2.png) [@zsawyer](https://forum.code.org/u/zsawyer)\
**Post date:** [February 27, 2019, 3:50pm UTC](https://forum.code.org/t/newline-characters-not-working/14735/7 "2019-02-27T15:50:51Z")

</div>

Some students drag in a textInput instead of a textArea. newline does not work with the textInput element.

My students were able to recreate the issue. Some used a textInput element and dragged its size to make it look like a textArea.

This was not caught initially by me because it looked like a textArea, and I did not ask them to go to the design tab to check,

---

<div class="post-metadata">

**Author:** ![kaitie\_o\_bryan](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/kaitie_o_bryan/32/2278_2.png) [@kaitie\_o\_bryan](https://forum.code.org/u/kaitie_o_bryan)\
**Post date:** [February 28, 2019, 4:49am UTC](https://forum.code.org/t/newline-characters-not-working/14735/8 "2019-02-28T04:49:55Z")

</div>

@zsawyer thanks for bringing that up! That is a frequent “miss” by me as well!

---

<div class="post-metadata">

**Author:** ![mcaulfield](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mcaulfield](https://forum.code.org/u/mcaulfield)\
**Post date:** [March 19, 2019, 6:37pm UTC](https://forum.code.org/t/newline-characters-not-working/14735/9 "2019-03-19T18:37:18Z")

</div>

@zsawyer

I came here with the same error that a few of my students were making, and your fix worked. Thanks!

---

<div class="post-metadata">

**Author:** ![jpnelson](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jpnelson](https://forum.code.org/u/jpnelson)\
**Post date:** [December 13, 2023, 9:28pm UTC](https://forum.code.org/t/newline-characters-not-working/14735/10 "2023-12-13T21:28:55Z")

</div>

I am dragging the text area into a phone app screen, and \n does not work to create a new line, and there is to “wrap” feature on the text area. Any help? From [code.org](http://code.org), hopefully?

---

<div class="post-metadata">

**Author:** ![madeline\_r\_burton](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/madeline_r_burton/32/5037_2.png) [@madeline\_r\_burton](https://forum.code.org/u/madeline_r_burton)\
**Post date:** [December 14, 2023, 2:15am UTC](https://forum.code.org/t/newline-characters-not-working/14735/11 "2023-12-14T02:15:19Z")

</div>

Would you please provide a sample app demonstrating the problem so we can see the context and the code? I personally am not seeing this issue.

---

<div class="post-metadata">

**Author:** ![jpnelson](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jpnelson](https://forum.code.org/u/jpnelson)\
**Post date:** [December 14, 2023, 3:09pm UTC](https://forum.code.org/t/newline-characters-not-working/14735/12 "2023-12-14T15:09:33Z")

</div>

It’s a problem that seems to only happen sometimes - happened to one of my students, and happened to me, but I found a fix. I got this code in this [code.org](http://code.org) questions section, and it fixed it for me and the student.  
setStyle(“ta”, “white-space: pre; overflow-wrap: normal;”);  
setText(“ta”, “a very very very very very\nvery very very very very\nvery very very very very\nvery very very very very\nvery long line of text”);  
The long text line was correctly placed on newlines, while previously it just horizontally went off the screen. Thanks.
