<output> Tag in HTML

The <output> tag in HTML is used to represent the result of a calculation or user action. It is commonly used in forms, where it displays the outcome of an input or operation.

Key Points on <output> Tag:

Syntax of <output> Tag:

Syntax Example

<output name="result"></output>

Example of <output> Tag in HTML:

This example shows how the <output> tag is used to display the result of a simple calculation, such as adding two numbers.

Code Example


        <form>
            <label for="num1">Number 1:</label>
            <input type="number" id="num1" value="10"><br>
            <label for="num2">Number 2:</label>
            <input type="number" id="num2" value="20"><br>
            <button type="button" onclick="calculateResult()">Add Numbers</button><br>
            <output name="result" id="result">0</output>
        </form>
        
        <script>
        function calculateResult() {
            var num1 = document.getElementById('num1').value;
            var num2 = document.getElementById('num2').value;
            var result = parseInt(num1) + parseInt(num2);
            document.getElementById('result').value = result;
        }
        </script>
                

Output



0

The <output> tag is a useful HTML element for displaying the result of calculations or user actions in a form. It makes it easy to show real-time feedback based on user input, making it an essential tool for interactive web applications.