Last Updated : 30 Nov, 2021
The
valueattribute in HTML is used to specify the value of the element with which it is used. It has different meaning for different HTML elements.
Usage:It can be used with the following elements: <input>, <button>, <meter>, <li>, <option>, <progress>, and <param>, <output>.
<input value = "value">
<!DOCTYPE html>
<html>
<head>
<title>HTML value Attribute</title>
</head>
<body style = "text-align:center">
<h1 style = "color:green;">
GeeksforGeeks
</h1>
<h2>
HTML value Attribute
</h2>
Input: <input type = "text" value = "GeeksforGeeks">
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>HTML value Attribute</title>
</head>
<body style = "text-align:center">
<h1 style = "color:green;">
GeeksforGeeks
</h1>
<h2>
HTML value Attribute
</h2>
<input type = "button" value = "Click me!">
</body>
</html>
<button value = "value">
<!DOCTYPE html>
<html>
<head>
<title>HTML value Attribute</title>
</head>
<body style = "text-align:center">
<h1 style = "color:green;">
GeeksforGeeks
</h1>
<h2>
HTML value Attribute
</h2>
<button id="btn" value="GeeksforGeeks" onclick="geek()">
Click me!</button>
<p id="g"></p>
<script>
function geek() {
var x = document.getElementById("btn").value;
document.getElementById("g").innerHTML = "Welcome to " + x;
}
</script>
</body>
</html>
<meter value = "value">
<!DOCTYPE html>
<html>
<head>
<title>HTML value Attribute</title>
</head>
<body style = "text-align:center">
<h1 style = "color:green;">
GeeksforGeeks
</h1>
<h2>
HTML value Attribute
</h2>
<p>Health: <meter min="0" low="40" high="90"
max="100" value="60"></meter></p>
</body>
</html>
<li value = "number">list item </li>
<!DOCTYPE html>
<html>
<head>
<title>HTML value Attribute</title>
</head>
<body >
<h1 style = "color: green;">
GeeksforGeeks
</h1>
<h2>
HTML value Attribute
</h2>
<p>Sorting Algorithms</p>
<ol>
<li value="50">Merge sort</li>
<li>Quick sort</li>
<li>Insertion sort</li>
</ol>
</body>
</html>
<option value = "value"></option>
<!DOCTYPE html>
<html>
<head>
<title>HTML value Attribute</title>
</head>
<body style = "text-align:center">
<h1 style = "color: green;">
GeeksforGeeks
</h1>
<h2>
HTML value Attribute
</h2>
Sorting Algorithms:
<select id="opt">
<option value="quick">Quick sort</option>
<option value="merge">Merge sort</option>
<option value="insertion">Insertion sort</option>
</select>
<button type="button" onclick="geek()">Click me!</button>
<p id = "p"></p>
<script>
function geek() {
var x = document.getElementById("opt").selectedIndex;
var y = document.getElementsByTagName("option")[x].value;
document.getElementById("p").innerHTML = "The selected
option has value equals " + y + ".";
}
</script>
</body>
</html>
<progress value = "number"></progress>
<!DOCTYPE html>
<html>
<head>
<title>HTML value Attribute</title>
</head>
<body style = "text-align:center">
<h1 style = "color: green;">
GeeksforGeeks
</h1>
<h2>
HTML value Attribute
</h2>
Progress:
<progress value="65" max="100">
</progress>
</body>
</html>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4