24

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
  • 32,294
  • 27
  • 115
  • 203
  • @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,746
  • 28
  • 47
  • 65
Crozin
  • 43,890
  • 13
  • 88
  • 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
  • 78,296
  • 16
  • 112
  • 156
1

iframe is also inline-block too

Kernel James
  • 3,752
  • 25
  • 32