W02 Learning Activity: HTML Block and Inline Elements
Overview
An HTML element is, by default, either a block-level or an inline element. Block elements occupy the full width of their container and start on new lines. Inline elements only occupy the space needed for the content and do not start on a new line.
Preparation Material
Carefully ponder, note, and reference the materials provided and concepts presented in the learning modules.
Block-level Elements
Block-level elements start on a new line on a page and take up the full width of their container. This means the
element container stretches out to the left and right as far as it can. Some common block-level elements are:
<p>
and <div>
and all the semantic containers like
<header>
, <footer>
, <main>
, <nav>
, and
<section>
.
Inline Elements
Inline elements do not start on a new line and only take up the space bounded by the tags defining the element.
Some common inline elements are: <span>
, <a>
, <img>
,
<button>
, and <input>
.
Video Demonstration: ▶️ Block versus Inline Elements – [ 4:36 minutes, 📄 Transcript ]
Activity Instructions
Answer the following questions about HTML elements.
- Which of the following HTML elements are inline elements by
default?
<header> <div> <span> <table> <form> <a> <label> <button> <input> <p> <aside> <cite>
Check Your Understanding
The other elements that are listed are block-level elements by default.<span> <a> <label> <button> <input> <cite>
How are you supposed to figure out which is which? You can try them out on your page. And you should also learn to get information using reliable sources. For example, you can use the HTML Reference to look up an element to verify if the element is block or inline. - Open the page named block-vs-inline.html in the week02 subfolder of your wdd130 folder.
- Review the HTML structure.
- To help you complete the exercise, render the page in Live/Five Server by right mouse clicking on the file name and selecting
"Open with Live/Five Server".
The page has been styled with CSS to help illustrate the differences between block and inline elements.
- Complete the tasks as given.
- Note that the inline elements
<span> <img> <a> and <button>
are only as big as the content within them.
Optional Resources
- Block Elements – MDN
- Inline Elements – MDN
- The block-level vs. inline elements distinction was used in HTML specifications up to 4.01. Later, this binary distinction is replaced with a more complex set of content categories.