HTML Guides for value
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>
The value of an <input type="date"> must be a full date written as YYYY-MM-DD, so keywords like today and localized dates like 15/03/2025 are rejected.
HTML has no relative date keywords. A date input's value has to be a valid date string: a four-digit year, a two-digit month and a two-digit day, joined by hyphens, as in 2025-03-15. Months and days need their leading zero (2025-3-5 fails), and the value can't include a time, because 2025-03-15T10:00 belongs to type="datetime-local". The min and max attributes of a date input follow the same format. An empty value is allowed and leaves the field blank.
Browsers discard a value they can't parse, so the field shows up empty instead of showing the date you meant. The date picker displays the date in the user's own locale, but the markup always uses YYYY-MM-DD, whatever language the page is written in.
To prefill today's date, write the actual date into value when the server renders the page. On a static page, leave value out and set it from a script after the page loads.
Invalid example
<label for="start">Start date</label>
<input type="date" id="start" name="start" value="today">
Valid example
<label for="start">Start date</label>
<input type="date" id="start" name="start" value="2025-03-15">
Setting today's date with JavaScript
<label for="end">End date</label>
<input type="date" id="end" name="end">
<script>
const now = new Date();
const month = String(now.getMonth() + 1).padStart(2, "0");
const day = String(now.getDate()).padStart(2, "0");
document.getElementById("end").value = now.getFullYear() + "-" + month + "-" + day;
</script>
An li element's value attribute must hold an integer, so a value that starts with anything other than a digit or a minus sign, such as NaN, is invalid.
Inside an ol, value sets the number shown for that list item. The HTML standard requires a valid integer: an optional - followed by one or more digits, like 3 or -1. The validator reads the value one character at a time. This message means the first character was neither - nor a digit, and it quotes that character. A word like first fails on its first letter, and so does a leading + or space.
NaN is JavaScript's "not a number" value. In the markup, it usually means a script or a rich text editor tried to work out the item's number, for example with parseInt() on text that has no digits, and wrote the failed result into the attribute.
Browsers ignore a value they can't parse and number the item as if the attribute weren't there, counting on from the item before it. Removing the attribute keeps the numbering readers see today. If an item needs a specific number, write that integer in value. To start the whole list at a number other than 1, put start on the ol instead. Fix whatever generates the attribute as well, or the bad value can come back the next time the page is edited.
Invalid example
<ol>
<li value="NaN">Preheat the oven to 180 °C.</li>
<li value="NaN">Mix the flour and the sugar.</li>
<li value="NaN">Bake for 25 minutes.</li>
</ol>
Valid example
<ol>
<li>Preheat the oven to 180 °C.</li>
<li>Mix the flour and the sugar.</li>
<li>Bake for 25 minutes.</li>
</ol>
An <input type="button"> element requires a non-empty value attribute because that attribute provides the button's visible label and its accessible name.
Unlike <input type="submit">, which defaults to a browser-provided label like "Submit", <input type="button"> has no default label. Without a value, the button renders as an empty rectangle with no text, and assistive technologies have nothing to announce to the user. The W3C validator flags this as an error because the HTML specification mandates that <input type="button"> must have a value attribute, and it must not be empty.
If you need a button without visible text (for example, an icon-only button), use a <button> element instead. The <button> element can contain child elements like <img> or <span>, and you can give it an accessible name through aria-label or visually hidden text. The <input> element cannot contain child content, so value is its only mechanism for labeling.
Invalid example
<input type="button" onclick="doSomething()">
Valid examples
Add a non-empty value attribute:
<input type="button" value="Click me" onclick="doSomething()">
Or switch to a <button> element, which is more flexible:
<button type="button" onclick="doSomething()">Click me</button>
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