11

This is clearly not the case as each element can have it's own default.

See here:

https://developer.mozilla.org/en-US/docs/Web/CSS/display

Initial value: inline

Applies to: all elements

And of course contradicting documentation which seems more correct in this case.

https://www.w3schools.com/css/css_display_visibility.asp

Is there something I'm missing here?

It seems to clearly state that "all elements" have "initial value" set to inline.

dippas
  • 58,591
  • 15
  • 114
  • 126
  • Related [Reset CSS display property to default value](https://stackoverflow.com/questions/8228980/reset-css-display-property-to-default-value) – Theraot Dec 18 '17 at 02:11
  • 1
    Possible duplicate of [Reset CSS display property to default value](https://stackoverflow.com/questions/8228980/reset-css-display-property-to-default-value) – Oleg Dec 18 '17 at 02:20
  • [display test: `unset`, `initial`, `inherit`, `revert`](https://jsfiddle.net/uhgd061b/) – Theraot Dec 18 '17 at 03:12
  • Your question is still not well constructed. Lay out the problem before the sharing the code. Beyond the ["How to ask"](https://stackoverflow.com/help/how-to-ask) advice, you also need to start by stating the question in a way that focuses on what gap remains _after_ your research. Describe [step like these](https://hackernoon.com/how-to-debug-any-problem-ac6f8a867fae) that you have done thus far, for code, conditions, and errors. State 'obvious' context that you already know, [so that people understand what you have tried](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) – New Alexandria Feb 25 '18 at 03:57

5 Answers5

12

First of all w3schools isn't the official Documentation, W3C is!

TL:DR: You are confusing things -- The initial value of the property which is inline and to which elements the property applies (no matter the value it has)

They are not related.


Here is the official Documentation about it

SS

Which match MDN Docs.

And yes the initial value of display is inline the line below (in your question) says it can apply display property to all elements, which is true and not starting "all elements" with inline, because if you read the MDN Docs you see this:

The display CSS property specifies the type of rendering box used for an element. In HTML, default display property values are taken from behaviors described in the HTML specifications or from the browser/user default stylesheet. The default value in XML is inline, including SVG elements.

(Emphasizes is mine)

And what that line means is any browser/user-agent are free to set the initial value of the element as they think it is better.

N.B. Remember that by initial value means using initial value itself, so whenever you set display:initial it will became display:inline as per the Documentation above states.

dippas
  • 58,591
  • 15
  • 114
  • 126
  • 1
    It does not say you can it says that is the initial value. –  Dec 18 '17 at 01:29
  • @mikejacques Actually it does not. That just means you can apply the `display`-attribute to all elements, which is true – SourceOverflow Dec 18 '17 at 01:31
  • @CAaker I don't see a single contribution to this question from you. (except for this comment, of course. Did you edit the question? Because that needs approval and that takes some time. – SourceOverflow Dec 18 '17 at 01:33
  • 3
    I don't think W3schools is "inaccurate" here. it talks about a "default" value for display, not an "initial" value, and I think that's reasonable. It would be deeply confusing to most web devs to think of the default display value for `

    ` elements as being "inline" even though that is their "initial" value.

    – Alohci Dec 18 '17 at 03:27
  • @Alohci sorry wrong choice of words I meant misleading updated the answer – dippas Dec 18 '17 at 03:55
  • It's not misleading either. W3Schools' statement about default values is 100% factually correct. – BoltClock Dec 18 '17 at 04:42
  • Just removed that sentence – dippas Dec 18 '17 at 09:34
9

Initial value: inline

...states that official recommendation for user agents is to interpret display:initial as display:inline, not as the default value for the type of element (i.e. block for <div>, inline-block for <span>, etc...).

So, in practice, setting display:initial; on a <div> will apply display:inline; to it in user agents respecting the standard recommendation, instead of display:block; as most developers would be tempted to assume. Setting display:initial; on any element should be interpreted as display:inline. That is what it means.

Ultimately, this is useful as it reduces ambiguity around a complex attribute, such as display.


As for why does MDN provide this information, generally speaking, there are very few (if any) contradictions between MDN and W3C/official sources, which makes it a valuable and reliable resource. Its main quality is it presents the information in a more accessible format (than the official docs) for people without a solid background on web technologies/concepts.

Personally, besides reading the articles/examples themselves, I find myself using it a lot as the fastest way to get the full list of official resources about any web concept, as you'll always find the links at the end of the MDN article on the subject (where applicable).

tao
  • 82,996
  • 16
  • 114
  • 150
  • 1
    I would argue that MDN is for people of any level of technical background in web development. On the other hand - at least in my opinion - W3C is for developers that work on the tools the web developers use (such as browsers, parsers, pretty printers, validators, minimizers, compilers, etc...) and I would argue that that is not web development. Also consider that currently Mozilla, Google, Microsoft (since October 2017), the W3C, and others contribute to MDN. (no, I did not down vote - I suspect there is some confusion on what `initial` does, see the link I posted as comment to the question) – Theraot Dec 18 '17 at 02:41
  • @Theraot, I did not say MDN is not for people of any level of technical background. I just pinpointed that it is more accessible and understandable than the official docs for people without a solid knowledge of web concepts. I believe we're saying the same thing. I am not a native speaker of English. If you think of a better way to express my idea I'd welcome the edit. Thanks for the link. I'm not able to find any contradiction between my answer and the linked one. – tao Dec 18 '17 at 02:50
  • @Theraot. As a (sometimes) web developer, I more often look in the W3C/WHATWG/Ecma International/IETF specs than at MDN. Although MDN is a fine resource, discrepancies *do* exist between the friendlier language of MDN and the precision of the official specs, and I prefer where possible to have that precision. – Alohci Dec 18 '17 at 02:57
  • Yes, I do not see a contradiction either. And as I said, I did not downvote, in fact I did upvote earlier. I am not a native speaker either, perhaps I should leave it at that. @Alohci as (more often that I would like) web developer, I rarely care that much about the specs (unless I need to write a parser or something like that), mainly because the discrepancies between the browser implementaton are the gritty day to day, and given that is what would matter for the end user, my only option is to test. – Theraot Dec 18 '17 at 03:04
  • The initial value is intended as a default value for unrecognized elements, to guarantee that every element has some value for display (and every other property) for the purposes of the cascade. It has never been designed as a way to specify browser defaults. Those are two completely unrelated concepts. Authors are the ones getting the two mixed up. – BoltClock Dec 18 '17 at 03:25
  • We seem to be in agreement, @Bolt. But you'll be surprised to find out how many frontend developers believe setting `display:initial` on a `
    ` will reset its `display` to `block`. That's why I wanted to make it clear it does not.
    – tao Dec 18 '17 at 03:52
  • 1
    No, I'm not surprised, that's why I said "Authors are the ones getting the two mixed up." ;) – BoltClock Dec 18 '17 at 03:53
6

Those two things aren't related.

The initial value of a property refers to the CSS-defined default value for that property. Every single CSS property has an initial value, regardless of element type, because CSS properties aren't tied to elements of any document language in any way. This initial value is intended as a default value for unrecognized elements, to guarantee that every element has a value for every property for the purposes of the cascade and therefore ensure that a browser knows how to render that unrecognized element as it encounters it.

The so-called "default value" of a property is just an arbitrary value set by a browser in its UA default stylesheet. The HTML5 spec contains a reference document on what default values should apply to what HTML elements, which browsers follow mostly, but this is completely unrelated to CSS's concept of an initial value (nor does it contradict its definition of initial value, because it defines default styles separately as "user-agent-level styles").

"Applies to", on the other hand, is unrelated to the initial value. Even if a property only applies to certain types of elements, those elements will always have every single CSS property, including properties that don't apply to them. What "Applies to" actually means is "Has effect on". If a property doesn't apply to an element, it simply means that it has no effect.

For example, you may find that the flex property only applies to flex items. However, every single element has a flex property, regardless of whether it's actually a flex item, and they pretty much all have its initial value simply because I'm not aware of any UA styles altering its value from the initial value for any element. You could still set an arbitrary value on an element that isn't a flex item, and it simply would have no effect — but you could, for example, force flex items that are children of this element to inherit this value with flex: inherit (you wouldn't actually do this, I'm just stating an example).

In fact, a real-world example of this exists in the ul and ol elements — many authors (including myself) set list styles on those elements, when really the list markers you see belong to their li children that are inheriting their list styles, since list styles only apply to list-items and ul and ol are not themselves list items.

And as mentioned, W3Schools isn't official documentation. To save you any more confusion, assume W3Schools does not exist. Continue using MDN if it is easier to understand, but always cross-reference with the official specs located at w3.org and whatwg.org (which MDN usually does a good job linking to, it pretty much never links to W3Schools).

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

Each user agent(browser) applies a default style sheet for an HTML page. You can see in the default HTML4 style sheet:

dir, hr, menu, pre   { display: block; unicode-bidi: embed }
li              { display: list-item }
head            { display: none }
...

The default display property is changed depending on the element.

Oleg
  • 6,124
  • 2
  • 23
  • 40
2

That would be true for a native xhtml browser. HTML browser is something else completely, it doesn't have to wait for separate instructions. In HTML all known elements have their display rendering predefined by default. (Which of course can be overridden).

There were browsers which didn't support styles at all. HTML tags are semantic. All xhtml is generic and of course to it all tags are equally [unknown] and indiscriminately inline by default.

Bekim Bacaj
  • 5,707
  • 2
  • 24
  • 26
  • 1
    You mean generic XML here, not XHTML. Browsers are just as aware, from a user-agent stylesheet perspective of an XHTML DOM as they are of an HTML DOM, and elements in an XHTML document are as semantic as ones in an HTML document. – Alohci Dec 18 '17 at 03:14
  • lol you are so wrong that you don't have the slightest clue about the reality and the empirical truth of browser existence. 1stly DOM has absolutely no relation with display properties of anything at all. 2ndly May I remind you that we were making web pages for browsers that didn't have a clue that one day there will be a xhtml at all. – Bekim Bacaj Dec 18 '17 at 05:40
  • What empirical truth? The truth that modern browsers *do* recognize XHTML as a distinct flavor of HTML with similar semantics and not simply as generic XML? Also how is the pre-XHTML Web relevant when you're the one discussing XHTML to begin with? – BoltClock Dec 18 '17 at 07:01
  • @Alohci: In fact they are so aware that, ironically, they implement CSS for **HTML** in terms of the XHTML namespace, [as required by the **HTML** spec](https://html.spec.whatwg.org/multipage/infrastructure.html#xml). – BoltClock Dec 18 '17 at 07:23