Can't figure out this one.
Text I enter into my textarea, doesn't break the lines.

CSS:

#description{ 
	float:right;
	font-size:12px;
	padding:4px 2px;
	border:solid 1px #afd45a;
	width:260px;
	height: 90px;
	margin:0px 20px 20px 6px;
}

HTML:

<input type="textarea" name="description" id="description" rows = "4" cols = "25"/>

Dani AI

Generated

As corrected for , the immediate editing problem was resolved by using the proper multi-line control. A few follow-up notes that help when line breaks still disappear later (for example, when you save text and then render it on a page):

CSS approach (no HTML changes, preserves user newlines)

.preserve-lines {
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

Use that class on the element that displays the saved text. The white-space property keeps newline characters while still allowing wrapping; see white-space on MDN.

Convert-newlines approach (explicit HTML)

// PHP: escape then convert newlines
echo nl2br(htmlspecialchars($text, ENT_QUOTES, 'UTF-8'));
// JS: escape then replace newlines before assigning innerHTML
function escapeHtml(s){
  return s.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
}
output.innerHTML = escapeHtml(text).replace(/\n/g,'<br/>');

Quick troubleshooting checklist:

  • Confirm a true multi-line control was used (see above and textarea on MDN).
  • Check styles that force white-space: nowrap or pre on the display element.
  • Verify server-side code does not strip or normalize newlines.
  • Always escape user text before converting to HTML to avoid XSS (see htmlspecialchars and nl2br on PHP.net).

Welcome notes from show this thread still helps others — these tips cover common post-entry rendering issues.

Recommended Answers

All 3 Replies

<textarea name="qwerty" rows = "4" cols = "25">
</textarea>

Absolutely worked!
Thank you!

This is a smart forum..
hey just googled for Textarea line break and found this forum..
hope i will like this place.. thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.