HTML <output> Element

Publish in HTML Tutorial el 25/05/2025 14:31

The <output> element represents the result of a calculation or user action. It's typically used to display results from form calculations or script outputs. Unlike other form elements, <output> doesn't have a value attribute - its content is set either by JavaScript or through form relationships.


Basic Syntax

Here's the basic structure of the <output> element:


Attributes

The <output> element supports these attributes:

  • for: Specifies the relationship between elements used in the calculation and the output
  • form: Associates the output with a form element
  • name: Specifies the name of the element


Examples

1. Basic Output Example

A simple output element displaying static text:

Play Code


2. Simple Calculator

Using output with form inputs to create a simple calculator:

Play Code


3. Range Slider with Output

Displaying the current value of a range slider using output:

Play Code


4. JavaScript Calculation

Using JavaScript to calculate and display results in an output element:

Play Code


5. Dynamic Content with JavaScript

Using output to display dynamic content from user input:

Play Code


Tips and Tricks

  • Use the for attribute to explicitly associate the output with input elements
  • Combine with the oninput event for real-time updates
  • Style output elements with CSS to make them stand out from regular text
  • For complex calculations, use JavaScript to update the output value
  • Remember that output elements are not form controls - they don't participate in form submission


Browser Support

The <output> element is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. For older browsers, you can use a span or div with similar functionality.

También te puede interesar

HTML <style> Element
HTML <style> Element

The <style> HTML element contains style information for a document, or part of a document. ...

HTML <strong> Element
HTML <strong> Element

The <strong> element is used to indicate that its content has strong importance, seriousnes...

HTML <span> Element
HTML <span> Element

The <span> element is an inline container used to mark up a part of a text or document. Unl...

HTML <source> Element
HTML <source> Element

The <source> element is used to specify multiple media resources for media elements like &l...

HTML <small> Element
HTML <small> Element

The <small> element is used to represent side-comments and small print, typically for discl...

HTML <section> Element
HTML <section> Element

HTML <section> Element: The Complete Guide The <section> element is a semantic HTML ...