Display

Display

Table of contents

Introduction

The CSS display property is used to define how an element should be displayed on a web page. It controls the layout and visibility of an element and determines how other elements interact with it.

There are several values that the display property can take:

  1. block: This value makes an element behave as a block-level element. It takes up the full width available and starts on a new line. Examples of block-level elements are <div>, <p>, and <h1>.

  2. inline: This value makes an element behave as an inline-level element. It takes up only as much space as necessary and does not start on a new line. Examples of inline-level elements are <span>, <a>, and <strong>.

  3. inline-block: This value combines aspects of both block and inline. It takes up only as much space as necessary, but still allows other elements to be positioned next to it. It does not start on a new line. It's commonly used for elements that need to have a specific width and height, such as buttons or images.

  4. none: This value hides the element and removes it from the normal document flow. The element will not be displayed, and the space it occupies will be collapsed. This can be useful for dynamically hiding and showing elements using JavaScript.

  5. flex: This value enables a flex container, allowing you to use flexbox layout for its child elements. Flexbox provides powerful and flexible methods for laying out elements within a container, allowing you to easily create responsive and dynamic layouts.

  6. grid: This value enables a grid container, allowing you to use CSS Grid Layout for its child elements. CSS Grid Layout provides a two-dimensional grid system that enables you to define complex layouts with rows and columns, making it ideal for creating grid-based designs.