A style attribute on a <picture> tag assigns a unique style to the picture.
Its value is CSS that defines the appearance of the picture element.
A style attribute on a <picture> element.
<picture class="picture"
style="display: inline-block;padding: 10px;border: 3px solid teal;">
<source media="(max-width: 520px)" srcset="/img/html/vangogh-sm.jpg">
<source media="(max-width: 768px)" srcset="/img/html/vangogh.jpg">
<img src="/img/html/vangogh-lg.jpg" alt="Vincent Van Gogh">
</picture>
The style attribute specifies the style, i.e. look and feel, of the <picture> 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 <picture> element only.
<picture style="CSS-styles">
Value | Description |
---|---|
CSS-styles | One or more CSS property/value pairs separated by semicolons (;). |
A style attribute on a <picture> element.
Clicking the button toggles the picture border color.
<picture id="mypicture" class="picture"
style="display: inline-block;padding: 10px;border: 3px solid teal;">
<source media="(max-width: 520px)" srcset="/img/html/vangogh-sm.jpg">
<source media="(max-width: 768px)" srcset="/img/html/vangogh.jpg">
<img src="/img/html/vangogh-lg.jpg" alt="Vincent Van Gogh">
</picture>
<br /><br />
<button onclick="toggle();">Toggle style</button>
<script>
let toggle = () => {
let element = document.getElementById("mypicture");
if (element.style.borderColor === "teal") {
element.style.borderColor = "tomato";
} else {
element.style.borderColor = "teal";
}
}
</script>
The style attribute assigns a border color to the <picture> element.
Clicking the button calls JavaScript which toggles the border color to another color.
Here is when style support started for each browser:
Chrome
|
38.0 | Oct 2014 |
Firefox
|
38.0 | May 2015 |
IE/Edge
|
13.0 | Nov 2015 |
Opera
|
25.0 | Oct 2014 |
Safari
|
9.1 | Mar 2016 |
Back to <picture>