
In this lesson, you’ll understand how elements appear, disappear, align, and behave on the page. Most layout confusion comes from misunderstanding display, visibility, and overflow.
Once you master these, debugging layouts becomes fast and logical.
Info!
Before Flexbox or Grid, every layout starts with display rules.
1. CSS Display Property
The display property defines how an element behaves in the layout flow.
It controls width behavior, line breaks, and box characteristics.
1.1 display: block
Block elements:
- Start on a new line
- Take full available width
- Accept width, height, margin, padding
Common block elements: div, p, section, h1-h6
1.2 display: inline
Inline elements:
- Do not start a new line
- Width equals content size
- Ignore width and height
Common inline elements: span, a, strong
Warning!
Width and height do not work on inline elements.
1.3 display: inline-block
Inline-block is a hybrid:
- Sits inline like text
- Accepts width and height
Used heavily for buttons, badges, and small components.
1.4 display: none
display: none removes the element completely.
- No space reserved
- Not visible
- Not accessible to screen readers
2. CSS Visibility
Visibility controls whether an element is visible without removing its space.
visibility: hidden
- Element is invisible
- Space is preserved
Tip!
Use visibility for temporary hiding without layout shift.
3. Overflow Control (Deep Explanation)
Overflow becomes important when content grows larger than its container. This usually happens in fixed-height cards, modals, sidebars, dropdowns, code blocks, and scrollable sections.
The CSS overflow property controls:
- Whether extra content is visible or hidden
- Whether scrolling is allowed
- How layouts behave when content exceeds limits
Info!
Overflow works only when an element has a fixed width or height.
3.1 overflow: visible (Default)
This is the default behavior. If content is larger than the container, it will overflow outside the box and remain visible.
Key behavior:
- Content is not clipped
- No scrollbars appear
- Elements may overlap
Warning!
Using overflow: visible in complex layouts can cause overlapping issues.
3.2 overflow: hidden
With this value, any content that exceeds the container size is clipped and not visible.
Common use cases:
- Image cropping
- Clean UI cards
- Masking animations
Tip!
overflow: hidden is commonly used with border-radius and animations.
3.3 overflow: scroll
This value forces scrollbars to appear at all times, even if the content does not overflow.
Behavior:
- Always shows scrollbars
- Can show both horizontal and vertical scrolling
Warning!
Unnecessary scrollbars can reduce usability and visual clarity.
3.4 overflow: auto (Most Used)
This is the most practical option. Scrollbars appear only when content actually overflows.
That’s why it is widely used in real-world projects.
3.5 overflow-x & overflow-y
Sometimes you want scrolling in only one direction.
overflow-x: hidden;
overflow-y: auto;
Common use cases:
- Disable horizontal scrolling
- Create vertical content feeds
- Scrollable panels and sidebars
Overflow Summary
- visible → content flows outside the container
- hidden → extra content is clipped
- scroll → scrollbars always visible
- auto → scrollbars appear only when needed
Common Mistakes
- Using inline when width is needed
- Hiding elements with display:none instead of visibility
- Forgetting overflow causes layout break
- Using inline-block instead of flex unnecessarily
What You Learned
- Difference between block, inline, and inline-block
- display:none vs visibility:hidden
- How overflow affects layout
- When to use each display type
Next lesson: CSS Positioning & Z-Index