The class attribute assigns one or more classnames to the <mark> 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 a <mark> element.
Paul Cézanne was a post-impressionist painter.
<style>
.marked-text {background: moccasin;font-style: italic;}
</style>
<p>
Paul Cézanne was a
<mark class="marked-text">post-impressionist</mark>
painter.
</p>
Classes (i.e. classnames) are used for styling the mark 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.
<mark class="classnames">
Value | Description |
---|---|
classnames | One or more space-separated class names. |
A class attribute styling a <mark> element.
Clicking the button toggles a classname that changes the background color.
Paul Cézanne was a post-impressionist painter.
<style>
.mark-moccasin { background-color: moccasin; }
.mark-lavender { background-color: lavender; }
</style>
<p>
Paul Cézanne was a
<mark id="mymark" class="mark-moccasin">post-impressionist</mark>
painter.
</p>
<br />
<button onclick="toggle();">Toggle class</button>
<script>
let toggle = () => {
let element = document.getElementById("mymark");
element.classList.toggle("mark-lavender");
}
</script>
Two CSS classes are defined in the <style> element.
The class attribute in <mark> assigns one classname.
Repeatedly clicking the button toggles another class, changing the background color of the <mark>.
Here is when class support started for each browser:
Chrome
|
6.0 | Sep 2010 |
Firefox
|
4.0 | Mar 2011 |
IE/Edge
|
9.0 | Mar 2011 |
Opera
|
11.1 | Mar 2011 |
Safari
|
5.0 | Jun 2010 |
Back to <mark>