CSS Inerview Question and Answer
CSS Inerview Question and Answer
Interview Question
Sr.No Topic Number of Questions
1 Basic CSS 10
2 Selectors 4
3 CSS Box Model 7
4 Layout 8
5 Typography 7
6 Colors and Backgrounds 9
7 CSS Transition 5
8 CSS Animation 5
9 CSS Transform 10
10 CSS Flex 8
11 Grid Layout 10
12 Responsive Design 8
Total 91
Q.1] What does CSS stand for? Q.6] What is an inline style?
• rel – It is used to indicate different relationships Q.9] How do you apply multiple styles to a
between the current document and the linked single element?
resource. Some common values are
- stylesheet • Multiple styles can be applied to a single element
- icon by separating each style declaration with a
- preload semicolon within the style attribute (for inline
- alternate styles) or within the CSS rule:
• type – The type attribute specifies the MIME type of
the linked resource.
4. ID Selector (#)
ID selector ✓ Selects a single element with a specific
• Defined using a hash (#) followed by an ID name. ID attribute
• IDs are unique within a document and should only
be applied to one element.
5. Attribute Selector
✓ Selects elements based on the presence
or value of an attribute.
Selectors
Q.11] What is a CSS selector?
• A CSS selector is a pattern that is used to select 6. Pseudo-classes
and style HTML elements based on various ✓ Selects elements based on their special
criteria such as element types, IDs, classes, state
attributes, and relationships with other
elements
7. Pseudo-elements
✓ Selects specific parts of an element's
content
2. Type Selector
8. Descendant Selector (space)
✓ Selects elements that are descendants
of another element.
Q.15] What is the CSS box model? • To center an element vertically, you can use
Flexbox
rounded borders
LAYOUT
Q.23] What is the position property in CSS?
Here is the diagram which illustrates the static and • Acts like relative until the element reaches a
relative position specified scroll point, then it "sticks" in place.
• To create a flexbox layout, you set display: flex; on • You specify a fallback font by listing multiple fonts
the parent container and use various properties
like flex-direction, justify-content, align-items,
etc., on the child elements to control their layout.
TYPOGRAPHY
Q.31] How do you change the font of an Q.36] How do you change the color of the text?
element?
• Using the font-family property in CSS. • Text alignment can be controlled using the
text-align property.
Syntax
3. Specific Size: You can set specific dimensions for Common Values
the background image using units like pixels,
percentages, or any other CSS length units.
REMEMBER
• You can use multiple background images in an Q.45] How do you change the opacity of an
element and position each one as needed using element?
the background-position property.
• This allows for creative and flexible design • We can change the opacity of an element using
options. the opacity property
Remember
The syntax for the transition property is as follows
CSS ANIMATION
CSS TRANSFORM
Q.51] What is the transition-delay property?
Q.56] What is the animation-timing-function
• A CSS animation allows you to animate changes property?
to CSS properties over time, using keyframes to
define the changes.
• The transform property applies a 2D or 3D
transformation to an element.
• This property allows you to rotate, scale, • This skews the element 20 degrees along the X-
skew, or translate an element. axis and 10 degrees along the Y-axis.
Q.57] How do you translate an element using CSS? Q.61] What is the transform-origin property?
• You can translate an element using the • The transform-origin property specifies the point
around which a transformation is applied.
translate() function.
• This moves the element 50 pixels to the right and
100 pixels down. • This rotates the element 45 degrees around its
top-left corner. Refer codepen
Q.58] How do you rotate an element using
CSS? Q.62] How do you apply multiple transforms
to an element?
Cross Axis
Q.65] What is the backface-visibility property?
• The cross axis is perpendicular to the main axis.
• The backface-visibility property determines • It runs in the opposite direction of the main axis
whether the back face of an element is visible • It is used for alignment and spacing of flex items.
when it is rotated • Directions
▪ When flex-direction is row or row-
reverse, the cross axis runs vertically.
▪ When flex-direction is column or
column-reverse, the cross axis runs
horizontally.
Main Axis
Q.68] What is the justify-content property? Q.71] What is the flex-wrap property?
Note:
•
RESPONSIVE
The viewport meta tag is used to control the layout
on mobile browsers.
• It ensures that the web page is rendered correctly
Q.85] How do you create a responsive layout Q.90] Explain @media only screen and (max-width:
600px)
using CSS?
• Only: This keyword is used to hide stylesheets
• Use percentage-based widths for layout elements
from older browsers that do not support media
rather than fixed pixel values
queries. It's a way to ensure that the media query
• Ensure images can scale within their containing will only apply in browsers that understand the
elements by using max-width: 100% media query syntax.
• Apply different styles based on the screen size or • Screen: This is a media type that targets screens,
device characteristics such as computer monitors, tablets,
smartphones, etc.
Q.86] What Are Media Queries? • (max-width: 600px): This condition applies the
styles within the media query if the viewport width
• Media queries are a CSS feature that allows is 600 pixels or less.
content rendering to adapt to different conditions
such as screen size, resolution, or orientation.
• They can be used to apply styles based on these
conditions.
😍 REMEMBER
Media Types
✓ all
✓ print
✓ screen
✓ speech
Media Features
✓ width
✓ min-width
✓ max-width
✓ height
✓ min-height
✓ max-height
✓ orientation