Skip to main content
  1. Data Science Blog/

Choosing Display Type in CSS

·1258 words·6 mins· loading · ·
CSS CSS Display Property CSS Display Types CSS Block-Level Displays CSS Inline-Level Displays CSS Flexbox Layout CSS Grid Layout

On This Page

Table of Contents
Share with :

Choosing Display Type in CSS
#

What is display property in HTML container?
#

There are many HTML container tags, discussed in another article. But the content inside these container can be rendered in different ways. This is controlled by a property display. What are the different values of display property and what is the meaning of those, we will see those in this article.

The display property in CSS defines how an element is displayed in the layout β€” it’s one of the most fundamental properties in CSS.

Here’s a breakdown of the most common and important values of display, along with their meanings and typical use cases:

1. Block-level Displays
#

ValueDescriptionExample
blockElement starts on a new line and takes up full width<div>, <section>, <p>
inlineElement flows inline with text, only takes up as much width as needed<span>, <a>, <b>
inline-blockBehaves like inline, but you can set width and heightCustom buttons, badges
noneHides the element completely (it’s not in the DOM visually)Toggle visibility

2. Flexbox Layout
#

ValueDescriptionUse Case
flexTurns container into a flexbox, for 1D layout (row or column)Navigation bars, centering items
inline-flexSame as flex but behaves like inline elementInline flexible elements

Once you use display: flex, you use properties like justify-content, align-items, flex-direction inside it.

3. Grid Layout
#

ValueDescriptionUse Case
gridTurns container into a CSS Grid for 2D layout (rows and columns)Page sections, dashboards
inline-gridSame as grid but behaves like inlineRarely used, inline grid content

4. Table Layout (for table-like designs)
#

ValueDescriptionHTML Equivalent
tableBehaves like a <table><table>
table-rowBehaves like <tr><tr>
table-cellBehaves like <td><td>
table-column, table-caption, etc.Corresponding to other parts of table layout<col>, <caption>

You can use these to make a table-like layout without actual <table> elements.

5. Other Values
#

ValueDescription
contentsMakes the element disappear visually, but keeps its childrenRare; useful in component design
list-itemMakes element behave like a list item (<li>) with a bulletOften used for custom lists
inheritInherits the display value from the parent
initialResets to the default display value
unsetRemoves any set value, falling back to inheritance or default

Common Use Cases
#

TaskUse display value
Layout sectionsblock, grid, flex
Inline buttonsinline-block, inline-flex
Toggle visibilitynone
Responsive navbarsflex
Image galleriesgrid
Custom list bulletslist-item

Usage of display : flex
#

When you apply display: flex to a container, you can then use various flex properties to control the layout of its child elements.

Example:
#

<div class="flex-container">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>
.flex-container {
  display: flex;
  justify-content: space-between; /* Align items horizontally */
  align-items: center;            /* Align items vertically */
  flex-direction: row;            /* Default: row (horizontal) */
  gap: 10px;                      /* Add spacing between items */
}

Common flex properties:
#

PropertyDescription
justify-contentAligns items horizontally (e.g., flex-start, center, space-between)
align-itemsAligns items vertically (e.g., stretch, center, baseline)
flex-directionChanges the axis direction (row, column, row-reverse, column-reverse)
flex-wrapAllows wrapping to next line if needed

Usage of display: grid
#

CSS Grid Layout is a powerful layout system in CSS designed to help web developers create complex and responsive web layouts easily and efficiently. It allows you to create two-dimensional layoutsβ€”both rows and columnsβ€”without using floats or positioning tricks.

What is CSS Grid Layout?
#

CSS Grid is a layout model that lets you divide a web page into major regions or define the relationship in terms of size, position, and layer between parts of a control built from HTML primitives.

Think of it as turning your container into a grid of cells, where you can place child elements precisely in any cell or span across multiple cells.

How CSS Grid Works
#

1. Create a Grid Container
#

You define a grid by setting display: grid on a container.

.container {
  display: grid;
}

2. Define Rows and Columns
#

Use grid-template-columns and grid-template-rows to define the structure.

.container {
  display: grid;
  grid-template-columns: 200px 1fr 1fr;
  grid-template-rows: auto auto;
}

This example creates:

  • 3 columns: one fixed (200px) and two flexible (1fr each)
  • 2 rows with automatic height

3. Place Grid Items
#

Each direct child of the grid container becomes a grid item, and you can control its position using:

.item1 {
  grid-column-start: 1;
  grid-column-end: 3;
  grid-row-start: 1;
  grid-row-end: 2;
}

Or use shorthand:

.item1 {
  grid-area: 1 / 1 / 2 / 3; /* row-start / column-start / row-end / column-end */
}

βœ… Key Features of CSS Grid
#

FeatureDescription
display: gridActivates grid layout on a container
grid-template-columns, grid-template-rowsDefines columns and rows
grid-column, grid-rowPlaces items in specific grid areas
fr unitFractional unit for flexible layouts
grid-gap / gapSpace between rows and columns
grid-template-areasName areas and place items semantically

🎯 Use Cases of CSS Grid
#

  • Page Layouts: Headers, sidebars, footers, main content
  • Dashboards: Control panels with resizable sections
  • Galleries: Image grids with consistent spacing
  • Forms: Neatly aligned labels and inputs

πŸ†š Flexbox vs Grid
#

FeatureFlexboxGrid
Direction1D (row or column)2D (row and column)
Use CaseAlignment, navigation barsLayouts, full-page sections
Item PlacementSequentialAbsolute (by coordinates)

🧠 Visualization Example
#

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto;
  gap: 10px;
}

HTML:

