HTML <output> Tag โ Display Results
๐ Introduction
The <output> tag is used to display the result of a calculation or user action.
It is commonly used in:
- Calculators
- Forms with live results
- Interactive web tools
๐ It is usually updated using JavaScript.
๐งฑ Syntax
<output>Result</output>
๐ก Example (Simple Calculator)
<!DOCTYPE html>
<html>
<head>
<title>Output Example</title>
</head>
<body>
<h2>Simple Addition</h2>
<form oninput="result.value = Number(a.value) + Number(b.value)">
<input type="number" id="a" value="0" />
+
<input type="number" id="b" value="0" />
=
<output name="result">0</output>
</form>
</body>
</html>
๐ฅ๏ธ Output Explanation
- User enters numbers
- Result updates automatically
<output>shows calculated value
๐ฏ Why <output> is Important
1. ๐ Displays Results
Used to show computed values.
2. โ๏ธ Works with Forms
Often used with JavaScript or form events.
3. ๐ง Improves UX
Users see results instantly without reloading the page.
๐งฉ How It Works
<input /> โ calculation โ <output></output>
โ Input โ Process โ Output
๐จ Example (Styled Calculator)
<form oninput="sum.value = +x.value + +y.value">
<input type="number" id="x" />
+
<input type="number" id="y" />
=
<output name="sum"></output>
</form>
โ๏ธ <output> vs <div>
| Tag | Purpose |
|---|---|
<output> |
Displays calculated result |
<div> |
Generic container |
๐ซ Common Mistakes
- Using
<output>without logic โ - Forgetting to update value โ
- Using it as static text โ
๐งช Mini Exercise
Create a form that:
- Has two number inputs
- Adds them together
- Displays result in
<output> - Updates automatically when typing