---
title: "Demystifying The CSS Display Property | CoderPad"
description: "The web page treats and sees every element as a box(to be precise, a rectangular box). The display property is a significant CSS property that you can use to determine how elements are displayed in your browser. This article will teach you how to improve your web page's display using the CSS display property."
canonical: "https://coderpad.io/blog/development/demystifying-the-css-display-property/"
last_modified: "2026-04-15 16:21:03"
---
[Back to blog](https://coderpad.io/blog/)

# Demystifying The CSS Display Property

November 21, 2022 7 Minute Read

By Joel Olawanle

[Development](https://coderpad.io/blog/development/)

The web page treats and sees every element as a box(to be precise, a rectangular box). There are two basic forms of boxes on a web page, and these are`block`and`inline`. The`display`property is a significant CSS property that you can use to determine how elements are displayed in your browser.

When you load a webpage in your browser, you will notice that the HTML elements on the page have their default ways of displaying. Some elements stack up on different lines, while others follow each other on one line. For example, all paragraph elements (`<p>`) stack up following each other on different lines, while the`<a>`elements, images, and others line up on a single line.

Block-level vs. inline elements – Image by [gcfglobal](https://edu.gcfglobal.org/en/basic-html/blocklevel-inline-and-organizational-elements/1/)

In this article, you will learn what the display property means, how it works, and the major values that affect how elements appear on the web page.

## What is the CSS display property?

The CSS display property sets how HTML elements display on your browser and the layout flow. The display property has about seven major values, which all affect how elements are displayed. Two major values you may be conversant with are [`flex`](https://coderpad.io/blog/development/a-guide-to-css-flexbox/) and [`grid`](https://coderpad.io/blog/development/a-very-very-in-depth-guide-on-css-grid/) which you can use to organize the layout of elements on your web page.

This article focuses on the flow of elements, and to perfectly understand, here are the display values that will be explained and used. These values include:

- `block`
- `inline`
- `inline-block`
- `inline-flex`
- `inline-grid`
- `none`

```
// Syntax
.selector {
    display: inline-block;
}Code language: CSS (css)
```

## CSS block display

You must have noticed that when you use a heading, paragraph tag, table tag, or semantic tags, they take the full width of space, and each element starts with a new line. This is because they are block-level elements.

Block-level elements will always start on a new line, irrespective of where you use the element. It will also always cover the entire width of the parent container, which stretches out to the left and right of its parent container.

To explain this, suppose your HTML looks like this where you have a heading, paragraph tags, and also tags like bold, italics, span, and others within the paragraph tag:

```
<body>
    <div>
        <h1>All Heading elements are block elements</h1>
        <h2>This means this will always be on a new line</h2>
        <h3>And will take up the entire container width</h3>
        <p>
            Paragraphs are block elements, while elements like the <em>em</em>,
            <i>italics</i>, <strong>strong</strong> <em>However</em>, em and and
            lots more are <small>inline</small> elements.
        </p>
        <p>
            Block elements define the flow of the HTML document.
            <span>While inline elements do not.</span>
        </p>
    </div>
</body>Code language: HTML, XML (xml)
```

To illustrate the block elements, I will add`background-color`, so you notice how they fill up the entire width and move to new lines.

Illustration of all HTML elements in their default display.

Normally, you might expect that since there is still more space after the first paragraph, the next paragraph should start from where it stopped, but it doesn’t work that way because it is a block-level element.

When you’re working with inline elements and want them to possess the qualities or act like block elements, you set the element’s`display`value to`block`. For example, you can set the`span`element’s`display`property to`block`so that it is no longer`inline`but now`block`.

```
span {
    display: block;
}Code language: CSS (css)
```

Then your page will look like this.

Image shows the span element converted from inline to block element.

Notice that the last paragraph takes up two lines because span now acts like a block element. Below are examples of [block elements](https://www.w3schools.com/html/html_blocks.asp) for reference purposes:

A list of block elements.

It is important to know that you can specify block elements`width`and`height`. You can also work with`padding`and`margin`efficiently, but it’s not so with inline elements. Let’s now explore inline elements.

## CSS inline display

The CSS inline display value is used to set a block element as an inline element. Inline elements are the opposite of block elements because they do not start on a new line and only take up as much width as their content.

For example, if I add a`background-color`property to each inline element in the HTML example, you will notice that these inline elements stick within other elements. They’re not for determining layout; they’re only used within block elements for styling.

Image highlighting all inline elements and showing how they fit within texts and their container.

You can convert a block element to act like an inline element using the`display`property set to`inline`. For example, let’s make the paragraph tags`inline`so that all the text comes together.

```
p {
    display: inline;
}Code language: CSS (css)
```
The paragraph tag converted from inline to block element.

You will notice that the background color for the paragraph goes around the text and no longer takes up the full width of the container.

It’s also important to know that inline elements do not accept`width`and`height`. They ignore it if you decide to use it. They accept`margin`and`padding`, but the element will still sit`inline`and only push other elements horizontally away, not vertically.

Applying padding and margin to inline elements.

Below are examples of [inline elements](https://www.w3schools.com/html/html_blocks.asp) for reference purposes:

A list of inline HTML elements.

## CSS inline-block display

You now understand what the inline and block display values mean and how they work. One angle is still missing; you might want a particular element to be set`inline`with the natural flow of text but also move to a new line and work with properties like`height`and`width`. This is where`inline-block`is useful.

The`inline-block`display value helps bridge the gap making it possible to have the major characteristics of the inline elements and the block element. This is not configured by default for any element. You get to apply this manually. For example, if you want to style the`<a>`tag, which sits in a paragraph to be a button.

```
<p>
    Block elements define the flow of the HTML document.
    <span>While inline elements do not.</span> <a href="">Click Me</a>
</p>Code language: HTML, XML (xml)
```

By default, the`<a>`tag is an inline element. Suppose you want to move it to a new line. You will notice it takes up the entire container width if you use`block`.

```
a {
    display: block;
    margin: 10px;
    padding: 10px 20px;
    background-color: rgb(50, 163, 255);
    border-radius: 5px;
    text-decoration: none;
    color: #fff;
}Code language: CSS (css)
```
Link tag converted to a block element.

To fix this, you can use`inline-block`, which will move the`<a>`element to a new line and not take up the entire width. Then you can also use properties like`height`,`width`,`padding`, and`margin`, which works properly compared to the`inline`element.

```
a {
    display: inline-block;
    margin: 10px;
    padding: 10px 20px;
    background-color: rgb(50, 163, 255);
    border-radius: 5px;
    text-decoration: none;
    color: #fff;
}Code language: CSS (css)
```
Using inline-block for link element so it posses features of both inline and block elements.

>

![ℹ️](https://coderpad.io/assets/emoji/2139.svg) You can apply the`inline-block`value to any element you wish when you want to move an element to a new line and avoid it from taking the entire width of your container. Also, when you want to be able to add`width`and`height`to inline elements.

## CSS inline flex and inline grid

When exploring the CSS [flexbox](https://coderpad.io/blog/development/a-guide-to-css-flexbox/) and [grid](https://coderpad.io/blog/development/a-very-very-in-depth-guide-on-css-grid/) layout properties, you will notice little or no emphasis made to the`inline-flex`and`inline-grid`options which work similarly to the`flex`and`grid`options but with little differences.

```
.box-container {
    display: inline-flex;
}Code language: CSS (css)
```

The`flex`,`grid`,`inline-flex`, or`inline-grid`values are usually applied to container elements. By default, these container elements like`div`are`block`elements. When you use either`flex`or`grid`as its`display`property, it functions like block-flex (it’s called flex) or block-grid (it’s called grid). However, there is nothing like block-flex or block-grid. But this means that the container works like a block container, but you now apply flex functionalities.

This means the container will take up full width, start from a new line, and all block features will work with the container element where the display value is added.

The difference between flex and inline-flex.

This is also similar to CSS grid. It is important to know that the`inline-flex`,`flex`,`grid`, and`inline-grid`is added to the container, and the`inline`or`block`display flow will only affect the container and not the container items.

## CSS display none

So far, you have learned very important display values. One last value to be explained is the`none`value. This value hides HTML elements from displaying on your web page. For example, you can use this`display`value if you have a portion of your web page or an element you wish to hide from appearing on the screen.

```
div {
    display: none;
}Code language: CSS (css)
```
An illustration of how to hide an element from the screen with`display: none`.

You might be conversant with the CSS`visibility`property which does a similar task to help hide HTML elements from displaying on the screen, but they both have some differences.

### CSS display none vs. visibility hidden

A very plain explanation is that when you use`visibility`with`hidden`as its value, it hides the HTML elements. However, the gap occupied by the hidden element will remain and affect the page. While the`display`property set to`none`will remove the element and its effects from the web page, the elements and tags will remain visible in the source code.

An illustration showing the difference between visibility of hidden and display set to none.

If you are building responsive web pages, you can use the`none`value of the`display`property to hide specific sections and display when on larger devices or when maybe a button is clicked, like the navigation menu.

## That’s it 🎉

In this article, you have learned what the CSS display property means and how it can help you set how HTML elements are displayed on your browser. You also learned the various values and how they work.

This is essential to make you aware of some behavior certain elements exhibit when working with them, so you don’t think an element filling up the entire width of your container is a bug when you want it to only take up the width of its content.

Thanks for reading, and have fun coding!

I’m Joel Olawanle, a frontend developer and technical writer interested in making the web accessible to everyone by always looking for ways to give back to the tech community. Follow me and connect with me on [Twitter](https://twitter.com/olawanle_joel).

## Subscribe for more CoderPad insights

## Trending Articles

Previous slide Next slide [Development

## What is Prompt Engineering?

Introducing AI tools such as ChatGPT and Bard helps increase the efficiency of tasks such as data generation, code generation and completion, text summarization, etc. How were these AI tools trained to answer almost every question you ask them? The answer, prompt engineering, is discussed in this blog post.

Read the post](https://coderpad.io/blog/development/what-is-prompt-engineering/) [Development

## A Guide To Using React’s useCallback() Hook

Are you looking to optimize your React applications? Have you heard of the useCallback hook? useCallback is a powerful React hook that helps you optimize your application by preventing unnecessary re-renders. In this post, we'll dive into React's useCallback() hook, define referential equality and callback functions and how to tie it all together.

Read the post](https://coderpad.io/blog/development/a-guide-to-using-reacts-usecallback-hook/) [Development

## MySQL vs. PostgreSQL: How Do They Compare?

A database is a convenient tool that allows users to access information, maintain records, and apply commonly used operations, such as insertion, modification, deletion, and data organization. Learn about MySQL vs PostgreSQL, their features, advantages, and disadvantages. Finally, check out which one is the best choice for you.

Read the post](https://coderpad.io/blog/development/mysql-vs-postgresql-how-do-they-compare/) [Development

## PostgreSQL LIKE Operator: A Detailed Guide

When using databases, searching for values that match a given pattern is a familiar necessity. Learn how you can retrieve entries with queries including a particular string using Postgres LIKE operator.

Read the post](https://coderpad.io/blog/development/postgresql-like-operator-a-detailed-guide/) [Development

## How To Use DataProvider In TestNG With Examples

When it comes to testing there are many tools and techniques available. In this post, we'll discuss how to use DataProvider with TestNG.

Read the post](https://coderpad.io/blog/development/how-to-use-dataprovider-in-testng-with-examples/) [Development

## How To Get Up And Running With Django Migrations: A Guide

Django migrations are a way of handling the application of changes to a database schema. By following the steps outlined in this guide, you can easily set up and use migrations in your Django projects.

Read the post](https://coderpad.io/blog/development/how-to-get-up-and-running-with-django-migrations-a-guide/) [Development

## Writing A Parameterized Test In JUnit With Examples

A JUnit parameterized test allows you to decouple data from structure, generating cleaner and more reliable tests. Learn more in this guide.

Read the post](https://coderpad.io/blog/development/writing-a-parameterized-test-in-junit-with-examples/) [Development

## How To Use Assert In JUnit With Examples

The JUnit Assert class is what you use to write unit testing assertions in JUnit. Learn more about it in this guide, full of examples.

Read the post](https://coderpad.io/blog/development/how-to-use-assert-in-junit-with-examples/) [Development

## A Simple Guide To TypeORM: What It Is And How To Use It

Considering current languages have object-oriented programming features, most database management systems are based on the relational model, with tables instead of objects. For these reasons, mapping relational objects is very important in development. In this article, you will learn what TypeORM, one of the main tools used today, is.

Read the post](https://coderpad.io/blog/development/a-simple-guide-to-typeorm-what-it-is-and-how-to-use-it/) [Development

## Using PreparedStatement in JDBC With Examples

In this post, we'll see why and how to work with JDBC and PreparedStatement. We will also learn along with examples using code.

Read the post](https://coderpad.io/blog/development/using-preparedstatement-in-jdbc-with-examples/) [Development

## React vs React Native: The Differences Explained

React and React Native are similar in that they both allow web developers to build applications based on the unique concept of components. But the two frameworks do this in radically different ways. In this post, we cover the key differences between react and react native frameworks, implementation, and which is an appropriate choice.

Read the post](https://coderpad.io/blog/development/react-vs-react-native-the-differences-explained/) [Development

## Logging in Django

The most challenging part of fixing a problem is identifying it. Unfortunately, this statement is exceptionally true when it comes to debugging. Learn how to use the power of logging into your Django applications to improve your debug process in this article.

Read the post](https://coderpad.io/blog/development/logging-in-django/)

## Hire with confidence.

See why engineering teams trust CoderPad to evaluate developers with realistic, AI-ready hiring workflows.

[Request a demo](https://coderpad.io/sales/)
