25

A span is an inline element and div is a block element. Is there a 'native' (X)HTML / HTML5 inline-block element that can act like a container? (Without applying CSS)

Definitions:

block
This value causes an element to generate a block box.
inline-block
This value causes an element to generate an inline-level block container. The inside of an inline-block is formatted as a block box, and the element itself is formatted as an atomic inline-level box.
inline
This value causes an element to generate one or more inline boxes.

Kees C. Bakker
  • 30,662
  • 25
  • 112
  • 197
  • @Oded: http://www.w3.org/TR/CSS2/visuren.html#display-prop – Crozin Jan 09 '12 at 14:26
  • An image is `inline-block`, it will not break in a line. – Kees C. Bakker Jan 09 '12 at 14:26
  • 1
    Hm, guess you are right: http://stackoverflow.com/questions/2402761/img-elements-block-level-element-or-inline-element. Quote: In CSS, you can set an element to display: `inline-block` to make it replicate the behaviour of images --> So you there's your answer as well. You need to specify it. – Erik Dekker Jan 09 '12 at 14:37
  • 1
    @KeesC.Bakker, @ErikDekker: The specs say nothing of this. HTML5 specifies `img` as Flow content, which kind of implies and `inline` display mode. It seems that [none of the browsers](http://meiert.com/en/blog/20070922/user-agent-style-sheets/) actively apply `inline-block` to `` elements, either (which given that the default is `inline`, see CSS2 spec, implies that images are indeed `inline`, not `inline-block`). Saying that `inline-block` "replicates the behavior of images" is kind of an over-simplification IMHO. – You Jan 09 '12 at 14:48
  • 2
    Is there still not an inline block element in 2019? – 1.21 gigawatts Jun 30 '19 at 08:20

3 Answers3

19

No, there is not. You have to specify inline-block explictly.

Rob
  • 14,107
  • 28
  • 46
  • 64
Crozin
  • 42,946
  • 13
  • 87
  • 135
10

Strictly speaking <button> fulfils the criteria set. HTML5 says

When the button binding applies to a button element [which it ordinarily does], the element is expected to render as an 'inline-block' box rendered as a button whose contents are the contents of the element.

However while it is a container element that has a default inline-block rendering, it is not a General Purpose container so can't be used for anything but as a button.

Alohci
  • 73,780
  • 12
  • 107
  • 149
1

iframe is also inline-block too

Kernel James
  • 3,226
  • 20
  • 22