HTML Guides for nan
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.
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>
The width of an <img> holds the text NaN, which usually means a script or template calculated the size from a missing or non-numeric value.
The width attribute takes a non-negative integer: digits only. NaN ("not a number") is what JavaScript returns when arithmetic runs on undefined or a non-numeric string, for example Math.round(data.width * scale) when data.width is missing. Writing that result into the markup puts the literal text NaN in the attribute. Other words that start with that letter, such as null or none, trigger the same message with a lowercase n.
Browsers can't read a number from NaN, so they ignore the attribute. The image then gets no reserved space before it loads, and the content below it shifts once it arrives. The height attribute often has the same bug and gets its own error.
Fix the code that produces the value. Check that the number is finite before you write it (Number.isFinite(width) in JavaScript), and leave the attribute out when the size isn't known.
Invalid example
<img src="photo.jpg" alt="A red car" width="NaN" height="NaN">
Valid example
<img src="photo.jpg" alt="A red car" width="640" height="480">
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