Arguments for the “style” Attribute
Published on June 27, 2007 (↻ July 25, 2021), filed under Development (RSS feed for all categories).
This post is partially outdated.
The HTML Working Group is currently arguing whether to drop the style
attribute. To encourage discussion outside the Working Group, here are the (edited) reasons I see to keep @style
:
To allow authors to manage unique formatting:
This is probably not the best description
[…], so let’s use an example: There’s strong desire to avoid page load “flickering” caused by images being loaded. The usual way to address this is by settingwidth
andheight
attributes, which should be replaced by thestyle
attribute (which is presentational by design).<img src="foo" alt="bar" style="width: 100px; height: 200px;">
Assuming that we don’t talk about galleries where all thumbnails 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 to usestyle
[…].To enable and 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 banner ad where the ad company wants to avoid a border around the ad, there are basically three options:
- Hope for each partner to remove an eventual border. (Doesn’t work.)
- Delivering the ad with
border="0"
(or worse). (Presentational.)- Delivering the ad with
style="border: 0;"
. [(Acceptable.)]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 great [feature].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, 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 proper use.
A reply to Henri Sivonen (original mail) shares more thoughts:
In my opinion, it is extremely silly to think that
height=''
andwidth=''
are bad butstyle='width: …; height: …;'
is good. I’d rather haveheight=''
andwidth=''
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,” usingstyle
for image [dimensions looks better to me] than usingwidth
andheight
attributes[…].
If this is not enough, there’s more.
Update (August 15, 2014)
I sometimes 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 in other cases still keep our hands away from it where we can: Asking to keep @style
is not the same as asking to use @style
.
About Me
I’m Jens (long: Jens Oliver Meiert), and I’m a frontend engineering leader and tech author/publisher. I’ve worked as a technical lead for companies like Google and as an engineering manager for companies like Miro, I’m a contributor to several web standards, and I write and review books for O’Reilly and Frontend Dogma.
I love trying things, not only in web development (and engineering management), but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (Please be critical, interpret charitably, and give feedback.)
Comments (Closed)
-
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
-
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.)
-
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
Maybe of interest to you, too:
- Next: HTML: All Elements From HTML 1 to XHTML 2.0
- Previous: A Plea for Better Software: Provide Auto-Save
- More under Development
- More from 2007
- Most popular posts
Looking for a way to comment? Comments have been disabled, unfortunately.
Get a good look at web development? Try WebGlossary.info—and The Web Development Glossary 3K. With explanations and definitions for thousands of terms of web development, web design, and related fields, building on Wikipedia as well as MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.