Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 174633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:33:26+00:00 2026-05-11T13:33:26+00:00

EDIT: After re-reading my post I think I am being a little bit unclear

  • 0

EDIT: After re-reading my post I think I am being a little bit unclear about what the problem is. Let me try to re-phrase it:

Users can leave comments on my site using a textarea field in a form. It should be possible to add line breaks in the comment using <br />. The comment is then stored as a string in a mysql-database (escaped to make it safe) and later on retrieved from the database and displayed on the site. Regular line breaks are not recognized when the comment is displayed.

Users can edit their comments, and in that case the original comment is displayed in a textarea field to be modified (see image below). The problem is that if there are any <br /> present, the code is not valid as XHTML 1.0 (see error message below).

Can I make the code valid using any other type of line break? As stated in the comments, regular line breaks in combination with xml:space="preserve" does not work (line breaks are displayed in the textarea field, but not when the comment is displayed as normal text on the site).


Original question:

I have a web-form which includes a textarea field to leave comments, and I want it to be able to add line breaks using <br />. Below is a simple example:

screen dump
(source: shipit.se)

It works as intended, however it does not validate as XHTML 1.0 transitional when using the W3C validation service. This is the error I get:

  1. Error Line 90, Column 1587: document type does not allow element "br" here

…ription" rows="0" cols="0">Test<br />line break</textarea></dd><dt class="cha

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements — such as a "style" element in the "body" section instead of inside "head" — or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML’s rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML’s "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).

Is there a way to make the line breaks valid code, or do I need to find a workaround (like e.g. using specific tags for line breaks in the textarea field and then replacing them with <br /> later on when displaying the comment)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:33:27+00:00Added an answer on May 11, 2026 at 1:33 pm

    From the DTD:

    <!ELEMENT TEXTAREA - - (#PCDATA) -- multi-line text field -->

    In the XHTML code of your page, a <textarea> can only contain text (#PCDATA), and you cannot nest any XHTML elements within the <textarea>.

    Your questions seems to show two different things. The image shows ‘<br />‘ written into a <textarea>, while the message from the W3C Validator is referring to a <br /> element written into the XHTML of your page within the <textarea> element.

    In the first case, having ‘Test<br />line break‘ appear to the user in the text area is done by using the appropriate entities, just as altCognito wrote:

    <textarea>Test&lt;br /&gt;line break</textarea> 

    Anything that’s being entered by the user that is then redisplayed within a <textarea> on a new page should be encoded (i.e., use entities for &, ', ', <, and >).

    If want to display a user’s entry:

    Test<br />line break

    …as…

    Test
    line break

    …within another text area, then you will need to parse what has been entered into the original <textarea> and replace the user-entered <br />s with normal line breaks. See Lucero’s answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: Prepare my objects for the use within a HashMap. after reading a bit
EDIT: This post was originally specific to ASP.NET, but after thinking about it I'm
I stumbled across BCrypt.net after reading Jeff Atwood's post about storing passwords which led
EDIT: after reading all the input from the other users, i decided, to use
EDIT 1 I apologize but after reading the 2 suggested articles I still don't
After reading the famous (and only) article about trying to explain why asmxs should
-Edit after closing- I try to install ruby 3 to a Server and that
After reading this post and some derivative publications (ddotdash.com) I wonder whether it is
Recently, I've got a dangerous idea into my head after reading this blog post.
EDIT: after reading this http://projects.scipy.org/numpy/ticket/1322 it seems that the NumPy version I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.