Dofactory.com
Dofactory.com

HTML <output> style Attribute

A style attribute on an <output> tag assigns a unique style to the element.

Its value is CSS that defines the appearance of the output element.

Example

#

A style attribute on an <output> tag.
Move the slider to see the output values change.



The value is 25
<form oninput="result.value = slider.value">
  <input type="range" id="slider" value="25"> 

  <br /><br />
  The value is 
  <output name="result" for="slider"
          style="background-color:#4238ca; color:#fff;padding:8px 15px;margin:5px;border-radius:10px;">25</output>
</form>

Using style

The style attribute specifies the style, i.e. look and feel, of the <output> element.

A style contains any number of CSS property/value pairs, separated by semicolons (;).

The style attribute overrides any other style that was defined in a <style> tag or an external CSS file.

This inline styling affects the current <output> element only.


Syntax

<output style="CSS-styles">

Values

#

Value Description
CSS-styles One or more CSS property/value pairs separated by semicolons (;).

More Examples

A style attribute on an <output> tag.
Clicking the button toggles the background color of the <output> element.



The value is 25

<form oninput="display.value = range.value">
  <input type="range" id="range" value="25"> 

  <br /><br />
  The value is 
  <output id="myoutput" name="display" for="range"
          style="background-color:indigo; color:#fff;padding:8px 15px;margin:5px;border-radius:10px;">
    25
  </output>
</form>

<br />
<button onclick="toggle();">Toggle style</button>

<script>
  let toggle = () => {
    let element = document.getElementById("myoutput");

    if (element.style.background === "teal") {
       element.style.background = "indigo";
    } else {
       element.style.background = "teal";
    }
  }
</script>

Code explanation

The style attribute assigns a background color to the <output> element.

Clicking the button calls JavaScript which toggles the background color to another color.


Browser support

Here is when style support started for each browser:

Chrome
10.0 Mar 2011
Firefox
4.0 Mar 2011
IE/Edge
13.0 Nov 2015
Opera
11.0 Dec 2010
Safari
5.1 Oct 2011

You may also like

 Back to <output>

Author: Jack Poorte
Published: Jun 20 2021
Last Reviewed: Sep 30 2023


What's your favorite/least favorite part of Dofactory?


Guides