CSS Interview Questions
CSS Interview Questions
1. What is CSS?
Answer:
CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of an HTML
document, including layout, colors, fonts, and animations.
Answer:
Internal CSS: Using the <style> tag within the <head> section.
External CSS: Linking an external .css file using the <link> tag.
Answer:
Content
Padding
Border
Margin
Answer:
Answer:
display: none: Removes the element from the document flow (it takes no space).
visibility: hidden: Hides the element but retains its space in the document flow.
6. What is the purpose of z-index in CSS?
Answer:
z-index controls the stacking order of elements. A higher z-index value brings an element to the
front.
Answer:
inline: Takes only the space required by the content (e.g., <span>).
Answer:
A CSS selector is used to target HTML elements for styling. Examples include:
Simple Selector
Combinator Selector
Pseudo-class Selector
Pseudo-element Selector
Attribute Selector
Answer:
Answer:
Flexbox is a layout model used to create flexible and responsive layouts. It aligns and distributes
space among items in a container.
11. What is the difference between position: absolute and position: relative?
Answer:
Answer:
Media queries are used to apply styles based on device characteristics, such as screen width, height,
or orientation. They are essential for responsive design.
Answer:
transition: Used for simple animations between two states (e.g., hover effects).
Answer:
Pseudo-classes are used to define special states of an element, e.g., :hover, :focus, :nth-child().
Answer:
float: Used for wrapping text around images or creating simple layouts.
flexbox: Used for creating complex, responsive layouts with better control over alignment and
spacing.
Answer:
CSS Grid is a layout system used to create two-dimensional grid-based layouts. It provides precise
control over rows and columns.
17. What is the difference between vh and vw units?
Answer:
Answer:
box-sizing: border-box includes padding and border in the element's total width and height, making
layout calculations easier.
Answer:
Answer:
@import is used to include external CSS files within another CSS file.