13

I am curious about why different browsers have different <input type="file"> button to browse the files. There are many questions asking how to style them, apparently some sort of "hacks" are used to alter them. But no one really explained why do browsers control it?

Dray
  • 887
  • 8
  • 25
  • FYI, it is getting much easier to stylize these buttons through the &::-webkit-file-upload-button and &::-ms-browse psuedo-classes. But I had to do things the hard way before I learned about this. If anyone is looking for how to stylize the buttons, I wrote a series of blog posts that are mainly about [stylizing file inputs](http://mrme.me/lio/blog). – hostingutilities.com Apr 08 '16 at 01:57

2 Answers2

8

Still remember the time when there was only one browser? Browser has to set a default font if no font was used in the styling. Not only the fonts had defaults, the buttons also have defaults too. The elements needs to be displayed even if no styling is used.

Over the time, more browsers appear and they could have the same default font but no, they want to differentiate from each other.

Imagine that the developer forgets to style the button and there's no default for buttons. How will <input> looks like? A text floating around below a form? That's not very sightly.

Back to the question: file input button. It was given a fixed name for it initially and the current browsers are just continuing what was being implemented at first. Over the time, people got used to what file upload text they see in their browsers. Like what the reference below said, some people, such as elderly or not good with computers(not limited to) who don't use other browsers, may get confused upon seeing another string of text.

Reference : Change default text in input type="file"?

Therefore saying control is a little bit too strong. A fallback sounds much better. :)

Community
  • 1
  • 1
cweitat
  • 1,199
  • 1
  • 11
  • 28
  • but having a default button text is a bit too much, in the case of type="file" – Dray Apr 03 '16 at 09:33
  • I mentioned in the question that some "hacks" are available and i am aware of that. – Dray Apr 03 '16 at 12:46
  • well i appreciate your response and I will wait until i can collect more information. Would be great if you could also found more. Thank you :) – Dray Apr 03 '16 at 13:33
  • @cweitat +1 for the `fallback` bit. – Roy Apr 04 '16 at 21:37
5

AS @cweitat already indicated, this dates back to the early beginnings of HTML and browsers (you remember mosaic browser?).

At that time interacting between page data and the browser was restricted to HTML syntax and semantics. No javascript modifications had been available.

Nevertheless, the need for supporting upload of files (local to the browser) to the server (that served the page) was well accepted. The way to go was providing a version of the button logic for that purpose. Buttons had been the kind of HTML elements that allowed for activity originating from the browser side (besides links).

At that time elements on the page displayed where not thought of in terms of "widgets", so likely nobody considered to provide sufficient settings on the HTML element for influencing all visual and interaction aspects involved with a widget for choosing and uploading a file.

With later standardisation of DOM as an representation of "the page" and javascript as a mechanism for modifying various aspects programmatically, it was not surprising that "users" also tried to get more and more control over styling and visual representation of such kind of buttons.

On the other hand, the growing (and nearly exploding) possibilities of influencing page representations nowadays, also reduce the pressure for "extending" the current HTML element syntax. (I have seen lots of web pages that avoid using most standard HTML elements in favor of div with some javascript.)

So browser control <input type="file"/>, because they have to provide a suitable representation of this element. As there is no specification on the internal representation an implementation of this element has to follow, but there being some alternative to get the functionality without using such kind of element, it is unlikely browser vendors will bother exposing internal state for page developers to fiddle with (and this way allowing more control).

In contrast to other buttons the visual representation of a file input button is a set of different visual components. One is the button itself. Another is the field showing the selected file. Also (at least logically) a pop-up window showing available files, probaby some filter logic and more buttons are also part of the functionality. (Even if the later parts usually are brought in from the window or operating system environment, but this is an implementation detail.)

Now the mere HTML element does not allow to specify styling with sufficient detail. E.g. specifying background color: Should this apply to the button element or also to the feedback area (selected file), or maybe even to the file selection pop-up? Browser developpers could have decided to exhibit some of the internal structuring of components used to the "user. However, in formaer days it was not "interesting" enough and today you may use other mechanisms.

rpy
  • 3,953
  • 2
  • 20
  • 31
  • just to know your opinion, why `input="file"` has to be given a specific visualization unlike other types, and even though they had to give a specific visualization shouldn't we allowed to at least edit it? – Dray Apr 06 '16 at 14:26
  • The group of characters belong together and using a special visualization might help a reader to recognize and "parse" that token as a single term. – rpy Apr 06 '16 at 14:36
  • I do not mean to offend you but your reply is full of abstractions. And doesn't answer what I asked, could you have a look again and try to be a bit more clear? I appreciate your response though. – Dray Apr 06 '16 at 16:36
  • 1
    Then, maybe I did not get what you asked for. I read _why different browsers have different button_ and _why do browsers control it_ as the question essence. To explain the _why_, history and historic development of HTML and browsers is key. If you intented to ask _how can I style a file input button_, then my answer clearly misses the point. – rpy Apr 06 '16 at 17:12
  • No, I know how to style it. Well thank you for your response :) – Dray Apr 06 '16 at 17:43
  • Nevertheless, what focus did you have in mind with the question (and the expected answer)? There is still the _doesn't answer what I asked_ that I should eliminate (a bit at least). – rpy Apr 06 '16 at 18:56