Skip to content

A comprehensive collection of CSS interview questions and answers to help developers prepare for front-end interviews. Covers core and advanced CSS topics like selectors, Flexbox, Grid, animations, responsive design, specificity, pseudo-classes, and best practices.

Notifications You must be signed in to change notification settings

softwaredeveloperhub01/CSS-Interview-Questions-and-Answers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

CSS Interview Questions and Answers

CSS Interviews – Top Questions & Answers for Web Developers


100 Trending CSS3 Interview Questions & Answers (2025 Edition)

A complete and easy-to-understand guide for CSS3 interview preparation — written in a simple, memorable, and practical way.


Basic CSS3 Interview Questions

1. What is CSS?

Answer:
CSS (Cascading Style Sheets) is used to style and design web pages. It defines how HTML elements should look — like color, layout, font, and spacing.


2. What’s new in CSS3 compared to CSS2?

Answer:
CSS3 introduced modules such as Flexbox, Grid, animations, transitions, media queries, gradients, and rounded corners — making responsive and interactive design easier.


3. What does “Cascading” mean in CSS?

Answer:
It means styles are applied in a hierarchy: browser default < external stylesheet < internal stylesheet < inline style. The latest rule overrides the earlier ones.


4. What are the different ways to apply CSS?

Answer:

  1. Inline — inside the HTML tag
  2. Internal — in <style> tags
  3. External — in a separate .css file linked via <link>

5. What is the difference between relative, absolute, and fixed positioning?

Answer:

  • Relative: Moves element relative to its normal position.
  • Absolute: Positions element relative to its nearest positioned ancestor.
  • Fixed: Stays fixed relative to the viewport (scrolling doesn’t affect it).

6. What is the z-index property?

Answer:
z-index controls the stacking order of elements. A higher value means the element appears on top.


7. What are pseudo-classes in CSS?

Answer:
Pseudo-classes define special states of an element — like :hover, :focus, or :active.


8. What are pseudo-elements?

Answer:
Pseudo-elements let you style specific parts of elements, e.g.

  • ::before – adds content before
  • ::after – adds content after

9. What is the difference between display: none and visibility: hidden?

Answer:

  • display: none removes the element from the layout.
  • visibility: hidden hides the element but keeps its space reserved.

10. What is the difference between em and rem units?

Answer:

  • em – relative to the parent’s font size
  • rem – relative to the root (HTML) font size

Intermediate CSS3 Questions

11. What is the box model in CSS?

Answer:
Every HTML element is a box — made of content, padding, border, and margin. This helps control spacing and layout precisely.


12. Explain the difference between margin and padding.

Answer:

  • Margin: Space outside the element’s border.
  • Padding: Space between content and border (inside the element).

13. What is the difference between inline, block, and inline-block?

Answer:

  • Inline: Doesn’t start a new line; ignores width/height.
  • Block: Takes full width; starts on a new line.
  • Inline-block: Behaves like inline but accepts width/height.

14. What are media queries?

Answer:
Media queries help make sites responsive by applying CSS based on screen size or device type.

Example:

@media (max-width: 600px) {
  body { background: lightblue; }
}

15. What is Flexbox in CSS3?

Answer: Flexbox makes layout alignment easy — it automatically adjusts element sizes and spacing in rows or columns.


16. What is the difference between Flexbox and CSS Grid?

Answer:

  • Flexbox: Best for one-dimensional layouts (row OR column).
  • Grid: Best for two-dimensional layouts (rows AND columns).

17. What is nth-child() used for?

Answer: Selects elements based on their order in a parent. Example: li:nth-child(2) selects the second list item.


18. What are transitions in CSS3?

Answer: Transitions animate property changes smoothly over time. Example:

div {
  transition: all 0.5s ease;
}

19. What are CSS animations?

Answer: They create frame-by-frame keyframe-based animations. Example:

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

20. What is the difference between transition and animation?

Answer:

  • Transition: Happens on state change (like hover).
  • Animation: Runs continuously or can be triggered manually.

Layout & Positioning

21. What is the default position property in CSS?

Answer: position: static; — elements appear in the normal flow.


22. What is the difference between float and Flexbox?

Answer: float was used for layout hacks; Flexbox is a modern layout system with better alignment and responsiveness.


23. What is overflow in CSS?

Answer: It controls what happens when content exceeds an element’s box. Values: visible, hidden, scroll, auto.


24. How do you center a div horizontally and vertically?

Answer: Modern way:

display: flex;
justify-content: center;
align-items: center;

25. What are CSS variables?

Answer: Variables store reusable values:

:root { --main-color: blue; }
div { color: var(--main-color); }

26. What is the difference between min-width, max-width, and width?

Answer:

  • width: Fixed size.
  • min-width: Minimum limit.
  • max-width: Maximum limit for flexibility.

27. What is the clip-path property?

Answer: It creates custom shapes by clipping an element to a specific path.


28. How can you create a responsive image?

Answer: Use:

img { width: 100%; height: auto; }

29. What is object-fit used for?

Answer: Controls how an image or video fits its container — like cover, contain, fill.


30. What is calc() in CSS?

Answer: calc() lets you do math inside CSS. Example: width: calc(100% - 50px);


Advanced CSS3 Concepts

31. What are gradients in CSS3?

Answer: Gradients create smooth color transitions — linear or radial.

Example:

background: linear-gradient(to right, red, yellow);

32. What is a CSS preprocessor?

Answer: A tool (like SASS or LESS) that adds programming features (variables, loops) to CSS.


33. What are CSS filters?

Answer: They apply effects like blur or brightness.

filter: blur(5px);

34. How do you make a sticky header?

Answer:

header { position: sticky; top: 0; }

35. What is a keyframe in animation?

Answer: Keyframes define how an animation changes over time using @keyframes.


36. What are vendor prefixes?

Answer: They ensure new features work across browsers. Example: -webkit-, -moz-, -ms-.


37. What is the difference between RGB and RGBA?

Answer: RGBA adds an alpha (opacity) channel: rgba(255, 0, 0, 0.5) — 50% transparent red.


38. What are shadows in CSS3?

Answer: Use box-shadow for elements and text-shadow for text.


39. How do you create rounded corners?

Answer: Use:

border-radius: 10px;

40. What is a transform in CSS?

Answer: Transforms move, rotate, or scale elements.

transform: rotate(45deg);

41. What are combinators in CSS?

Answer: Combinators define relationships:

  • A B → descendant
  • A > B → child
  • A + B → adjacent
  • A ~ B → sibling

42. What is specificity in CSS?

Answer: Specificity decides which CSS rule wins when multiple apply. Inline > ID > Class > Element.


43. What is the universal selector?

Answer: * targets all elements.


44. What is the purpose of !important?

Answer: Overrides all other rules — use sparingly as it breaks the cascade.


45. What is the default display value of <div> and <span>?

Answer:

  • <div> → block
  • <span> → inline

46. What is word-wrap?

Answer: It allows long words to break and wrap to the next line.


47. What is white-space in CSS?

Answer: Controls how spaces and line breaks are handled.


48. How to create a transparent background color?

Answer: Use RGBA: background-color: rgba(0,0,0,0.3);


49. What is backface-visibility?

Answer: Hides or shows the back of an element when rotated in 3D.


50. How to create a responsive layout without media queries?

Answer: Use Flexbox or Grid with flexible units like %, fr, or auto.


About

A comprehensive collection of CSS interview questions and answers to help developers prepare for front-end interviews. Covers core and advanced CSS topics like selectors, Flexbox, Grid, animations, responsive design, specificity, pseudo-classes, and best practices.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published