What is the difference between display: inline and display: inline-block in CSS?
The display property in CSS is very useful and commonly used property which contains many values. This article contains display:inline and display:inline-block property.
“display: inline” Property: This property is used to display an element as an inline element (like <span>). The height and width properties are not effected on display:inline; property. It allows only left and right side of margins, not top and bottom. In simple words it has no line break before and after of its neighbor elements and it allows HTML next to it.
Syntax:
element {
display: inline;
// CSS property
}
Example 1:
<!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:

“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 don’t force to line break.
Syntax:
element {
display: inline-block;
// CSS property
}
Example 2:
<!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:

Recommended Posts:
- CSS | Display property
- Display div element on hovering over <a> tag using CSS
- How Facebook Display Ads for something you searched
- Display a Resized and Cropped Image using CSS
- HTML | DOM Style display Property
- Display Property in Bootstrap with Examples
- How to display HTML tags as plain text using PHP
- How do you display JavaScript datetime in 12 hour AM/PM format?
- Hide or show elements in HTML using display property
- How to display multiple horizontal images in Bootstrap card ?
- How to xdebug var_dump to display full object/array ?
- Display the number of links present in a document using JavaScript
- How to display confirmation dialog when clicking an <a> link using JavaScript / jQuery ?
- How to write a:hover in inline CSS?
- How to write an inline IF statement in JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



