CSS Questions
Q5. Difference between relative, absolute, and fixed positioning?
A:
Relative – positioned relative to its normal position.
Absolute – positioned relative to the nearest positioned ancestor.
Fixed – positioned relative to the viewport; doesn’t move on scroll.
Q6. What is the difference between inline, internal, and external CSS?
A: Inline is inside an element’s style attribute, internal is in a <style> tag in HTML, external
is in a separate .css file.
Q7. Explain the difference between em, rem, %, and px in CSS.
A:
px – fixed pixel size.
% – relative to parent’s size.
em – relative to element’s font size.
rem – relative to root (<html>) font size.
Q8. How to center a div using CSS?
A: Use display: flex; justify-content: center; align-items: center; on the parent
container.
18. What does CSS stand for?
Cascading Style Sheets.
19. Difference between inline, internal, and external CSS?
Inline – inside tag; Internal – inside <style> in HTML; External – in .css file.
20. What are CSS pseudo-classes?
Special states of elements (e.g., :hover, :focus).
21. What is the difference between relative, absolute, and fixed positioning?
Relative – based on normal position; Absolute – based on nearest positioned ancestor; Fixed –
based on viewport.
22. Difference between em, rem, %, and px?
em – relative to element font size; rem – relative to root font size; % – relative to parent; px –
fixed pixels.
23. Difference between inline-block and block?
Inline-block – behaves inline but can have height/width; Block – starts on new line.
24. What is the difference between position: sticky and fixed?
Sticky scrolls until a limit, Fixed stays in the same position.
25. What are CSS media queries?
Rules to apply styles based on device screen size.
26. What is the difference between relative units and absolute units?
Relative – size changes based on context; Absolute – fixed size.
27. What is the difference between z-index and stacking context?
z-index defines order of elements; stacking context is how elements are grouped.
28. What is the difference between opacity and visibility?
Opacity 0 hides but still clickable; visibility hidden hides but keeps space.
29. How to create a gradient in CSS?
Use linear-gradient() or radial-gradient().
30. Difference between nth-child() and nth-of-type()?
nth-child – matches based on all children; nth-of-type – matches based on type.
31. What is a CSS flexbox?
A layout model for aligning items in rows/columns easily.
32. Difference between inline SVG styling and image styling?
Inline SVG supports CSS styling, image SVG does not.
33. How do you make text responsive?
Use relative units (em, rem, vw) and media queries.
34. Difference between CSS Grid and Flexbox?
Grid – 2D layout; Flexbox – 1D layout.
CSS – Frequently Asked Interview Q&A
1. What is CSS and what are its advantages?
CSS (Cascading Style Sheets) styles HTML content. Advantages: separates content and design,
improves consistency, faster page loads.
2. Difference between inline, internal, and external CSS?
Inline: inside style attribute, Internal: inside <style> in HTML, External: separate .css file.
3. What are pseudo-classes and pseudo-elements?
Pseudo-class targets element states (:hover), pseudo-element styles parts of elements
(::before, ::after).
4. Difference between relative, absolute, fixed, and sticky positioning?
Relative: based on original position, Absolute: based on nearest positioned ancestor, Fixed:
based on viewport, Sticky: scrolls until a limit.
5. Difference between em, rem, %, and px?
em: relative to element font size, rem: relative to root font size, %: relative to parent, px: fixed
pixels.
6. Difference between inline-block and block display values?
Inline-block: inline but allows height/width, Block: starts on a new line.
7. What are media queries? How are they used?
CSS rules applied based on device size:
@media (max-width: 600px) { body { font-size: 14px; } }
8. Difference between z-index and stacking context?
z-index controls layer order, stacking context is the environment that determines layering.
9. Difference between opacity and visibility?
Opacity hides visually but keeps clickable, visibility hidden hides and keeps space.
10. Difference between CSS Grid and Flexbox?
Grid: 2D layout, Flexbox: 1D layout (row or column).
11. How do you center a div using CSS?
display: flex; justify-content: center; align-items: center;
12. What are CSS transitions and animations?
Transitions animate between states, animations create multi-step movements with @keyframes.
13. Difference between relative and absolute units in CSS?
Relative adjusts with screen size (%, em), absolute stays fixed (px).
14. Difference between nth-child() and nth-of-type() selectors?
nth-child: selects by position, nth-of-type: selects by element type.
15. What is the difference between inline SVG styling and image SVG?
Inline SVG can be styled with CSS, image SVG cannot.