HTML element which defaults to display:inline-block?

HtmlCss

Html Problem Overview


<div> defaults to block

<span> defaults to inline

Is there one that defaults to inline-block?

If not, what special tag name would be appropriate for me to apply 'inline-block' using CSS?
Or should I stick to using a class?

Html Solutions


Solution 1 - Html

From what I can tell the <img> tag is the only inline-block by default. To be on the safe side I would recommend a class, you never know when changing all elements of a certain type will come back to bite you. Or, you could always make up your own tag and assign display:inline-block; to it. This way you aren't changing the default functionality of standard elements...

EDIT

It also appears that button, textarea, input, and select elements are also inline-block

Sources:

According to this img is inline-block http://dev.w3.org/html5/markup/img.html#img-display

And here claims that button, textarea, etc. are as well: http://www.w3.org/TR/CSS2/sample.html

EDIT #2

While the source above claims that img tags are inline-block it seems (thanks to Alohci) that they are just inline http://jsfiddle.net/AQ2yp/

The following were tested in Firefox:

button is inline-block: http://jsfiddle.net/GLS4P/

textarea is inline: http://jsfiddle.net/235vc/

input is inline: http://jsfiddle.net/RFKe8/

select is inline-block: http://jsfiddle.net/5B4Gs/

Solution 2 - Html

> Is there one that defaults to inline-block?

Strictly speaking, no there isn't. The W3 HTML specifications do not ever specify default CSS property values for any elements. They do provide a "default style sheet" for HTML 4, but developers are only encouraged to use it - it is not a requirement or any sort of mandate. The HTML 5 specifications indicate "typical default display properties" but, again, those are not required (also keep in mind that HTML 5 is still a working draft anyways).

So that leaves all default values up to the browser and how the developers actually feel elements should be displayed to a user. No one can guarantee that a specific element will display as inline-block or any other way in someone's browser. You should always explicitly set that if you want it to happen. Don't rely on "defaults."

> If not, what special tag name would be appropriate for me to apply 'inline-block' using CSS? Or should I stick to using a class?

This is up to you and how you are designing your pages. You should always use elements that are semantically appropriate to the content contained within them. If the element will always be used in a context which will require inline-block display, by all means set it to that in your style sheet. Otherwise, you will have to resort to classes or more specific selectors in order to make your elements display properly.

Solution 3 - Html

Here is a Fiddle that gets the default display value for a majority of HTML tags.

Fiddle

In chrome, the default inline-block elements are: "INPUT", "BUTTON", "TEXTAREA", "SELECT"

Solution 4 - Html

My solution to this is declaring what I call a slice.

CSS

sl {
    display: inline-block;
}

Usage

<sl>inline block stuff</sl>

Solution 5 - Html

You can check my codepen with all HTML elements and their display property by default. Some tags are syntax-broken, but it does not matter for our purpose.

Currently, there are 5 elements with display: inline-block in FF :

  1. <button>
  2. <select>
  3. <meter>
  4. <progress>
  5. <marquee>

And additional 2 (including 5 above) in Chrome:

  1. textarea
  2. input

Solution 6 - Html

In principle, it depends on the browser what the default value for the display property is for each element. Even HTML5 drafts do not prescribe what values must be used, though it presents “expected rendering” of elements in terms of CSS.

According the default style sheet for HTML in the CSS 2.1 specification, the elements that have display: inline-block by default are button, input, select, and textarea. Browsers use such settings, except that in Firefox, this only applies to button and select.

In the Rendering section of HTML5 CR, the meter and progress elements are additionally describes as having inline block as “expected rendering”, and browsers that have implemented these elements appear to behave that way. The keygen element is also described as being an inline block, but Firefox does not do that (it implemented keygen internally as select in the DOM); IE does not support keygen at all; Chrome implements it as suggested.

Since all of these elements have rather specialized meanings, functionality, and rendering idiosyncracies, none of them is adequate for general use as an element that is an inline block by default and may have various meanings. What you can use for such an element is normally span or div, depending on whether you prefer inline or block as the default rendering.

Solution 7 - Html

Now you can create a Custom Element (for example: <inline-block> or whatever) that will have its CSS property display set to inline-block by default.

customElements.define( 'inline-block', class extends HTMLElement {
    constructor() {
        super()
        this.attachShadow( { mode: 'open' } )
            .innerHTML = `<style> :host { display: inline-block } </style>
                          <slot></slot>`
    }
} )

#hw { background-color: lightblue }

<inline-block id="hw">Hello World</inline-block>

Solution 8 - Html

button, textarea, input, and select default to inline-block.

In the event you would want to inline-block a div you'd give it a class name.

.inline-block {
    display: inline-block
}

Then...

<div class="inline-block"></div>

CORRECTION

I was mistaken about img. It seems it defaults to inline and not inline-block

Solution 9 - Html

This isn't really a true answer to the question right now, but with enough support, it may someday be.

<seg> short for "segment". As in, segments of a line.

with the polyfill:

<style> seg { display: inline-block; } </style>

It really would be nice if there was an official one, but there is not, so here is the best (IMO) suggested name for such an element that I know of.

Solution 10 - Html

YES there is an element that defaults to inline.

The answer is the span element.

<span>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Question700 SoftwareView Question on Stackoverflow
Solution 1 - HtmlDryden LongView Answer on Stackoverflow
Solution 2 - HtmlanimusonView Answer on Stackoverflow
Solution 3 - HtmlPreston SView Answer on Stackoverflow
Solution 4 - HtmlquemefulView Answer on Stackoverflow
Solution 5 - HtmlAvernikozView Answer on Stackoverflow
Solution 6 - HtmlJukka K. KorpelaView Answer on Stackoverflow
Solution 7 - HtmlSupersharpView Answer on Stackoverflow
Solution 8 - HtmljonsuhView Answer on Stackoverflow
Solution 9 - HtmlSeph ReedView Answer on Stackoverflow
Solution 10 - HtmlhttpgioView Answer on Stackoverflow