- 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
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
<output> </output>
Attribute
HTML output tag supports Global and Event attributes of HTML. And some specific attributes as well which are listed bellow.
Attribute | Value | Description |
---|---|---|
for | element_id | List of IDs of other elements, i.e it indicates the elements who have contributed input value to the calculation. |
form | form_id | Enables to place output elements anywhere within a document. |
name | name | It is the name of the element. |
Examples of HTML output Tag
Bellow examples will illustrate the usage of output tag. Where, when and how to use it to create output section and how we can style that output using CSS.
Creating Output Element
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> <title>HTML output tag</title> </head> <body> <!--create output element--> <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>
Output based on two input field
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> <title>HTML output tag</title> </head> <body> <!--create output element--> <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>
Output of Arithmetic Operation
In the following example, we are going to perform the arthimetic operations.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML output tag</title> </head> <body> <!--create output element--> <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>
Styling Output Element
Let's look at the following example, where we are going to apply CSS to the output tag.
<!DOCTYPE html> <html lang="en"> <head> <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 element--> <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
Supported Browsers
Tag | |||||
---|---|---|---|---|---|
ouput | Yes 10.0 | Yes 13.0 | Yes 4.0 | Yes 5.1 | Yes 11.0 |
To Continue Learning Please Login
Login with Google