I've started it all using a combination of \r
and \n
as below, with no success:
<textarea rows="10" readonly><?php echo 'First line.\r\nSecond line.'; ?></textarea>
Using a successive combination of
and
, I was able to achieve my aim across browsers, but get this HTML5 validation error when validating with the w3 Validator:
Error: A numeric character reference expanded to carriage return.
On the other hand, using a regular return in the <textarea>
and applying the CSS rule below, I get no validation error; the challenge with this approach is that it is not cross-browser compatible (not supported particularly by Internet Explorer nor Edge).
textarea {
white-space: pre-line;
}
Below is the content of my <textarea>
element:
<!-- First approach, as described above. -->
<textarea rows="10" readonly><?php echo 'First line. Second line.'; ?></textarea>
<!-- Here, the second one, in combination with the white-space: pre-line; CSS rule. -->
<textarea rows="10" readonly><?php echo 'First line.
Second line.'; ?></textarea>
How can I successfully effect a valid and cross-browser compatible carriage return within the HTML <textarea>
element?