HTML Block & Inline
HTML Block and Inline Elements
Every HTML element has a default display value, depending on what type of element it is.
The two most common display values are block and inline.
Block-level Elements
A block-level element always starts on a new line, and browsers automatically add space before and after the element.
A block-level element always takes up the full width available.
Two commonly used block-level elements are <p> and <div>.
The <p> element defines a paragraph.
The <div> element defines a division or section.
<p>Hello World</p> <div>Hello World</div>
Common block-level elements in HTML include:
<address> <article> <aside> <blockquote> <canvas> <dd> <div> <dl> <dt> <fieldset> <figcaption> <figure> <footer> <form> <h1>–<h6> <header> <hr> <li> <main> <nav> <noscript> <ol> <p> <pre> <section> <table> <tfoot> <ul> <video>
Inline Elements
An inline element does not start on a new line.
An inline element only takes up as much width as necessary.
This is a <span> element inside a paragraph.
<span>Hello World</span>
Common inline elements in HTML include:
<a> <abbr> <acronym> <b> <bdo> <big> <br> <button> <cite> <code> <dfn> <em> <i> <img> <input> <kbd> <label> <map> <object> <output> <q> <samp> <script> <select> <small> <span> <strong> <sub> <sup> <textarea> <time> <tt> <var>
Note: An inline element cannot contain a block-level element.
The div Element
The <div> element is often used as a container for other HTML elements.
It has no required attributes, but style, class, and id are commonly used.
When combined with CSS, <div> can be used to style blocks of content.
<div style="background-color:black;color:white;padding:20px;"> <h2>London</h2> <p>London is the capital city of England. It is the most populous city in the United Kingdom.</p> </div>
The span Element
The <span> element is an inline container used to mark up part of a text.
It has no required attributes, but style, class, and id are commonly used.
When combined with CSS, <span> can be used to style small parts of text.
<p>My mother has <span style="color:blue;font-weight:bold;">blue</span> eyes and my father has <span style="color:darkolivegreen;font-weight:bold;">dark green</span> eyes. </p>
Chapter Summary
- Block-level elements start on a new line and take up the full width available
- Inline elements do not start on a new line and only take up the width they need
- The
<div>element is a block-level container - The
<span>element is an inline container
Exercise
Which type of elements takes up the full width available?
Block elements Inline elements
HTML Tags
| Tag | Description |
|---|---|
<div> | Defines a section in a document (block-level) |
<span> | Defines a section in a document (inline) |