#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
CSS3 Fundamentals

CSS Display

The display property decides how an element takes part in layout: whether it starts on a new line, whether width and height apply to it, and whether its children are laid out with a special system such as flexbox or grid. Changing display is often the first step in fixing a layout problem, because the default value of an element determines most of its behaviour.

Block, inline and inline-block side by side

A block element, such as div, p or section, starts on a new line and stretches across the full width of its container. Width, height, margin and padding all work as you would expect.

An inline element, such as span, a or strong, flows inside a line of text. It ignores width and height, and vertical margins do not push other lines away.

Inline-block is a mix. The element sits in the line like a word, yet it accepts width, height and vertical spacing like a block. It is useful for small badges or buttons placed in a row.

.tag {
  display: inline-block;
  padding: 4px 10px;
  margin: 0 6px 6px 0;
  border-radius: 999px;
  background: #e8eefc;
}

.nav-links a {
  display: block;      /* whole row becomes clickable */
  padding: 12px 16px;
}

Turning on flex and grid

Setting display: flex or display: grid on a container changes how its direct children are arranged, while the container itself still behaves as a block. Flexbox arranges children in a single row or column and is ideal for toolbars, cards in a row and centring. Grid arranges children in rows and columns at the same time and suits page layouts and galleries. Their inline versions, inline-flex and inline-grid, make the container sit inside a line of text instead.

Hiding elements: none versus visibility

display: none removes the element from layout entirely. It takes up no space, and screen readers skip it. In contrast, visibility: hidden makes the element invisible but leaves an empty gap where it was. Pick display: none for things like closed menus, and visibility or opacity when you need the space reserved.

ValueNew line?Width/height work?
blockYesYes
inlineNoNo
inline-blockNoYes
noneNot renderedNot applicable

Mistakes to watch for

Many beginners set a width on a link or span and wonder why nothing changes. The element is still inline, so the width is ignored until you switch it to inline-block or block.

Another surprise comes with inline-block rows: a small gap appears between items. That gap is the whitespace between the tags in your HTML, rendered like a space character. Using a flex container with gap avoids the problem and gives you precise spacing.

Finally, remember that display: none cannot be animated with a transition. If a dropdown needs to fade, animate opacity and toggle visibility instead.

Takeaway

Check an element's current display value in your browser's developer tools whenever sizing seems ignored. Most surprises come from an element being inline when you expected block, or the reverse.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course