HTML & CSS Interview Question #7
What is the difference between block-level and inline elements?
HTML Fundamentals, Structure, Semantics, Links, Images, Tables & Forms Junior Beginner
Quick Interview Answer
Historically, block-level elements normally start on a new line and occupy the available horizontal space, while inline elements participate within a line of text. Common examples are div and p for block-level behavior, and span and a for inline behavior.
Detailed Explanation
Historically, block-level elements normally start on a new line and occupy the available horizontal space, while inline elements participate within a line of text. Common examples are div and p for block-level behavior, and span and a for inline behavior.
In modern CSS, the final layout behavior is controlled by the CSS display property, so an element's default display can be changed. HTML semantics and CSS layout behavior should therefore be treated as related but separate concerns.
Code Example
<p>
Learn <span class="highlight">HTML</span>
before advanced CSS.
</p>
<div class="card">Block container</div>