Gradient
Gradient

Reputation: 2343

Are block and inline elements defined in the CSS or HTML spec?

I would say the display of an element is a CSS thing. However, in many places, I read things like HTML div is a block element. Is it just a shortcut that people use?

And is it actually specified in the CSS specs (for example that div are block elements) or is it just a general convention used by browsers? Where is it in the spec?

Upvotes: 0

Views: 238

Answers (3)

Quentin
Quentin

Reputation: 943163

HTML 3.2 defined the terms.

They were partially adopted by CSS when it defined the display property but this expanded to support many more values.

The HTML 4 specification continued to use the terms.

HTML 5 dropped the terms block and inline in favour of a wider set of categories.

Upvotes: 1

t.niese
t.niese

Reputation: 40842

The html5 specs do not talk about inline and block elements when describing those elements, they talk about:

Content-Model: Kinds of Content

  • Metadata content
  • Flow content
  • Sectioning content
  • Heading content
  • Phrasing content
  • Embedded content
  • Interactive content

HTML4 used inline and block-level but :

HTML does not use the terms "block-level" or "inline" as part of its content model rules, to reduce confusion with CSS.

The w3c suggest in 10 Rendering how browsers should render the elements, but:

User agents are not required to present HTML documents in any particular way. However, this section provides a set of suggestions for rendering HTML documents that, if followed, are likely to lead to a user experience that closely resembles the experience intended by the documents' authors.

So the content-model define which elements are allowed at which places, but suggest only how they should be rendered. However the display value like block, inline, table, ... are mostly equal in all browsers, but things like padding, margin, ... might differ.

For html4 the Appendix D. Default style sheet for HTML 4 exists:

This style sheet describes the typical formatting of all HTML 4 ([HTML4]) elements based on extensive research into current UA practice. Developers are encouraged to use it as a default style sheet in their implementations.

Html is not about rendering, html is a markup language that allows to organise information in a standardised way. A browser conforms to the html specs if it is able process the html according to the specification. Beside that there are the CSS specifications for the visual rendering, the browser conforms to those if it renders the DOM elements according to those specifications. And a browser conforms to the webstandards if it conforms to all those individual standards.

Upvotes: 2

sheplu
sheplu

Reputation: 2975

It was defined in the HTML specification, but now it's a bit wider

The distinction of block-level vs. inline elements is used in HTML specifications up to 4.01. In HTML5, this binary distinction is replaced with a more complex set of content categories. The "block-level" category roughly corresponds to the category of flow content in HTML5, while "inline" corresponds to phrasing content, but there are additional categories.

More infos : https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements

Upvotes: 0

Related Questions