One of the most amazing things about working on the Web is that you can have years of experience under your belt and there are still things you don’t know. Often, people associate this with a more quickly-moving language like JavaScript, but it equally hold true for HTML. Although, on the first sight, HTML seems like a very “easy” markup language, it can still be incredibly hard to write solid, semantic HTML – even for seasoned developers. But then, there are even moments where you are just surprised because you hear about a little detail you never heard before or completely forgot about. And sometimes, that little detail is a whole HTML element.
Earlier this month, Den Odell just wrote a fantastic article about such an element: the HTML <output> element. The <output> element was added to HTML in 2009, in W3C’s HTML 5 Working Draft 12 and it is a form element. Its intent is clearly stated in the HTML Living Standard: The output element represents the result of a calculation performed by the application, or the result of a user action. So it is primarily intended for the output of, let’s say, a little calculator:
<form onsubmit="return false" oninput="sum.value = Number(a.value) + Number(b.value)">
<label for="a">First number:</label>
<input type="number" id="a" name="a" value="0">
<label for="b">Second number:</label>
<input type="number" id="b" name="b" value="0">
<label for="sum">Sum:</label>
<output id="sum" name="sum" for="a b" role="status">0</output>
</p>
</form>
Looking at the code above, there are a few details you might notice: first of all, the <output> element can be used very much like any other form element. It works inside a <form> but you can also use it outside of a form and associate the output with the form via a form attribute. I always go to mdn and have a quick look at what attributes are supported. You can also see that the output element has a for attribute, much like the <input>s. But the for attribute of the <output> actually supports a space-separated list of other elements’ ids, which are indicating which elements contributed input values to the calculation – or otherwise affected the result. Lastly, the <output> can have a name, of course.
Practical Use Cases
Now, not everyone of us is building basic calculators all the time. So what are practical use cases for this element?
One of the most useful things is that the element is mapped to role="status" in the accessibility tree. For better cross-browser compatibility, it might make sense to add an additional role="status“, for now. So the <output> element will announce its value when it changes, for example via a screen reader, and the entire content is spoken without interrupting the user.
This makes the <output> very flexible and useful. And it might be reason enough to think about how you could use it in one of your next projects. Den, for example, mentions using it for displaying user-friendly versions of range slider values. This is actually something I could consider for the knob components of my little style mixer above, as well. 🤔 He also suggests using it for immediate form validation feedback, like for password strength indicators, character counts, or real-time validation messages. And, of course, it can be useful to output any kind of server-calculated output, even fetched values coming from APIs or the total of a shopping cart. You could also use it to output the adjusted scaled quantities in recipes, show changed interest rates in a mortgage calculator, or to announce the adjusted dates or duration of stay in a booking form. So basically, <output> is super useful when user interaction results in a live calculation or a value update, and you want screen readers to announce it automatically without using extra ARIA hacks.
But as Scott O'Hara notes, the latest version of the HTML standard also isn’t super strict when it comes to the result inside of an output. It can be the result of a math calculation inside of a form, yes. But you could also interpret it a bit more broadly, as everything that makes sense to announce as the “result of a user action” – as long as it is Phrasing Content, so you can’t use headings, lists, or sectioning elements like article, section, div, and so on. But you are not confined to outputting numbers only. Scott, for instance, explored using <output> for toast components, those little, temporary notifications appearing on the screen somewhere. But if you think about it: it could also be used for outputting the number of matched items in interactive filters. So when a user selects a certain set of filters, the <output> shows “42 results” or “No items found” dynamically. It could be used to display the results of interactions on a dashboard (“CPU usage 75%”, “120 visits per month”). It could be used to announce the score or right answers in quizzes or games. Or, you could use it to provide feedback on any interactive action, for example toggling a switch in a settings section (“Notifications enabled!”) or completing a task (“1893 todos remaining for today.”).
If you think about it: the
Time to play and experiment with it, I guess…
❦
This is post 14 of Blogtober 2025.
~