Becoming a web developer

What does it mean to display inline vs inline blocks?

CSS treats each HTML element as if it is in its own box. This box will either be a block-level box or an inline box.

Block elements:

In normal flow (default if not specified otherwise) each element sits on top of the next one. Each element starts on a new line even if previeous elements did not take up the full width of the browser window.

display of block-level elemts

Examples include: <h1> <p> <ul> <li>

Inline elements:

Inline boxes flow between surrounding text.

display of inline elemts

Examples include: <img>

The display property

The display property allows to turn an inline elent into a block-level element or vice versa.

The values this property can take are:


Using display: inline to create a navigation structure

In the following example you can see a list. Each item in the list is usually treated as a block-level element, but the rule for the <li> elements indicates that they should be treated as inline elemts, which means they will sit alongside each other rather than appearing on new lines.
This technique is often used to create navigation for a site.

List in default block display:

list displayed as block

List in inline display:

list displayed inline

List in inline display with one element hidden:

list with hidden element