Skip to content

Property vs. Attribute

AttributeProperty
Defined in the HTML markupExists on the DOM object
Stored as stringsCan be any JavaScript type
Represents the initial valueRepresents the current value
Accessed using getAttribute() / setAttribute()Accessed using dot notation or bracket notation
html
<input id="inp" value="Hello">
js
const input = document.getElementById("inp");

console.log(input.getAttribute("value")); // "Hello"
console.log(input.value); // "Hello"

Now change the value:

js
input.value = "World";

console.log(input.value); // "World"
console.log(input.getAttribute("value")); // "Hello"