The class attribute assigns one or more classnames to the <output> tag.
Classnames are defined in a stylesheet or in a local <style> element.
Classes, i.e. classnames, are used to style elements.
A class attribute styling an <output> element.
<style>
.output-result {
background-color: #4238ca;
color: #fff;
padding: 8px 15px;
margin: 5px;
border-radius: 10px;
}
</style>
<form oninput="result.value = slider.value">
<input type="range" id="slider" value="25">
<br /><br />
The value is <output class="output-result"
name="result"
for="slider">25</output>
</form>
Classes (i.e. classnames) are used for styling the output element.
Multiple classnames are separated by a space.
JavaScript uses classes to access elements by classname.
Tip: class is a global attribute that can be applied to any HTML element.
<output class="classnames">
Value | Description |
---|---|
classnames | One or more space-separated class names. |
A class attribute styling an <output> element.
Clicking the button toggles a classname that changes the output background and text colors.
<style>
.output {
background-color: #4238ca;
color: #fff;
padding: 8px 15px;
margin: 5px;
border-radius: 10px;
}
.bg-lighter {
background-color: #808cf8;
}
</style>
<form oninput="display.value = range.value">
<input type="range" id="range" value="25">
<br /><br />
The value is <output class="output" id="myoutput"
name="display"
for="range">25</output>
</form>
<br />
<button onclick="toggle();">Toggle class</button>
<script>
let toggle = () => {
let element = document.getElementById("myoutput");
element.classList.toggle("bg-lighter");
}
</script>
Three CSS classes are defined in the <style> element.
The class attribute in <output> assigns two of these classnames.
Repeatedly clicking the button toggles another class, changing the background and text color of the <output>.
Here is when class 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>