You are currently viewing CSS Cheat Sheet 169:  inline-block

CSS Cheat Sheet 169: inline-block

A Comprehensive Guide to display inline-block

Unlock the secrets of modern web layout design with our comprehensive guide to CSS Layout using the powerful property: display: inline-block. In the ever-evolving world of web development, mastering the art of creating visually appealing and responsive layouts is crucial. The CSS display: inline-block property offers a versatile solution that combines the best of both worlds, allowing elements to flow inline while retaining block-level properties. In this tutorial, we will delve deep into the intricacies of CSS Layout display: inline-block, equipping you with the skills needed to craft stunning web designs and responsive interfaces. Whether you’re a budding web developer or an experienced coder looking to level up your layout game, this guide will provide you with valuable insights and hands-on examples to harness the true potential of display: inline-block in your CSS toolkit.


Before diving into this tutorial, you should have a basic understanding of HTML and CSS. If you’re new to these technologies, consider familiarizing yourself with them first.

1. Understanding display Property

In CSS, the display property defines how an HTML element should be displayed. The display property can take various values, such as block, inline, inline-block, and more. Each value affects how an element interacts with other elements on the page.

2. Introduction to inline-block

The display: inline-block value is a powerful tool for creating flexible layouts. It combines characteristics of both inline and block elements. When an element is set to inline-block, it is treated as an inline-level element, but it can have block-level properties like width, height, margin, and padding.

3. Creating a Basic Layout

Let’s start by creating a simple layout using display: inline-block. Consider the following HTML and CSS code:


<div class="box"></div>
<div class="box"></div>
<div class="box"></div>


.box {
  width: 100px;
  height: 100px;
  background-color: #3498db;
  display: inline-block;
  margin: 10px;

In this example, we’ve created three <div> elements with the class “box.” Each box is displayed as an inline-block element. The margin property adds spacing between the boxes.

4. Adjusting Element Sizes

You can easily adjust the size of inline-block elements by changing the width and height properties. For example, to make the boxes smaller:

.box {
  width: 50px;
  height: 50px;
  /* Other styles remain the same */

5. Working with Margins

Margins can be used to control the space around inline-block elements. In the previous example, we set a margin of 10px. You can adjust it according to your design preferences.

6. Centering Elements Horizontally

To center inline-block elements horizontally within a container, you can set the text-align property of the container to center. For example:

.container {
  text-align: center;

.box {
  /* Other styles remain the same */

7. Responsive Layouts

One of the strengths of display: inline-block is its responsiveness. Elements flow horizontally, and when the container’s width is insufficient, they wrap to the next line automatically. This behavior makes it suitable for creating responsive grids and layouts.


In conclusion, our journey through the world of CSS layout has illuminated the power and versatility of CSS Layout display: inline-block. With this property at your disposal, you have the tools to create responsive, visually captivating web designs that adapt seamlessly to various screen sizes and orientations. From basic layouts to more complex grids, display: inline-block allows for endless creative possibilities in web development.

As you embark on your web design endeavors, remember that mastering CSS layout techniques like display: inline-block is just the beginning. The dynamic nature of the web demands continuous learning and adaptation. Stay updated with the latest developments in CSS and keep honing your skills to craft remarkable user experiences. With the knowledge gained from this guide, you are well on your way to becoming a proficient web layout designer, ready to tackle the ever-evolving landscape of web development with confidence and creativity. So, embrace CSS Layout display: inline-block and let your web designs shine in the digital realm.

Leave a Reply