Author -  Sai gowtham

Display:block vs inline-block in CSS

In this tutorial, we are going to learn about the difference between block vs inline-block in css with the help of examples.

Block

If we set display property with value block then those elements will occupy the entire space on the x-axis(horizontal line).

Each element will also start on the new line.

Let’s see an example:

<span>First item</span>
<span>Second item</span>
<span>Second item</span>
span{
  display: block;
}

Output:

css display:block example

Have you seen in the above image each span element is occupied the entire space on an x-axis.

By default in html we have block level elements which are div, h1 , p, form,li,article, footer, section etc.

inline-block

If we set display property with inline-block then those elements are positioned side by side on the x-axis.

<h1>First heading</h1>
<h1>Second heading</h1>
<h1>Third heading</h1>
h1{
   display: inline-block;
   padding:1rem;
   border:1px solid;
}

Output:

Here we have the output with h1 elements are positioned side by side.

display inline-block example.png

Conclusion

The main difference between block and inline-block is block elements will starts with a new line and occupy the entire space on the x-axis(horizontal line), inline-block will place each element side by side on the x-axis.

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2023 (Beginner + Advanced)
JavaScript - The Complete Guide 2023 (Beginner + Advanced)
116,648 students enrolled
52 hours of video content
$14.99 FROM UDEMY
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
631,582 students enrolled
49 hours of video content
$24.99 FROM UDEMY
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
203,937 students enrolled
31.5 hours of video content
$14.99 FROM UDEMY