Computer >> Computer tutorials >  >> Programming >> HTML

How to use the <output> tag in HTML?


The HTML <output> tag specifies the result of a calculation. Here are the attributes of the <output> tag in HTML −

Attribute
Value
Description
forHow to use the <output> tag in HTML?
for
List of IDs of other elements, i.e it indicates the elements who have contributed input value to the calculation.
formHow to use the <output> tag in HTML?
form
Enables to place output elements anywhere within a document.
nameHow to use the <output> tag in HTML?
name
It is the name of the element.


How to use the <output> tag in HTML?

Example

You can try to run the following code to specify the result of a calculation −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML Output Tag</title>
   </head>
   <body>
      <form oninput = "result.value = parseInt(a1.value)+parseInt(a2.value)">
         <input type = "range" name = "a1" value = "0" /> +
         <input type = "number" name = "a2" value = "5" /> <br />
          The output is: <output name = "result"></output>
      </form>
   </body>
</html>