⚖️attributes vs. properties

HTML attributes vs. DOM properties

🔸 HTML attributesDOM propertiesattr-prop sync

For element nodes, most standard HTML attributes automatically become properties of DOM objects. 📗 JS.info ⟩ Attributes and properties

<body id="page"> => body.id="page"

HTML attributes

  • attribute name is case-insensitive.

  • attribute values are always strings.

  • element.attributes collection is iterable and has all the attributes as objects with name and value properties.

DOM properties

property ⇔ attribute sync

Last updated

Was this helpful?