Open In App

What is the difference between display: inline and display: inline-block in CSS?

Last Updated : 03 Aug, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The display property in CSS is a very useful and commonly used property that contains many values. The display property defines how an HTML element should be displayed on the webpage. The property also specifies the type of box used for an HTML element and how it should be laid out on the page. If we need to display the elements that are laid out as inline elements, or laid out as inline-level block containers, then the display: inline and display: inline-block properties will be implemented. In this article, we will see the display property, along with understanding the 2 different property values for the display property, i.e., the display:inline and display:inline-block property, among several other properties, & finally, will understand their basic differences & implementation through the examples.

display: inline” Property: This property is used to display an element as an inline element (like <span>). The height and width properties are not affected on display: inline; property. It allows only the left and right sides of margins, not the top, and bottom. In simple words, it has no line break before and after its neighbor elements and it allows HTML next to it. When the element is declared with display: inline property, then it is treated as an inline element that will not start on a new line. Inline elements also cannot have a width, height, margin, or padding applied to them.

Syntax:

element {
display: inline;
// CSS property
}

Example 1: This example demonstrates the display property by setting its value as inline.

HTML




<!DOCTYPE html>
<html>
   
<head>
    <title>
        display:inline; property
    </title>
    <style>
        p {
            color: green;
        }
         
        .gfg {
            display: inline;
            padding: 15px 15px;
            border: 1px solid black;
            color: white;
            background-color: green;
        }
         
        div {
            text-align: justify;
        }
         
        h1 {
            color: green;
        }
         
        h1, h2 {
            text-align: center;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h2>
        display: inline; property
    </h2>
    <div>
        Prepare for the Recruitment drive of product based
        companies like <span class="gfg">Microsoft, Amazon,
            Adobe</span> etc with a free online placement
        preparation course. The course focuses on various
        MCQ's & Coding question likely to be asked in the
        interviews & make your upcoming placement season
        efficient and successful.
    </div>
</body>
   
</html>


Output: inline display: inline-block” Property: This property is used to display an element as an inline-level block container. The element itself is formatted as an inline element, but it can apply height and width values. It is placed as an inline element (on the same line as adjacent content). It looks like an inline element but it behaves as a block element and doesn’t force to line break. It allows having a block-level appearance while still being laid out inline with other elements.

Syntax:

element {
display: inline-block;
// CSS property
}

Example 2: This example demonstrates the display property by setting its value as inline-block.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
        display:inline-block; property
    </title>
    <style>
        p {
            color: green;
        }
         
        .gfg {
            display: inline-block;
            padding: 15px 15px;
            border: 1px solid black;
            color: white;
            background-color: green;
        }
         
        div {
            text-align: justify;
        }
         
        h1 {
            color: green;
        }
         
        h1, h2 {
            text-align: center;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <h2>display: inline-block; property</h2>
    <div>
        Prepare for the Recruitment drive of product based
        companies like <span class="gfg">Microsoft, Amazon,
            Adobe</span> etc with a free online placement
        preparation course. The course focuses on various
        MCQ's & Coding question likely to be asked in the
        interviews & make your upcoming placement season
        efficient and successful.
    </div>
</body>
 
</html>


Output: 

inline-block

Difference between display: inline and display: inline-block:

                                                          display: inline

                             display: inline-block

The width and height of the display: inline elements can’t be changed.

The width and height of the display: inline-block elements can be changed.

It can have padding and margin in the horizontal direction. But, with respect to the vertical direction, it does not have a margin and padding.

It can have padding and margin in all four directions.

It cannot have a child block element. 

It can have a child block element.



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads