Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Essential CSS
Lesson Plan
  1. Introduction
    1. Welcome to Essential CSS
    2. Getting started with the course
    3. What are file formats?
    4. Web standards
    5. What is HTML?
    6. What is CSS?
    7. Devtools, your indispensable best friend
  2. CSS Key Concepts
    1. Some background about CSS
    2. CSS Syntax and Terminology
    3. Selectors
    4. Cascade and Specificity
    5. Origin and Importance
    6. Inheritance
    7. How browsers handle CSS
  3. Basic Mental Model
    1. Everything on the web is a box
    2. The box model
    3. How big is your box?
    4. The relationship between px and em
    5. The `box-sizing` property
    6. The `display` property
    7. Formatting contexts
    8. Block boxes
    9. Inline boxes
    10. What is inline-block?
  4. Flexbox and Grid
    1. The parent-child relationship
    2. Sizing in Flexbox
    3. Flex directions
    4. Basic grid concepts
    5. Setting up a grid
    6. Placing grid items
    7. Box alignment
  5. Building web layouts
    1. Arranging your boxes on the web
    2. Positioning schemes
    3. Floating boxes
  6. Typography
    1. Making your text look good
    2. What is a font?
    3. Typesetting with CSS

Inline boxes

3m:8s

Inline-level elements generate inline-level boxes, which are dealt with differently from block boxes. As the name suggests, the behaviour of such boxes within an inline formatting context is more like a stream rather than discrete blocks. Content is laid out in the inline direction, which is the direction that text flows, and this is dependent on the writing system of the content being displayed.

According to the specification, all HTML elements have an initial value of inline for the display property. But browser stylesheets set certain elements to display: block to make unstyled HTML look better out-the-box. We can see how things would look by resetting every element on the page to have a display of inline just to see how it looks with the following CSS.

body * {
display: inline;
}

This example contains a new selector that we hadn’t covered in the earlier introduction. The * symbol is called a universal selector. It selects all elements. So this particular style rule, in English, reads: select all elements nested in the body element and make them inline elements.

A screenshot of devtools showing an images default inline display

An interesting thing to note, especially if you’re new to web development, is that images, which are declared in a web page using the img tag, have no browser styles applied to them. So they will always be display: inline unless you state otherwise. When an image is inline within a run of text, the text will run on either side of the image.

Images, videos and iframes are considered replaced elements, because their contents cannot actually be controlled by CSS. There is no way you can change the contents of an image or video file with CSS, because the image data or video data can only be edited and accessed with dedicated software. CSS only allows you to adjust how such elements are displayed.

When everything is inline, you will notice that there is no clear separation of paragraphs of text any longer. The text continually flows onto the next line. So one way to think about the two different types of boxes, is that block boxes behave like solids while inline boxes behave like liquids.

Can you measure the width and height of a liquid? Not really. A liquid takes up whatever shape and space its container does. It is similar with inline elements. So the width and height properties will have no effect on inline boxes.

A screenshot of devtools showing width and height have no effect on inline boxes

Firefox Devtools will tell you if you are using a property that is not applicable, by greying it out and when you hover over the information symbol icon, a pop-up will attempt to tell you the reason why.

Only margins and paddings along the inline-axis will have a visible effect on an inline box. And if an inline box is split over more than 1 line box, margins, borders and paddings will not apply on the “split” side of the box. Think of how you would slice a Snickers bar, the part that is cut will not have any chocolate coating on it.

Screenshot of devtools showing margin and padding along the inline-axis

You can see this from the browser when you highlight the element to inspect the margin and padding. Even though they are applied on all 4 sides, the top and bottom distances between lines don’t change at all. The additional spacing only occurs between text on the same line. The height of a line box is determined by the text’s font-size and the line-height property.

These properties will be covered in more detail in the Typography section of this course.