DOM Properties

HTMLInputElement.value

Build a form with the HTML form generator

Read/write, with type-dependent restrictions. Represents the current control value, which may differ from the value attribute after user or script editing. For file inputs, scripts cannot set an arbitrary non-empty value. Script assignments do not automatically fire input or change. Example result: initial / changed.

Formal Syntax & Structure

html syntaxhtml
element.value

Return Value

string

Property value. Read/write, with type-dependent restrictions.

Working Example

Example Snippethtml
<input id="demo" value="initial"><p>  Result:  <output id="result"></output></p><script>  const e = document.getElementById('demo');  const result = value => { document.getElementById("result").textContent = String(value); };  e.value='changed'; result(e.defaultValue+' / '+e.value);</script>
HTML Reference