Open In App

HTML input value Attribute

Last Updated : 30 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The HTML input value attribute defines the initial value of an <input> element, such as text fields, checkboxes, or radio buttons. It sets the default content or state for the input before user interaction or form submission.

It has different meanings for different input types:

  • The “button”, “reset” and “submit” property specifies the text on the button.
  • The “text”, “password” and “hidden” property specifies the initial value of the input field.
  • The “checkbox”, “radio” and “image” property specifies the value associated with the input.

Syntax

<input value = "text">

Attribute Value: It contains a single value text that specifies the value of the input element.

Example 1: In this example we creates a centered page with a green heading, demonstrating the use of the input value attribute. The text field is pre-filled with the default value “GeeksforGeeks” upon loading.

html
<!DOCTYPE html>
<html>

<head>
    <title>HTML input value Attribute</title>
</head>

<body style="text-align:center">

    <h1 style="color:green;">
        GeeksforGeeks
    </h1>

    <h2>
        HTML input value Attribute
    </h2>

    Input: <input type="text" value="GeeksforGeeks">
</body>

</html>

Output:

inputvalue

Example 2: In this example we demonstrates an input button with the value attribute set to “Submit”. It is centered on the page with a green heading titled “GeeksforGeeks”.

html
<!DOCTYPE html>
<html>

<head>
    <title>HTML input value Attribute</title>
</head>

<body style = "text-align:center">
    
    <h1 style = "color:green;">
        GeeksforGeeks
    </h1>
         
    <h2>
        HTML input value Attribute
    </h2>
         
    <input type = "button" value = "Submit">
</body>

</html>

Output:

inputvalue

Supported Browsers

The browser supported by <input> value attribute are listed below:


Next Article

Similar Reads