FrontendDeveloper.in

CSS Interview Questions

  • Question 1

    What is the CSS box model?

    The box model consists of content, padding, border, and margin.

    By default, width applies to content only. With box-sizing: border-box, width includes padding and border, which makes layouts easier to reason about.

  • Question 2

    What is specificity in CSS?

    Specificity decides which selector wins when multiple rules target the same element.

    Order from weaker to stronger is roughly: element selectors, class/attribute/pseudo-class selectors, then ID selectors, and finally inline styles.

  • Question 3

    What is the cascade in CSS?

    The cascade combines selector specificity, source order, and importance (!important) to determine final styles.

    Understanding the cascade helps avoid unnecessary overrides and brittle stylesheets.

  • Question 5

    What is Flexbox best used for?

    Flexbox is ideal for one-dimensional layouts (row or column), alignment, spacing, and equal-height distribution.

    It simplifies centering and responsive rearrangement without float hacks.

  • Question 8

    What are pseudo-classes and pseudo-elements?

    Pseudo-classes target states (e.g., :hover, :focus-visible, :nth-child). Pseudo-elements target virtual parts (e.g., ::before, ::after, ::placeholder).

    They help reduce extra markup for UI states and decoration.

  • Question 9

    What is stacking context and `z-index`?

    z-index only compares elements within the same stacking context. New contexts are created by properties like positioned elements with z-index, opacity < 1, transform, and filter.

    Many z-index bugs come from unexpected stacking contexts.

  • Question 13

    What are media queries used for?

    Media queries apply styles conditionally by viewport/device features.

    Example:

    @media (max-width: 768px) {
    .sidebar {
    display: none;
    }
    }
    

    They are core for responsive design.

  • Question 14

    What is `clamp()` in CSS?

    clamp(min, preferred, max) creates fluid values with safe limits.

    Useful for typography and spacing that scales with viewport but remains readable.

  • Question 15

    What is `object-fit` for images/videos?

    object-fit controls how replaced content fits inside a box.

    Common values:

    • cover: fills box, may crop.
    • contain: fits entirely, may leave empty space.
Get LinkedIn Premium at Rs 399