Arguments for the “style” Attribute
Published on Jun 27, 2007 (updated Jul 25, 2021), filed under development (feed). (Share this on Mastodon or Bluesky?)
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 web developer, manager, and author. I’ve worked as a technical lead and engineering manager for small and large enterprises, I’m an occasional contributor to web standards (like HTML, CSS, WCAG), 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. (I value you being critical, interpreting charitably, and giving feedback.)