How to specify a name for the output element in HTML?

The name attribute specifies the name of an <output> element. It is used to reference form data after it has been submitted, or to reference the element in JavaScript. The <output> tag is used to represent the result of a calculation.

The HTML <for> type attribute is used because it specifies the relationship between the result of the calculation and the elements used in the calculation. form is used because it specifies which form the output element it belongs to. name is used because it specifies a name for the output element.

Syntax:

<output name="name">

Example: In this example, we will specify a name for the output element.

HTML




<!DOCTYPE html>
<html>
   
<body>
    <h1>The output element</h1>
    <form oninput=
          "k.value=parseInt(x.value)+parseInt(y.value)">
        <input type="range" id="x" value="20"> +
        <input type="number" id="y" value="20">
        = <output name="k" for="x y"></output>
    </form>
</body>
 
</html>


Output: