Definition: Sets the width of an element's content area. This property controls how much horizontal
space an element occupies on the page. The actual space taken may be larger if padding, border, or margin
are applied. Width can be specified in pixels, percentages, or other CSS units.
Definition: Sets the height of an element's content area. This property controls how much vertical
space an element occupies. Like width, height can be affected by padding, border, and margin. The default
height is typically determined by the content itself unless explicitly set.
Default Value: auto (height determined by content)
Definition: Sets a maximum width limit for an element. The element can be smaller than this value,
but will never exceed it. This is extremely useful for responsive design and preventing elements from
becoming too wide. Max-width is commonly used to contain content and improve readability.
Definition: Sets a maximum height limit for an element. Elements can be shorter but never taller than
this specified value. When content exceeds max-height, overflow behavior (scroll, hidden, etc.) determines
how extra content is handled. Useful for creating expandable sections and preventing layout breakage.
Max-height: 100px with overflow:auto - scrollable content box
Line 1: This box has a maximum height. Line 2: Content exceeding this height Line 3: Creates a
scrollbar when needed Line 4: Perfect for list containers Line 5: And content previews Line 6:
Scroll to see more
Definition: Sets a minimum width that an element must maintain. Elements will always be at least this
wide, even if content is shorter. This prevents elements from becoming too small on narrow screens.
Min-width is crucial for responsive design to maintain usability and prevent content from becoming
unreadable.
Definition: Controls how an element is rendered and flows in the document. The display property
determines whether an element is treated as block-level or inline, and how it participates in the
layout. Different display values enable different layout techniques like flexbox and grid. This is one
of the most fundamental CSS properties.
Default Value: Varies by element (block for div, inline for span)
Values: block | inline | inline-block | flex | grid | none | table | table-cell | and more
✦ display: block
Block elements take full width and start on new line
display: none removes element from layout completely
This element is hidden by
display: none
This element is visible
.hidden {
display: none;
/* Element takes no space */
}
📝 visibility – Hide or Show Elements
Definition: Controls whether an element is visible or hidden. Unlike display: none, visibility:
hidden keeps the element's space in the layout - it just becomes invisible. This property is useful when
you need to hide elements while maintaining the document flow. Works well with transitions for fade
effects.
Element is hidden but space remains (notice the empty space)
Hidden Element
This element below is visible
.hidden-element {
visibility: hidden;
/* Element is hidden but space is preserved */
}
✦ Difference: visibility vs display
Compare visibility: hidden (reserves space) vs display: none (no space)
visibility: hidden
Hidden
Below Element
display: none
Hidden
Below Element
/* Reserves space */
.visibility-hidden {
visibility: hidden;
}
/* Removes from layout */
.display-none {
display: none;
}
📝 overflow – Handle Extra Content
Definition: Determines what happens when content exceeds the element's dimensions. This property
controls whether overflowing content is clipped, hidden, scrollable, or visible. Essential for managing
content that doesn't fit within defined bounds. The overflow property impacts both horizontal and
vertical directions, though you can control them separately with overflow-x and overflow-y.
Definition: Controls the transparency level of an element. Values range from 0 (completely
transparent/invisible) to 1 (completely opaque/visible). Unlike visibility: hidden, opacity still allows
the element to be interactive even when transparent. Opacity affects the entire element and all its
children. Perfect for creating fade effects, watermarks, and disabled state styling.