References

Beginner-friendly references for web development, with live, editable examples.

The HTML value attribute

Attribute All modern browsers Updated
Quick answer

The HTML value attribute sets the control's value — the initial or submitted data, depending on the element. It is used on form controls including <input>, <option>, <button>, <li>, <meter>, <progress> and <data>.

Overview

The value attribute sets a control's value — but what that means depends on the element. On a text <input> it sets the initial text; on a checkbox or radio it sets the value that is submitted when checked (not whether it is checked); on an <option> it is what is submitted when that option is selected; and on <li>, <meter>, <progress> and <data> it has its own meaning.

For text inputs, value sets only the initial value — once the user types, the attribute and the live value diverge, so read element.value in JavaScript for the current value. On checkboxes and radios, the value is submitted only if the control is checked, which is why grouping radios by name and giving each a distinct value is how you capture the choice.

One exception worth remembering: <textarea> has no value attribute — its initial content goes between the opening and closing tags instead.

Syntax

<input type="text" name="city" value="London">

Values

Value
A string or number, depending on the element and input type.

Example

Live example
<input type="text" name="city" value="London" style="padding:8px;">

Best practices

  • On checkboxes and radios, value is what is submitted when checked — set it meaningfully.
  • For text inputs, remember value is only the initial value; read element.value in JavaScript for the current one.
  • Give each <option> a value when the submitted data differs from the visible text.
  • Put a <textarea>'s initial content between its tags, not in a value attribute.

Frequently asked questions

What does the value attribute do?
It sets a control's value — the initial text of an input, the submitted value of a checked checkbox or selected option, and so on.
Does value set whether a checkbox is checked?
No. That is the checked attribute. value is what gets submitted when the box is checked.
Why doesn't value update as I type?
The attribute holds only the initial value. Read element.value in JavaScript for the live, current value.
How do I set default text in a textarea?
Place it between the tags — <textarea>Default</textarea> — since <textarea> has no value attribute.