HTML Guides for newline
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
A single-line <input>, such as type="text", can't hold a line break in its value, so the text has to fit on one line or move to a <textarea>.
The HTML standard says the value of text, search, telephone and password inputs must not contain line feed or carriage return characters. Browsers enforce this by stripping them: an input whose value is 12 Main Street, a line break and Springfield shows 12 Main StreetSpringfield, with the two lines glued together. Writing the line break as doesn't help, because the validator and the browser both see the decoded character.
This usually happens when a template prints text from a database or a rich text editor straight into value, and that text was saved with line breaks. When Nu shortens a long value, the message reads Bad value for attribute, with no value between the two spaces; look for an <input> whose value spans several lines in the source.
Pick the fix that matches what the field is for:
- If people should see and edit several lines, use a
<textarea>, which keeps line breaks. - If the field is meant to be single-line, replace the line breaks with a space or a comma before printing the value.
- If the input only carries data for a script and nobody edits it,
type="hidden"accepts line breaks in itsvalue.
Invalid example
<label for="address">Address</label>
<input type="text" id="address" name="address" value="12 Main Street
Springfield">
Valid example
<label for="address">Address</label>
<input type="text" id="address" name="address" value="12 Main Street, Springfield">
Keeping the line break with a textarea
<label for="address">Address</label>
<textarea id="address" name="address" rows="2">12 Main Street
Springfield</textarea>
Validate at scale.
Ship accessible websites, faster.
Automated HTML & accessibility validation for large sites. Check thousands of pages against WCAG guidelines and W3C standards in minutes, not days.
1K Weekly
1,000 monthly checks. Cancel anytime.
Get 1K Weekly →Join teams across 40+ countries