Vincent Van Gogh was born
,
in Zundert, the Netherlands.
He died
,
(age 37) in Auvers-sur-Oise, France.
A style attribute on a <time> tag assigns a unique style to the time element.
Its value is CSS that defines the appearance of the time element.
A style attribute on a <time> element.
Vincent Van Gogh was born
,
in Zundert, the Netherlands.
He died
,
(age 37) in Auvers-sur-Oise, France.
<article>
<p>
Vincent Van Gogh was born
<time style="color: brown; background: moccasin;" datetime="1853-03-30">March 30, 1853</time>,
in Zundert, the Netherlands.<br />He died
<time style="color: brown; background: moccasin;" datetime="1890-07-29">July 29, 1890</time>,
(age 37) in Auvers-sur-Oise, France.
</p>
</article>
The style attribute specifies the style, i.e. look and feel, of the <time> 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 <time> element only.
<time style="CSS-styles">
Value | Description |
---|---|
CSS-styles | One or more CSS property/value pairs separated by semicolons (;). |
A style attribute on a <time> element.
Clicking the button toggles the background color.
Vincent Van Gogh was born
,
in Zundert, the Netherlands.
He died
,
(age 37) in Auvers-sur-Oise, France.
<article>
<p id="myp">
Vincent Van Gogh was born
<time style="color: brown; background: moccasin;" datetime="1853-03-30">March 30, 1853</time>,
in Zundert, the Netherlands.<br />He died
<time style="color: brown; background: moccasin;" datetime="1890-07-29">July 29, 1890</time>,
(age 37) in Auvers-sur-Oise, France.
</p>
</article>
<br />
<button type="button"onclick="toggle();">Toggle class</button>
<script>
let toggle = () => {
let elements = document.getElementById("myp").getElementsByTagName("time");
[].forEach.call(elements, element => {
if (element.style.backgroundColor === "moccasin") {
element.style.backgroundColor = "aliceblue";
} else {
element.style.backgroundColor = "moccasin";
}
}
);
}
</script>
The style attribute assigns a background color to the <time> element.
Clicking the button calls JavaScript which toggles the background to another color.
Here is when style 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 <time>