Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML <picture> style Attribute

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.

Example

#

A style attribute on a <picture> element.

Vincent Van Gogh
<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>

Using style

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.


Syntax

<picture style="CSS-styles">

Values

#

Value Description
CSS-styles One or more CSS property/value pairs separated by semicolons (;).

More Examples

A style attribute on a <picture> element.
Clicking the button toggles the picture border color.

Vincent Van Gogh

<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>

Code explanation

The style attribute assigns a border color to the <picture> element.

Clicking the button calls JavaScript which toggles the border color to another color.


Browser support

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

You may also like

 Back to <picture>

Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides