Jens Oliver Meiert

Arguments for the “style” Attribute

Post from June 27, 2007 (↻ December 11, 2016), filed under .

The HTML Working Group is currently arguing about dropping or keeping the style attribute. To encourage discussion outside the Working Group, here are the reasons I see to keep @style:

  • To allow authors to set really [unique] formatting:

    This is probably not the best description […], so let’s use an example: There is partially strong desire to avoid page load “flickering” caused by images being loaded. The usual way to address that is by setting width and height attributes which should be replaced by the style attribute (that is presentational by design).

    <img src="foo" alt="bar" style="width: 100px; height: 200px;">

    Assuming that we don’t talk about galleries where all thumbs have the same size (and may thus be styled via #gallery img {} […]), but instead a content rich website that uses many different image or media sizes, there is no other practical option but using style […].

  • To enable/ensure styling of external material:

    […] take advertising agencies that deliver ad code to commercial websites. Apart from the shadow world their markup appears to come from, we want them to adhere to web standards, too.

    But how’s that going to happen without style? Considering a really simple banner ad where the ad company only wants to make sure there appears no border around the banner, there are basically three options:

    1. Hope for each partner to remove an eventual border. (Doesn’t work.)
    2. Delivering the ad with border="0" (or worse). (Presentational.)
    3. Delivering the ad with style="border: 0;". [(Workable.)]
  • To enable […] scoped style sheets:

    Robert Burns […] mentioned them, and even though I remember Eric (Meyer) to be unsure about their future, scoped style sheets might become a really great thing one day.

    Arguments for scoped style sheets should probably be collected on www-style, but […] they could mean even more elegant and effective style sheets […].

We could go on with compatibility, philosophy, and other arguments. At this point I don’t consider it wise to drop the style attribute. It sends the wrong signal. We should instead focus on advocating its appropriate use.

A reply to Henri Sivonen (original mail) shares more thoughts:

In my opinion, it is extremely silly to think that height='' and width='' are bad but style='width: …; height: …;' is good. I’d rather have height='' and width='' on all elements that are replaced elements in the normal case.

Assuming that we don’t want any presentational stuff in our documents at all, [and regarding] the style attribute as the only attribute we would need “in case,” using style for image [dimensions] is better than using width and height attributes […].

If this is not enough, there’s more.

Update (August 15, 2014)

I sure do have a complicated way of expressing myself. The idea here was that there is the occasional use case for @style, like for really unique stuff you really need but really can’t handle differently. We should still keep our hands away from it where we can.

About the Author

Jens Oliver Meiert, photo of July 27, 2015.

Jens Oliver Meiert is a developer (O’Reilly, W3C, ex-Google) and philosopher. He experiments with art and adventure. Here on meiert.com he shares and generalizes and exaggerates some of his thoughts and experiences.

There’s more Jens in the archives and at Amazon. If you have any questions or concerns (or recommendations) about what he writes, leave a comment or a message.

Comments (Closed)

  1. On July 2, 2007, 11:17 CEST, Laurens Holst said:

    I agree that style should be kept, however your first argument is kind of off; designating the image’s width on <img> elements is not presentation; it’s specifying meta-information of the image, which noticably improves the user experience (the flickering you mentioned).

    The only downside is that due to historical reasons, the attributes override the intrinsic dimensions of the image, which is stylistic behaviour. That’s wrong, but it’s hard to fix. Nevertheless, the attributes still fulfill their meta-information role, especially in the case that you mention.

    ~Grauw

  2. On July 4, 2007, 20:05 CEST, Jens Oliver Meiert said:

    That’s an interesting aspect that we should probably add to the style wiki page, too.

    (For what it’s worth, I couldn’t hold back another reply to the discussion.)

  3. On September 26, 2007, 17:02 CEST, Ronald Klip said:

    Another reason not to drop the style attribute is that it is widely used in scripting. Showing or hiding elements, or setting their position. Especially setting an element’s position (for example to use in a dragable div) would be impossible without style - unless you’d create a class rule for every position on the screen.

    .left1 {left: 1px;}
    [..]
    .left1920 {left: 1920px;}
    .top1 {top: 1 px;}
    [..]
    .top1200 {top: 1200px;}
    

    Somewhat inconvenient.

Read More

Have a look at the most popular posts, possibly including:

Or maybe say hi on Twitter, Google+, or LinkedIn?

Looking for a way to comment? Comments have been disabled, unfortunately.

Flattr? Found a mistake? Email me, jens@meiert.com.

You are here: HomeArchive2007 → Arguments for the “style” Attribute

Last update: December 11, 2016.

“If there is any secret, it is missed by seeking.”