Lecture 18 — CSS Display Property⌗

Instructor: Laksh Budhrani


Objectives⌗

By the end of this lesson, you will be able to:

  1. Understand the purpose of the CSS display property.
  2. Differentiate between block, inline, and inline-block.
  3. Use display: inline-block to arrange elements next to each other.

Quick Recall: Previous Lectures Review⌗

Let’s quickly recall what we have learned so far!

HTML Tags⌗

TagWhat It Does
<div>Groups larger sections of content
<span>Groups a small part of text

CSS Properties⌗

PropertyWhat It Does
background-colorChanges the background color
font-familyChanges the font
colorChanges the text color
font-sizeChanges the text size
text-alignAligns text horizontally
text-decorationAdds or removes decorative lines
widthControls the width of an element
heightControls the height of an element
borderAdds an outline around an element
paddingAdds space inside the border
marginAdds space outside the border

Objective 1 — Understanding the display Property⌗

What it does: The CSS display property controls how HTML elements are arranged on a webpage.

For example, some elements appear one below another, while others appear next to each other.

We can use the display property to change how elements are arranged.


Objective 2 — Different Display Values⌗

a) display: block⌗

What it does: Displays an element on a new line. Block elements are placed one below another.

Example:

<div>First Box</div>
<div>Second Box</div>
div {
    display: block;
    background-color: lightblue;
    width: 200px;
    height: 60px;
}

Display Block Example


b) display: inline⌗

What it does: Displays elements next to each other on the same line.

Inline elements take up only as much space as their content needs. The width and height properties do not work normally on inline elements.

Example:

<div>First Box</div>
<div>Second Box</div>
div {
    display: inline;
    background-color: lightblue;
    width: 200px;
    height: 60px;
}

Display Inline Example


c) display: inline-block⌗

What it does: Displays elements next to each other while still allowing us to control their width and height.

Example:

<div>First Box</div>
<div>Second Box</div>
div {
    display: inline-block;
    background-color: lightblue;
    width: 200px;
    height: 60px;
}

Display Inline Block Example

Remember: inline-block is especially useful when creating cards or sections that need to appear next to each other.


Quick Comparison⌗

Display ValueArrangementWidth & Height
blockOne below anotherWork
inlineNext to each otherDo not work normally
inline-blockNext to each otherWork

Side Note — Vertical Alignment⌗

Sometimes, elements using inline-block may not line up perfectly at the top, especially when they contain different amounts of text.

We can use vertical-align: top; to align their top edges.

div {
    display: inline-block;
    vertical-align: top;
}

Note: This is an additional CSS property. You do not need to use it for today’s activities.


Guided Activity — JP2 School Athletics!⌗

The Story⌗

John Paul II Catholic School wants to showcase its school sports on its website.

Let’s create three cards featuring:

  • Basketball
  • Soccer
  • Volleyball

Your Task⌗

Open your existing jp2_website.html file.

Create three separate <div> containers, one for each sport. Use display: inline-block to place them next to each other.

Include a heading and a short description for each sport.

Style your containers using CSS properties learned so far.

JP2 Academic Departments Website


Independent Activity — My Favorite Person: Career Highlights!⌗

Open your existing favorite_website.html file.

Your Task⌗

Create a section showcasing three important career highlights of your chosen person.

For example:

  • Singer → Debut album, awards, concerts
  • Actor → First movie, major awards, popular movies
  • Athlete → Professional debut, championships, records

Use separate <div> containers for your three career highlights.

CSS Requirements:

  1. Use display: inline-block to arrange the containers next to each other.
  2. Use width and height to control their dimensions.
  3. Use at least three other CSS properties learned in previous lectures.

Favorite Website Display Example


Summary: CSS Display Property Learned Today⌗

Property / ValueWhat It Does
display: blockPlaces elements one below another
display: inlinePlaces elements next to each other
display: inline-blockPlaces elements next to each other while allowing width and height