Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to specify HTML options that are "default" according to W3Schools?

Tags:

html

dir

Do I need to specify HTML options that are "default" according to W3Schools?

I have always thought that you could omit "default" HTML options such as dir="ltr" in <html>, or media="all" in <link> for stylesheets.

But I frequently see big websites (e.g. YouTube) do this anyway. Is there any advantage by doing this, or are they only wasting a few bytes?

I have been wondering this for quite some time, and I was thinking that there might be browsers that handle things differently, such as displaying web pages in RTL by default.

like image 834
Xen Avatar asked Dec 03 '25 12:12

Xen


1 Answers

You should not pay any attention to what W3schools says about defaults.

There are many default attribute values in HTML, and in those cases, you need not specify the attribute if you want to get the default; that’s the very point of defaults. You may do so, for explicitness or some other reason (like styling or scripting).

But the dir attribute has no default value set in HTML specifications. In practice, browsers mostly default to dir=ltr, but this is not required. (The prose of HTML 4.01 just mentions the two values. The DTDs specify no default value.) In HTML5 drafts, however, it seems that the default for dir on the root element would be set to ltr.

The default for media in link is set to screen in the HTML 4.01. There are some inconsistencies here, and browsers may in fact imply all. So it is quite understandable that people wish to make it explicit whether a style sheet should apply to screen only or to all media.

like image 170
Jukka K. Korpela Avatar answered Dec 08 '25 08:12

Jukka K. Korpela



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!