Zack Macomber
Zack Macomber

Reputation: 6905

HTML textarea cuts off beginning new lines

An HTML text area works fine with new lines ("\n") when they're after any other content in the text area, whether it be whitespace characters like spaces or tabs ("\t") or not.

However, when text area content begins with a new line (for example, "\ntest"), that new line gets cut off on display.

Any ideas on what causes this/how to remedy it?

Upvotes: 0

Views: 288

Answers (1)

Aleksandr M
Aleksandr M

Reputation: 24396

This seems to be by the spec.

A single newline may be placed immediately after the start tag of pre and textarea elements. If the element's contents are intended to start with a newline, two consecutive newlines thus need to be included by the author.

Note that in the past there were some bugs in the various browsers regarding leading new lines in elements:

Upvotes: 1

Related Questions