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.
A style attribute on an <output> tag.
Move the slider to see the output values change.
<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>
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.
<output style="CSS-styles">
Value | Description |
---|---|
CSS-styles | One or more CSS property/value pairs separated by semicolons (;). |
A style attribute on an <output> tag.
Clicking the button toggles the background color of the <output> element.
<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>
The style attribute assigns a background color to the <output> element.
Clicking the button calls JavaScript which toggles the background color to another color.
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 |
Back to <output>