Top 10 CSS Interview Questions with Answers
1. What is CSS?
CSS stands for Cascading Style Sheets. It is used to style and layout web pages.
2. What are the different types of CSS?
There are three types: Inline CSS, Internal CSS, and External CSS.
3. What is the difference between id and class in CSS?
id is unique and used for one element, while class can be used for multiple elements.
4. What is the box model in CSS?
The box model includes margin, border, padding, and content. It describes how elements are displayed and
spaced.
5. What is the difference between relative, absolute, fixed, and sticky positioning?
Relative: Positioned relative to itself. Absolute: Relative to nearest positioned ancestor. Fixed: Relative to
browser window. Sticky: Toggles between relative and fixed.
6. What is a pseudo-class in CSS?
A pseudo-class is used to define a special state of an element, like :hover, :first-child, :last-child.
7. What is the difference between em, rem, and px?
px is absolute unit. em is relative to the parent. rem is relative to the root element.
8. What is specificity in CSS?
Specificity determines which rule is applied when multiple rules match an element. It depends on selectors
used.
9. What are media queries?
Media queries are used to apply CSS styles based on device size, resolution, or orientation.
10. How can you make a website responsive?
By using relative units, flexible layouts, and media queries to adapt to different screen sizes.