Display in CSS

Display in CSS ek important property hai jo layout control karta hai. Ye decide karta hai ki koi HTML element block hoga ya inline.

Har HTML element ka ek default display value hota hai:

  • Mostly block ya inline

display property ka use karke tum kisi bhi element ka default behavior change kar sakte ho.


Display in CSS – Block-level Elements

Block-level elements:

  • Hamesha new line se start hote hain
  • Full width lete hain (left se right tak)

Examples:

  • <div>
  • <h1> - <h6>
  • <p>
  • <form>
  • <header>
  • <footer>
  • <section>

Display in CSS – Inline Elements

Inline elements:

  • New line se start nahi hote
  • Sirf utni width lete hain jitni zarurat ho

Examples:

  • <span>
  • <a>
  • <img>

Common Values

display property ke kuch important values:

Value Description
inline Element inline ban jata hai
block Element block ban jata hai
contents Container remove ho jata hai, sirf children rehte hain
flex Element flex container ban jata hai
grid Element grid container ban jata hai
inline-block Inline jaisa behave karta hai but height, width apply hota hai
none Element completely hide ho jata hai

Display in CSS – Override Default Value

Tum kisi element ka default display change kar sakte ho.

Example 1: <li> ko inline banana (horizontal menu)

Display in CSS – Override Default Value

Example 2: <span> ko block banana

<span> ko block banana

Example 3: <a> ko block banana

<a> ko block banana

Note:
display change karne se element ka type change nahi hota.
Inline element ko block banane par bhi wo block elements ke rules follow nahi karega internally.


More Values Example

Display in CSS – More Values Example

Display in CSS – Hide Elements

display: none

  • Element completely hide ho jata hai
  • Page me koi space nahi leta

Example:

display: none

JavaScript se Show/Hide

Show element:

Show element

Toggle show/hide:

Toggle show/hide

CSS Display vs Visibility

display: none

  • Element remove ho jata hai
  • Space nahi leta

Example:

Display in CSS vs Visibility

visibility: hidden

  • Element invisible hota hai
  • Lekin space still leta hai

Example:

visibility: hidden

Display in CSS ek core property hai jo web layout control karti hai. Iska use karke tum elements ko block, inline, flex, grid ya hidden bana sakte ho.

Proper use se:

  • Layout clean hota hai
  • Responsive design improve hota hai
  • UI control better hota hai

Leave a Comment