CSS Display Property Explained with Block, Inline, and Inline-Block

Hi everyone!

In this section, we are going to explore one of the most fundamental and powerful CSS tools — the display property. If we’ve ever worked on web layouts, chances are we’ve already encountered it, even if we didn’t realize its full potential. Now, it’s time to dig deeper and understand how this property shapes the layout of every webpage.

By learning how to use the display property properly, we unlock the ability to control how elements behave in a layout — whether we want them to appear in a row, stack vertically, or hide them from view altogether. The display property is what helps us create flexible, clean, and responsive layouts.

Block and Inline Elements in HTML

Before diving into CSS, let’s start with how elements behave by default in HTML. For instance, when using a <p> tag, we’ll notice that it stretches all the way across the container. That’s because it’s a block-level element.

Now let’s say we want a specific word in that paragraph to have a different style, without breaking the line. That’s where inline elements shine. Here’s a quick example:

<p>Hello, <span>Beautiful</span> World</p>

In this case, the <span> tag doesn’t break the flow — the word “Beautiful” stays on the same line. Inline elements stay in line with surrounding content and only occupy the space their content requires.

Recap:

  • Block-level elements (like <div>, <p>, <h1>) always start on a new line and take up the full width.

  • Inline elements (like <span>, <strong>, <a>) do not start on a new line and stay within the flow of text.

Three Essential CSS Display Values

CSS offers many display values, but these three are foundational:

  1. block

  2. inline

  3. inline-block

Let’s break them down.

display: block

A block-level element:

  • Starts on a new line

  • Stretches across the entire width of the parent container

  • Can be styled using properties like width, height, margin, and padding

Common examples include <div>, <section>, <article>, and <header>.

display: inline

Inline elements:

  • Flow alongside other inline elements

  • Ignore properties like width and height

  • Only occupy space equal to their content

Elements like <span>, <strong>, and <a> are inline by default.

display: inline-block

This is the best of both worlds:

  • Appears inline with other elements

  • Supports width, height, margin, and padding

It’s perfect for items like buttons, menus, and navigation links that should sit side-by-side but still need custom dimensions.

Practical Example — Changing Layouts with Display

Let’s say we want to create three square boxes that appear side by side. Here’s the CSS:

.box {
  display: inline-block;
  width: 200px;
  height: 200px;
  background-color: lightblue;
  margin: 10px;
}

If the screen is wide enough, the boxes appear in a row. Want them to stack vertically instead? Just change the display value:

.box {
  display: block;
  width: 100%;
}

This small change has a big impact on layout — and that’s exactly the kind of power CSS gives us.

Hiding Elements with CSS

Sometimes we need to temporarily hide elements. That’s where display: none comes in:

.hidden {
  display: none;
}

Unlike visibility: hidden, which only hides the element but leaves its space, display: none removes it entirely from the layout. This is especially useful for:

  • Toggling menus

  • Form steps

  • Mobile navigation

Try It Yourself — Live Demo Playground

Want to practice this yourself? Check out this interactive example: https://css-display.vercel.app/

You’ll be able to:

  • Compare block vs inline behavior

  • Test inline-block layouts

  • Change display styles and observe the results in real-time

Use developer tools in your browser to explore and experiment.

Also, try the mini-challenge in the 8.0 CSS Display project. Your task:

  1. Make three boxes display side by side

  2. Then stack them vertically

Just by updating one property — the layout changes completely.

Why the Display Property Is So Important

If we’re serious about web design, then mastering the display property is essential. It’s the building block of all layouts. Whether we’re creating a landing page, a portfolio, or an entire web app — understanding display behavior helps us:

  • Fix common layout issues

  • Manage spacing effectively

  • Structure content with clarity

This foundation will also prepare us for more advanced layout systems like Flexbox and Grid, which we’ll explore soon.

So take your time to experiment with different display values. Observe how they behave across devices and browsers. Mastery here means smoother development later.

Keep building and see you in the next section!

Comments

Postingan Populer

Image

Halo teman-teman! Aku mau cerita tentang salah satu project seru yang aku kerjakan: halaman marketing untuk SEO Panel . Aku nggak bikin seluruh platform-nya, tapi fokus di bagian depan website supaya setiap elemen dan kontennya bisa langsung menyampaikan nilai produk dengan jelas dan mudah dipahami. Awal Proyek SEO Panel punya platform SEO all-in-one yang keren banget di belakang layar, dengan fitur-fitur lengkap buat bantu pengguna meningkatkan peringkat website. Tapi mereka butuh halaman depan yang nggak kalah kuat: tampilannya harus menarik, langsung menjelaskan manfaat, dan bikin pengunjung mau mencoba layanan. Aku mulai dengan memahami audiens mereka: siapa penggunanya, masalah apa yang sering ditemui di SEO, dan apa yang bikin mereka tertarik. Dari situ aku bikin alur konten dan layout yang gampang ditangkap pengunjung dalam beberapa detik pertama. Proses Desain Untuk halaman ini aku pakai WordPress dan Elementor supaya desainnya fleksibel dan nggak perlu coding dari awal. Fokus...

Image

Superingan is a Blogger template designed with simplicity and functionality in mind, offering a clean and user-friendly platform for professional websites. This theme is perfect for various website types, including personal blogs, online magazines, news websites, and portfolios. Features: Responsive Design: Your website will look its best across all devices, from desktops and laptops to tablets and smartphones. Customizable Colors: Easily change the template's colors to match your branding or preferences. Custom Headers: Upload your own header image to add a personal touch to your website. Custom Menus: Create and manage your website's navigation menus with ease. Widget Areas: Add widgets to display additional content and features on your website's sidebar. Clean HTML & CSS Code: The template is built with clean and well-structured code, making it easy to learn and customize further. Superingan is an ideal choice for those seeking a professional website with a sim...

Hi everyone! Welcome back to our CSS Grid series on Dindin Design! In the previous article, we explored how to size our grid columns and rows using fr , px , minmax() , and more. Now that we know how to set up a grid, it’s time to take it to the next level — by learning how to place elements inside the grid. In this article, we’ll learn Grid Item Placement — how to position and span items across your grid using properties like grid-column , grid-row , and grid-area . You’ll also learn how Flexbox and Grid can work together, and how to create overlapping layouts. What You’ll Learn Key Grid terminology: tracks, lines, cells, and items How to place grid items using grid-column , grid-row , and grid-area How to span items across multiple tracks Centering content inside grid items using Flexbox How to create overlapping layouts Grid Basics Refresher Before diving into placement, let’s refresh a few terms: Term Description Grid Container The parent element wi...