3

I know that img.align is deprecated or even obsolete, still ... Firefox is changing the values of my attributes. In particular see example

const img = document.querySelector("img");
console.log("img.align:", img.align);
<img src="http://www.gravatar.com/avatar" align="center" >

results:

  • chrome: img.align: center
  • firefox: img.align: middle

Any idea why firefox changes the value of the attribute? Are there other attribute values firefox changes?

This has implications for code like

document.querySelectorAll("img[align=center]")

Which fails on Firefox (only) and so would any CSS using the same selector; img[align=center] { ... }, for example.

Possibly relevant: Can I add custom attribute to HTML tag?

Martin
  • 22,212
  • 11
  • 70
  • 132
gman
  • 100,619
  • 31
  • 269
  • 393
  • Worse than that. [It's been obsolete for over a year at least](https://www.w3.org/TR/html52/obsolete.html#non-conforming-features) – Rob Aug 27 '17 at 02:30
  • Good to know but not relevant to my question – gman Aug 27 '17 at 02:55
  • IMO this is an interesting (?) fact but not a good stackoverflow question. The people here **cannot** know the answer for that unless they are the authors of this feature => opinion based – smnbbrv Aug 27 '17 at 05:40
  • Really? It seems like [asking](https://stackoverflow.com/questions/tagged/internet-explorer) [about](https://stackoverflow.com/questions/tagged/safari) the [quirks](https://stackoverflow.com/questions/tagged/google-chrome) of [browsers](https://stackoverflow.com/questions/tagged/firefox) is one of the most common questions on Stack Overflow – gman Aug 27 '17 at 05:44
  • Very few of them ask for the history behind design decisions that were made, though. Most of them are just interested in workarounds. (I was expecting those links to point to individual questions, but the fact that they instead point to question lists is telling.) – BoltClock Aug 27 '17 at 06:08
  • Here's one I answered as well: [What are the historical reasons for excluding input[type='image'\] from form.elements](https://stackoverflow.com/questions/39503469/what-are-the-historical-reasons-for-excluding-inputtype-image-from-form-elem) It's a game of chance, either the information is publicly documented somewhere, or it's not and therefore only the people who made the decisions can answer. I do prefer not to concern myself with whether that makes a question on- or off-topic, though. – BoltClock Aug 27 '17 at 06:10

2 Answers2

3

Any idea why firefox changes the value of the attribute?

Because middle is the correct value as defined in RFC 1866 (HTML 2.0), HTML 3.2 and HTML 4, not center. The align attribute on the img element has never had center as a possible value, because center has historically always referred to horizontal alignment (floating), and you can't float an image at the center of a line. Other implementations at the time, such as IE, did allow center as a possible value with the same meaning as middle (see Stefan's answer), and so my guess is that Firefox is providing interop while still adhering to the standard by aliasing the values.

It's not clear to me why Chrome doesn't do the same. It does seem to treat center as middle for the purposes of rendering, in any case. But if by rewriting the value Firefox is breaking attribute selectors, I'd consider that a defect (albeit one they probably aren't inclined to fix since the attribute is obsolete).

The real question is why MDN claims that the only possible values are left, right, justify, and center. The DOM level 2 spec, of course, contains a more accurate description of the align attribute, though it doesn't list the possible values since they're already listed in the HTML spec.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
1

the html specification does not know of a value center for the align attribute for img tags (but for other tags). however, firefox probably recognizes center as value (instead of other nonsense) and accepts it as middle since firefox and possible other browsers have done this at some point in their life according to this rather ancient bug report

stefan0xC
  • 337
  • 5
  • 11