👀 Live Preview
A text field with a default value and a submit button label from value:

The value attribute is a fundamental HTML form feature that sets the initial or submitted data for a control. On a text field it pre-fills what the user sees; on a checkbox or radio it defines what gets sent when that option is selected.
Understanding value is essential for building forms with defaults, hidden fields, submit button labels, and grouped radio options. It works together with name (how data is labeled on submit) and type (what kind of control it is).
Pre-fill fields.
Submitted data.
One name, many values.
Button text.
.value property.
Select choices.
valueThe primary purpose of the value attribute is to specify data associated with a form element. For text-like inputs, it is the starting content in the field. For checkboxes and radios, it is the payload paired with the control’s name when selected. For type="submit" and type="button" inputs, it sets the button’s visible label.
Users can edit text values, but unchecked checkboxes are omitted from form submission entirely regardless of their value.
On checkboxes and radios, the words beside the control come from a <label> or nearby text. value is the machine-readable string sent to the server (e.g. value="yes").
Add value with a string on supported form elements:
<input type="text" name="username" value="JohnDoe">
<input type="checkbox" name="subscribe" value="yes" checked>
<input type="submit" value="Send">element.value (live current value).<option>: value submitted for that select choice.The value attribute accepts a string. Meaning depends on the element and input type:
text, email, search, etc.) — Pre-filled string shown in the field.value="pro").<option> — Value for that dropdown item (falls back to option text if omitted).<!-- Text default -->
<input type="text" value="Hello">
<!-- Checkbox payload when checked -->
<input type="checkbox" name="agree" value="yes">
<!-- Radio: same name, different values -->
<input type="radio" name="plan" value="free">
<input type="radio" name="plan" value="pro">| Control type | What value means | Example |
|---|---|---|
type="text" | Initial field content | value="JohnDoe" |
type="checkbox" | Sent when checked | value="yes" |
type="radio" | Sent for selected option | value="m" |
type="submit" | Button label | value="Submit" |
type="hidden" | Hidden submitted data | value="token123" |
| JavaScript | input.value = "..." | Read/write live value |
| Element | Supported? | Typical use |
|---|---|---|
<input> (many types) | Yes | Primary use — defaults and submission data |
<button> | Yes | Submitted value for button-type controls in forms |
<option> | Yes | Value for each select dropdown item |
<param> | Yes | Parameter value for object/embed (legacy) |
<li> (ordered lists) | Yes | Explicit list numbering value |
<textarea> | No attribute | Put default text between tags, not value |
value vs name vs defaultValue| Attribute / property | Role | Example |
|---|---|---|
name | Key in form submission | name="email" |
value | Data for that key / initial content | value="a@b.com" |
element.value (JS) | Current live value | Changes as user types |
defaultValue (JS) | Original HTML default | Reset reference value |
placeholder | Hint only; not submitted | Gray example text |
Pre-fill a form, update values with JavaScript, and see how radio buttons share a name but use different values.
A text field with a default value and a submit button label from value:
A form with pre-filled text, email, checkbox, and submit button:
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username" value="JohnDoe">
<label for="email">Email:</label>
<input type="email" id="email" name="email" value="john.doe@example.com">
<input type="checkbox" id="subscribe" name="subscribe" value="yes" checked>
<label for="subscribe">Subscribe</label>
<input type="submit" value="Submit">
</form>JohnDoe.john.doe@example.com.subscribe=yes on submit.value.Update the current value when data changes at runtime:
<input type="text" id="dynamicField">
<script>
document.getElementById("dynamicField").value = "DynamicValue";
</script>The script sets .value on the input, which updates both the displayed text and the value that would be submitted. Prefer .value over setAttribute("value", ...) for live form fields.
Each radio shares name but carries a distinct value:
<input type="radio" name="size" value="s"> Small
<input type="radio" name="size" value="m" checked> Medium
<input type="radio" name="size" value="l"> LargeOnly the selected radio is submitted, e.g. size=m. Labels (“Small”, etc.) are for humans; value is the compact code sent to the server.
<label> elements so screen readers announce checkbox and radio options clearly.input type="submit"; make it descriptive (“Send message” not “OK” alone).Default or payload.
Type or select.
name=value pairs.
Structured input.
The value attribute is supported on form controls in all browsers. It is one of the oldest and most reliable HTML form features.
Works consistently across desktop and mobile browsers for all supported input types.
Bottom line: Safe to use on all supported form elements in every modern browser.
pro, not option2)name for every submittable control.value in JavaScript for live updatesvalue with visible label text on radiosvalue on <textarea> (use inner text)on in productionvalue to provide default or pre-filled values for form elements.The value attribute is a crucial part of HTML forms, letting you set defaults, button labels, and submission payloads. Used with name and the right type, it structures how data flows from browser to server.
Master both HTML defaults and the JavaScript .value property to build forms that are easier to use and easier to process on the backend.
valueBookmark these before your next value implementation.
value sets initial content (text) or submission data (checkbox/radio).
Works on input, button, option, and a few other elements.
Radio groups share name but each option has its own value.
In JavaScript, use element.value to read and update the current value.
value on a checkbox, browsers typically use on when checked. Always set an explicit value in production code.<textarea> and </textarea>. Use .value in JavaScript for textareas.value is real content (submitted for text fields). placeholder is a gray hint that disappears when the user types and is not a substitute for labels.readonly if you need the value sent but not edited..value. It immediately reflects what the user sees and what gets submitted.Try pre-filled fields, then update a value with JavaScript.
5 people found this page helpful