32

Each element in HTML has a default display mode like "block", "inline", etc. For example, the "div" display is "block", and the "span" display is "inline".

I need a display mode like the "button" elements. It's more like the "inline" because you can put some of them in one line, but unlike the "inline" they can have width property.

OK, enough, let's back to my question. Which display mode do HTML buttons have?

9
  • Look at the available display property-values, and it'll show you the type that you want, though it's not necessarily the same, by default, in every browser. Commented Feb 10, 2015 at 15:03
  • Sounds like you want inline-block; Commented Feb 10, 2015 at 15:05
  • 3
    The <button> element is an inline element. Commented Feb 10, 2015 at 15:08
  • 3
    @TylerH: no, it's an inline-block, see: w3.org/TR/CSS2/sample.html Commented Feb 10, 2015 at 15:10
  • 2
    @LinkinTED In that case, MDN is wrong: developer.mozilla.org/en-US/docs/Web/HTML/Element/button Commented Feb 10, 2015 at 15:15

2 Answers 2

30

A button is by default an inline-block, so multiple buttons without a line break or some will be displayed next to each other:

<button>button 1</button>
<button>button 2</button>

If you want them to be under each other, you could display them as block:

button {
  display: block;
}
<button>button 1</button>
<button>button 2</button>

Sign up to request clarification or add additional context in comments.

Comments

-2

And by changing button's display value to block, you could easily center it like so: (suppose it has a class of btn)

.btn{
    display: block;
    margin: 2em auto;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.