8

The div is the quintessential block level element, and the span is the inline counterpart. They are the simplest possible form of that display type, with no other properties. In a great many cases I will give either of them the style:

display: inline-block;

This makes them behave in a very handy way. For div it means boxes that will easily sit next to each-other, while maintaining their width and height as defined. For the span I can use this to make colorful rectangles. The inline-block display is great for so many things, but I have never seen an element that starts as an inline-block without anything else going on.

Images (img) are, but they are obviously not suited for the same things as a div, they have that style, but they fulfill a different purpose.

So is there an element that I don't know of that is the quintessential inline-block, or is this left out?

And if not, why? The uses of inline-block are numerous, so it seems like there should be some element that takes that basic form.

Marc Audet
  • 46,011
  • 11
  • 63
  • 83
zeel
  • 1,101
  • 1
  • 13
  • 31

3 Answers3

6

The only elements I can think of that have an in-line appearance, but allow for a width and height to be set, are:

  • img,
  • input,
  • textarea
  • select, and
  • button

The only element here, though, that can take HTML content is the button element; which is not an ideal use of the button since it's intended to be an element with which the user might/should interact; rather than simply a container element.

While you may have multiple uses for such an element, there's no convincing reason, given the ease with which the display property might be changed, that the W3C, or any other authority, should explicitly define one; especially given that the only difference between inline and inline-block is the ability to assign dimensions and margin.

David Thomas
  • 249,100
  • 51
  • 377
  • 410
6

There's no such element, and there are some good reasons why not.

inline-block has several uses in contemporary web design. However it is not part of the original design, which only includes block and inline elements. Instead it derives from <img> as added by NSCA Mosaic. (Which uses the wrong markup and helped defeat the original "responsive design". I think we've only just started to fix the problems with img).

Further down the timeline, inline-block still wasn't part of IE4 or 5, or any version of Netscape. It wasn't part of the early HTML4 era. So we wouldn't expect to find your hypothetical element in that version of the standard. inline-block only appears in CSS2, which came after HTML4. (Look at the reference section in each standard).

Unlike block, inline-block is affected by whitespace in the markup. It's implied by the name, and it's what you'd expect from looking at <img> in the middle of some text (aka wordprocessor object anchored "as character"). But beyond its origins there, the whitespace-dependent markup soon becomes very troublesome. I wouldn't expect W3C HTML5 to enshrine this in a new element.

Specifying it would certainly involve argument about "semantics", separation of content and presentation etc. (As well as what to call it :). And if the default rendering makes whitespace significant - is that not part of the semantics of that element? Consider using images to represent words - or individual letters of a word (with appropriate alt text). This illustrates that the presence of whitespace (or not) around this element would be semantically significant, just like the presenceofwhitespaceseparatingwordsissemanticallysignificant. That seems like a big problem to me.

inline-block is often promoted as a modern alternative to using float everywhere. But neither is genuinely suitable. This is why CSS3 will standardize new layout modes: "flexbox" and "grid", to support modern responsive designs with genuine, clean markup. No dummy markup (or dummy generated content). No hacking around whitespace-dependence.

Community
  • 1
  • 1
sourcejedi
  • 3,051
  • 2
  • 24
  • 42
  • Nice answer. And I didn't know about `flexbox`. I little reading and I think I'm in love. . . – zeel May 10 '13 at 21:57
  • +1 I made some [similar arguments](http://stackoverflow.com/a/16469536/1306809) the other day. Anytime whitespace in the HTML source code becomes a problem, that suggests that it's an inappropriate use of inline-block. – Matt Coughlin May 11 '13 at 14:22
  • 1
    @MattCoughlin nice! That complements my argument so well, I've linked to it from my answer. – sourcejedi May 11 '13 at 14:58
  • @zeel, wups, looks like there's an even newer one as well :). I've just added a link for CSS3 ["Grid"](http://hugogiraudel.com/2013/04/04/css-grid-layout/#grid). I guess it's good they're not trying to cram everything into one mode. – sourcejedi May 11 '13 at 18:15
  • @sourcejedi: Good deal! I added a return link where it seemed relevant. btw, another CSS3 layout option is [columns](http://www.w3.org/TR/css3-multicol/). – Matt Coughlin May 11 '13 at 18:35
0

The img tag is inline-block by default:

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img

Edit: You can check this SO question: Is <img> element block level or inline level?

Community
  • 1
  • 1
Kristian Vitozev
  • 5,791
  • 6
  • 36
  • 56
  • I mentioned images. They are not "quintessential", since they do not have any content, have a specialized display (an image) and are semantically distinct (as images). – zeel May 10 '13 at 10:47