HTML value Attribute

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 3 Examples
Forms & Inputs

Introduction

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).

What You’ll Learn

01

Text default

Pre-fill fields.

02

Checkbox

Submitted data.

03

Radio groups

One name, many values.

04

Submit label

Button text.

05

JavaScript

.value property.

06

option

Select choices.

Purpose of value

The 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.

💡
value vs label text

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").

📝 Syntax

Add value with a string on supported form elements:

value.html
<input type="text" name="username" value="JohnDoe">
<input type="checkbox" name="subscribe" value="yes" checked>
<input type="submit" value="Send">

Syntax Rules

  • Always a string (quote special characters appropriately).
  • On text, email, number, etc.: initial displayed value; user can change it.
  • On checkbox/radio: submitted value when checked; visibility comes from labels.
  • On hidden inputs: fixed data sent with the form (not shown to users).
  • JavaScript: read/write with element.value (live current value).
  • On <option>: value submitted for that select choice.

💎 Values

The value attribute accepts a string. Meaning depends on the element and input type:

  • Text inputs (text, email, search, etc.) — Pre-filled string shown in the field.
  • Checkbox / radio — Data associated with that option when selected (e.g. value="pro").
  • Submit / reset / button inputs — Label text on the button face.
  • Hidden — Data included in submission without display.
  • <option> — Value for that dropdown item (falls back to option text if omitted).
value-types.html
<!-- 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">

⚡ Quick Reference

Control typeWhat value meansExample
type="text"Initial field contentvalue="JohnDoe"
type="checkbox"Sent when checkedvalue="yes"
type="radio"Sent for selected optionvalue="m"
type="submit"Button labelvalue="Submit"
type="hidden"Hidden submitted datavalue="token123"
JavaScriptinput.value = "..."Read/write live value

Applicable Elements

ElementSupported?Typical use
<input> (many types)YesPrimary use — defaults and submission data
<button>YesSubmitted value for button-type controls in forms
<option>YesValue for each select dropdown item
<param>YesParameter value for object/embed (legacy)
<li> (ordered lists)YesExplicit list numbering value
<textarea>No attributePut default text between tags, not value

value vs name vs defaultValue

Attribute / propertyRoleExample
nameKey in form submissionname="email"
valueData for that key / initial contentvalue="a@b.com"
element.value (JS)Current live valueChanges as user types
defaultValue (JS)Original HTML defaultReset reference value
placeholderHint only; not submittedGray example text

Examples Gallery

Pre-fill a form, update values with JavaScript, and see how radio buttons share a name but use different values.

👀 Live Preview

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

Example

A form with pre-filled text, email, checkbox, and submit button:

value.html
<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>

How It Works

  • Username field starts with JohnDoe.
  • Email field starts with john.doe@example.com.
  • Checked checkbox sends subscribe=yes on submit.
  • Submit button displays “Submit” from its value.

Dynamic Values with JavaScript

Update the current value when data changes at runtime:

dynamic-value.html
<input type="text" id="dynamicField">

<script>
  document.getElementById("dynamicField").value = "DynamicValue";
</script>

How It Works

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.

Example — radio button values

Each radio shares name but carries a distinct value:

radio-value.html
<input type="radio" name="size" value="s"> Small
<input type="radio" name="size" value="m" checked> Medium
<input type="radio" name="size" value="l"> Large

How It Works

Only the selected radio is submitted, e.g. size=m. Labels (“Small”, etc.) are for humans; value is the compact code sent to the server.

♿ Accessibility

  • Do not rely on value for visible labels — Use <label> elements so screen readers announce checkbox and radio options clearly.
  • Pre-filled values — Users with assistive tech hear defaults; ensure they are accurate and editable where appropriate.
  • Avoid sensitive defaults — Do not pre-fill passwords or private data without user consent.
  • Submit button value — Acts as accessible name for input type="submit"; make it descriptive (“Send message” not “OK” alone).
  • Distinguish placeholder from value — Placeholders are hints and may be skipped by some assistive technologies.

🧠 How value Works

1

Set in HTML

Default or payload.

value=""
2

User interacts

Type or select.

Input
3

Form submits

name=value pairs.

POST/GET
=

Server receives data

Structured input.

Browser Support

The value attribute is supported on form controls in all browsers. It is one of the oldest and most reliable HTML form features.

Universal · Fully supported

Core form feature everywhere

Works consistently across desktop and mobile browsers for all supported input types.

100% All browsers
Google Chrome Supported
Supported
Mozilla Firefox Supported
Supported
Apple Safari Supported
Supported
Microsoft Edge Supported
Supported
value attribute Excellent

Bottom line: Safe to use on all supported form elements in every modern browser.

💡 Best Practices

✅ Do

  • Use meaningful radio/checkbox values (pro, not option2)
  • Pair with name for every submittable control
  • Use .value in JavaScript for live updates
  • Pre-fill only when it helps users (edit forms, preferences)
  • Set descriptive submit button values

❌ Don’t

  • Confuse value with visible label text on radios
  • Use value on <textarea> (use inner text)
  • Trust client values without server validation
  • Pre-fill sensitive fields without consent
  • Rely on default checkbox value on in production
  • Use value to provide default or pre-filled values for form elements.
  • When dynamically setting values with JavaScript, ensure it aligns with user experience and form logic.
  • Be mindful of accessibility when using pre-filled values with assistive technologies.

🎉 Conclusion

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.

Key Takeaways

Knowledge Unlocked

4 truths every developer should know about value

Bookmark these before your next value implementation.

4
Core concepts
📝 02

Works on input, button,

Works on input, button, option, and a few other elements.

Syntax
⚙️ 03

Radio groups share name

Radio groups share name but each option has its own value.

Usage
🔒 04

In JavaScript, use element.value

In JavaScript, use element.value to read and update the current value.

Dynamic

❓ Frequently Asked Questions

If you omit value on a checkbox, browsers typically use on when checked. Always set an explicit value in production code.
No. Put default text between <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.
Yes, but disabled controls are not submitted with the form. Use readonly if you need the value sent but not edited.
For live form updates, use .value. It immediately reflects what the user sees and what gets submitted.

Practice form values

Try pre-filled fields, then update a value with JavaScript.

Try the form example →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful