- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <output> Tag
The HTML <output> tag is a flexible and under used component that enables programmers to dynamically show the outcomes of calculations or scripts inside the content. It improves the overall user experience by offering a quick and meaningful way to display the results of user activities or computations.
It can be used in forms, math-related material, or any other part of the document where dynamic output needs to be given because it is a self-closing tag, which means it doesn't need a closing tag.
Syntax
Following is the syntax for HTML <datalist> tag −
<datalist>.......</datalist>
Specific Attributes
The HTML <output > tag also supports the following additional attributes −
S.No. | Attribute & Description |
---|---|
1 | for List of IDs of other elements, i.e it indicates the elements who have contributed input value to the calculation. |
2 | form Enables to place output elements anywhere within a document. |
3 | name It is the name of the element. |
Example
Following is the example, where we are providing the range slider along with a inputfield and considering the sum of the user given values.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML output tag</title> </head> <body> <!--create output tag--> <form oninput="add.value = parseInt(n1.value) + parseInt(n2.value)"> <input type="range" min="0" max="100" name='n1' value="10"> <input type="number" name='n2' value="20"> <br> Output: <output name='add'></output> </form> </body> </html>
On running the above code, it will generate an output consisting of the range slider along with a input field displayed on the webpage.
Example
Considering the another scenario, where we are going to take two input fields with predefined values and retrieving the output as the combination of the both the values.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML output tag</title> </head> <body> <!--create output tag--> <form oninput="add.value = (txt1.value).concat(txt2.value)"> <input type="text" name='txt1' value="HTML"> <input type="text" name='txt2' value="CSS"> <br> Output: <output name='add'></output> </form> </body> </html>
When we run the above code, it will generate an output consisting of the two input field provided with a data displayed on the webpage.
Example
In the following example, we are going to perform the arthimetic operations.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML output tag</title> </head> <body> <!--create output tag--> <form oninput="sum.value = parseInt(n1.value) + parseInt(n1.value) + parseInt(n3.value)"> <input type="range" value="10" name='n1'> + <input type="number" value="5" name='n2'> + <input type="number" value="10" name='n3'> = <output name='sum'></output> </form> </body> </html>
On running the above code, it will generate an output consisting of the input fields that are going to perform the arithmetic operations and provide the output.
Example
Let's look at the following example, where we are going to apply CSS to the output tag.
<!DOCTYPE html> <html lang="en"> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>HTML output tag</title> <style> output { width: 200px; height: 50px; color: blue; padding: 10px; background-color: cadetblue; font-size: 20px; } </style> </head> <body> <!--create output tag--> <form oninput="sum.value = parseInt(n1.value) + parseInt(n1.value)"> <input type="range" value="5" name='n1'> + <input type="number" value="2" name='n2'> <br> <br> Output: <output name='sum' for="n1 n2"></output> </form> </body> </html>
When we run the above code, it will generate an output consisting input field along with a CSS applied to the output tag displayed on the webpage.