A style attribute on a <body> tag assigns a unique style to the page body.
Its value is CSS that defines the appearance of the body.
A style attribute on a <body> tag.
<body style="background-color:oldlace; padding:25px;">
<h2>The Night Watch</h2>
<p>
Militia Company of District II under the Command of
Captain Frans Banninck Cocq, also known as The Shooting
Company of Frans Banning Cocq and Willem van Ruytenburch,
but commonly referred to as The Night Watch (Dutch:
De Nachtwacht), is a 1642 painting by Rembrandt van Rijn.
It is in the collection of the Amsterdam Museum but is
prominently displayed in the Rijksmuseum as the
best-known painting in its collection. The Night Watch
is one of the most famous Dutch Golden Age paintings.
</p>
<p>
The painting is famous for three things: its colossal
size, the dramatic use of light and shadow (tenebrism),
and the perception of motion in what would have
traditionally been a static military group portrait.
The painting was completed in 1642, at the peak of the
Dutch Golden Age.
</p>
<br />
<img src="/img/html/nightwatch.jpg">
</body>
The style attribute specifies the style, i.e. look and feel, of the <body> 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 <body> element only.
<body style="CSS-styles">
Value | Description |
---|---|
CSS-styles | One or more CSS property/value pairs separated by semicolons (;). |
A style attribute on a <body> tag.
Clicking the button toggles the background color.
Militia Company of District II under the Command of Captain Frans Banninck Cocq, also known as The Shooting Company of Frans Banning Cocq and Willem van Ruytenburch, but commonly referred to as The Night Watch (Dutch: De Nachtwacht), is a 1642 painting by Rembrandt van Rijn. It is in the collection of the Amsterdam Museum but is prominently displayed in the Rijksmuseum as the best-known painting in its collection. The Night Watch is one of the most famous Dutch Golden Age paintings.
The painting is famous for three things: its colossal size, the dramatic use of light and shadow (tenebrism), and the perception of motion in what would have traditionally been a static military group portrait. The painting was completed in 1642, at the peak of the Dutch Golden Age.
<body id="mybody" style="background-color:oldlace; padding:25px;">
<h2>The Night Watch</h2>
<p>
Militia Company of District II under the Command of
Captain Frans Banninck Cocq, also known as The Shooting
Company of Frans Banning Cocq and Willem van Ruytenburch,
but commonly referred to as The Night Watch (Dutch:
De Nachtwacht), is a 1642 painting by Rembrandt van Rijn.
It is in the collection of the Amsterdam Museum but is
prominently displayed in the Rijksmuseum as the
best-known painting in its collection. The Night Watch
is one of the most famous Dutch Golden Age paintings.
</p>
<p>
The painting is famous for three things: its colossal
size, the dramatic use of light and shadow (tenebrism),
and the perception of motion in what would have
traditionally been a static military group portrait.
The painting was completed in 1642, at the peak of the
Dutch Golden Age.
</p>
<br />
<img src="/img/html/nightwatch.jpg">
<br /><br />
<button onclick="toggle();">Toggle style</button>
<script>
let toggle = () => {
let element = document.getElementById("mybody");
if (element.style.backgroundColor === "oldlace") {
element.style.backgroundColor = "aliceblue";
} else {
element.style.backgroundColor = "oldlace";
}
}
</script>
</body>
The style attribute assigns a background color to the <body> element.
Clicking the button calls JavaScript which toggles the background color.
Here is when style support started for each browser:
Chrome
|
1.0 | Sep 2008 |
Firefox
|
1.0 | Sep 2002 |
IE/Edge
|
1.0 | Aug 1995 |
Opera
|
1.0 | Jan 2006 |
Safari
|
1.0 | Jan 2003 |
Back to <body>