5

May I know if there is any difference between HTML block elements (Eg. <p>, <div>,...) and CSS property display: block?

Since from what I have read they are the same, but why we still need to use display: block for some block level element.

4
  • developer.mozilla.org/en/docs/Web/HTML/Block-level_elements Commented May 26, 2015 at 11:37
  • 7
    It's the same. Block elements are block because they have display: block as default styles. Nothing more. We can say that span with display: block is the same as div (both with zero semantic value). Commented May 26, 2015 at 11:37
  • dustwell.com/div-span-inline-block.html Commented May 26, 2015 at 11:38
  • 2
    You are starting from a false assertion. We do not need to use display:block on block level elements unless the property is being reverted to that state after being changed previously. Commented May 26, 2015 at 11:42

2 Answers 2

4

What you call "HTML block elements" are elements who have their display property set to block so there is no difference between a <div> and a <span> with display:block;.

This display property is set by the user agent stylesheet (i.e your browser). You can view these properties in chrome dev tool under "user agent stylesheet".

The only reason I see of using display:block; for a div element is :

  • your target adience is using some obscur user agent that don't follow web stadards (very unlikely)
  • you need to override a previous CSS declaration like display:none;
Sign up to request clarification or add additional context in comments.

Comments

1

There is no difference between... because block elements already have default css property display: block.

But we use display: block to show them again, when we hide/remove them from page using display: none.

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.