<div class="container">
  <div class="box">1</div>
  <div class="box">2</div>
  <div class="box">3</div>
</div>

This creates a 3-column layout with equal widths and 10px gaps between boxes.

How to set display property in bootstrap and tailwind?
#

The underlying CSS display values are the same, but the class names and flexibility differ between Bootstrap and Tailwind. Tailwind tends to be more expressive and granular by default. Both provide utility-based control over display. Both support responsive variants.

  1. Bootstrap:

Bootstrap provides utility classes for the display property using the pattern:

.d-{value}

Common examples:

  • .d-block β†’ display: block;
  • .d-inline β†’ display: inline;
  • .d-flex β†’ display: flex;
  • .d-none β†’ display: none;
  • responsive variations like: .d-sm-none, .d-md-block, etc.

  1. Tailwind CSS:

Tailwind provides utility classes for display using descriptive class names:

display: {value}
FeatureBootstrapTailwind CSS
Syntax.d-block, .d-noneblock, hidden
Naming styleShort + prefixedDescriptive + unprefixed
CustomizationRequires Sass overrideFully configurable via tailwind.config.js
ConsistencyBootstrap is limited to fewer display typesTailwind supports more modern display values like grid, inline-grid out of the box

Common examples:

Utility ClassCSS Equivalenttailwind
.d-blockdisplay: blockblock
.d-inlinedisplay: inlineinline
.d-flexdisplay: flexflex
.d-griddisplay: gridgrid
.d-inline-griddisplay: inline-gridinline-grid
.d-nonedisplay: nonehidden
.d-inline-blockdisplay: inline-blockinline-block
.d-sm-none, .d-md-block, .d-md-grid, .d-lg-inline-grid`responsive variationssm:hidden, md:flex
Utility Classesgrid-cols-2, gap-4, auto-rows-fr

How does browser knows which framework to use for css class?
#

Frameworks like Tailwind and Bootstrap are developer tools. Browsers just apply CSS rules β€” they don’t “know” what framework you’re using.

  1. Tailwind / Bootstrap = Class Names β†’ CSS

Frameworks like Tailwind and Bootstrap define a set of prewritten CSS classes that map to standard CSS properties.

Example:

<div class="grid"> <!-- Tailwind -->
<div class="d-grid"> <!-- Bootstrap -->

Behind the scenes:

  • Tailwind:

    .grid {
      display: grid;
    }
    
  • Bootstrap:

    .d-grid {
      display: grid;
    }
    

When the browser sees:

<div class="grid">

It doesn’t think: β€œAh, Tailwind!” It just sees the class name and applies the CSS rule:

display: grid;

Developer Side vs. Browser Side

AspectDeveloper View (Tailwind/Bootstrap)Browser View
Semantic Frameworksgrid, d-grid, etc.Just CSS classes
Additional FeaturesConfig files, responsive variantsNot relevant
Rendered OutputHTML + linked CSS filesCSS β†’ Style Tree
Dr. Hari Thapliyaal's avatar

Dr. Hari Thapliyaal

Dr. Hari Thapliyal is a seasoned professional and prolific blogger with a multifaceted background that spans the realms of Data Science, Project Management, and Advait-Vedanta Philosophy. Holding a Doctorate in AI/NLP from SSBM (Geneva, Switzerland), Hari has earned Master's degrees in Computers, Business Management, Data Science, and Economics, reflecting his dedication to continuous learning and a diverse skill set. With over three decades of experience in management and leadership, Hari has proven expertise in training, consulting, and coaching within the technology sector. His extensive 16+ years in all phases of software product development are complemented by a decade-long focus on course design, training, coaching, and consulting in Project Management. In the dynamic field of Data Science, Hari stands out with more than three years of hands-on experience in software development, training course development, training, and mentoring professionals. His areas of specialization include Data Science, AI, Computer Vision, NLP, complex machine learning algorithms, statistical modeling, pattern identification, and extraction of valuable insights. Hari's professional journey showcases his diverse experience in planning and executing multiple types of projects. He excels in driving stakeholders to identify and resolve business problems, consistently delivering excellent results. Beyond the professional sphere, Hari finds solace in long meditation, often seeking secluded places or immersing himself in the embrace of nature.

Comments:

Share with :

Related

Exploring CSS Frameworks - A Collection of Lightweight, Responsive, and Themeable Alternatives
·1376 words·7 mins· loading
Web Development Frontend Development CSS Frameworks Lightweight CSS Responsive CSS Themeable CSS CSS Utilities Utility-First CSS
Exploring CSS Frameworks # There are many CSS frameworks and approaches you can use besides …
Dimensions of Software Architecture: Balancing Concerns
·833 words·4 mins· loading
Software Architecture Software Architecture Technical Debt Maintainability Scalability Performance
Dimensions of Software Architecture # Call these “Architectural Concern Categories” or …
Understanding `async`, `await`, and Concurrency in Python
·599 words·3 mins· loading
Python Asyncio Concurrency Synchronous Programming Asynchronous Programming
Understanding async, await, and Concurrency # Understanding async, await, and Concurrency in Python …
High-Level View of HTML CSS JavaScript
·4022 words·19 mins· loading
Web Development HTML CSS JavaScript Web Development Frontend Development
High-Level View of HTML CSS JavaScript # Introduction # HTML, CSS, and JavaScript are the three …
Understanding Vocal Frequencies in Speech-to-Text AI Applications
·4605 words·22 mins· loading
AI NLP Speech-to-Text Vocal Frequencies Sound Signals AI Applications
Exploring Voice Signal Processing # Introduction # In AI projects that involve human voice, such as …