May 14, 2021


Latest Software News and Hacks

Top 60 CSS Interview Questions and Answers in 2021

Top 60 CSS Interview Questions and Answers in 2021

CSS means “Cascading Style Sheets.” CSS is defined as a  computer language for laying out and structuring web pages, i.e., HTML or XML. This language consists of coding elements, and they are composed of the “cascading style sheets,” which are called CSS files.

What is CSS used for?

CSS is the language mainly used for describing the presentation of Web pages, which includes colors, layout, and fonts. It allows the users to adapt the presentation to various types of devices, like large screens, small screens, or printers. CSS is independent of HTML and is used with any XML-based markup language.

Do you have a CSS Interview Scheduled? Then, it’s better to get prepared before you attend an interview so that you can crack them easily. We have listed the most frequently asked CSS Interview Questions. Please go through the entire article so that you will not miss any of them.

Top CSS Interview Questions and Answers

1. List the advantages of using CSS? 

Top 60 CSS Interview Questions and Answers in 2021

A few of the advantages of CSS are listed below:

  1. Greater consistency in design.
  2. Easier to maintain and update.
  3. More formatting options.
  4. Lightweight code.
  5. Search engine optimization benefits.
  6. Faster download times.
  7. Ease of presenting different styles to different viewers.
  8. Greater accessibility.

2. From where CSS originated?

Standard Generalized Markup Language(SGML) is the origin of CSS. It is a language used to define markup languages.

3. List the major versions of CSS?

The major versions of CSS are listed below:

  1. CSS 1
  2. CSS 2
  3. CSS 2.1
  4. CSS 3
  5. CSS 4

4. Define the Box model in CSS and list its properties?

Box model in CSS

In CSS, the “box model” is mainly used when we are talking about design and layout.

The CSS box model is a container that consists of various properties, including borders, padding, margin, and the content itself. It is mainly used to create designs and layouts of web pages. It is also used as a toolkit for customizing the layout of various elements.


  1. Content:  Actual Content of the box where we place the text or image.
  2. Padding: Area surrounding the content, i.e., the space between border and content
  3. Border: It is the area that surrounds the padding.
  4. Margin: It is the area that surrounds the border.

5. Define the methods to integrate CSS on a web page?

We have three methods to integrate CSS on web pages, they are:

  1. Inline method – It inserts the style sheets in an HTML document.
  2. Embedded/Internal method – It adds a unique style to a single document.
  3. Linked/Imported/External method – It is used to make changes on different pages.

6. Define cascading? How do style sheets cascade?

The cascade is an algorithm that specifies how to combine the property values originating from various sources. The CSS Cascade is also defined as an algorithm where the browser decides which CSS style is to be applied to an element.

We have three major CSS cascades:

  1. Elements –  We can apply the same CSS style to multiple elements to achieve a similar style.
  2. Multiple Style One Element – We can apply multiple styles to a particular HTML element to achieve that unique style.
  3. Same style, Multiple Pages – We can apply the same stylesheet to different HTML pages entirely to achieve template styling very quickly.

7. List the limitations of CSS?

A few of the limitations of CSS are:

  1. CSS is unable to perform logical operations like if/else or for/while or +/-.
  2. You can not read any files using CSS.
  3. It can’t interact with databases.
  4. CSS can not request a web page.

8. List the CSS frameworks?

A CSS framework can be defined as a library that allows easier, more standards-compliant web design by making use of the Cascading Style Sheets language. CSS frameworks offer various modules and tools:

  1. Reset stylesheet
  2. Grid especially for responsive web design.
  3. Web typography.

The CSS Frameworks are listed below:

  1. Bootstrap: It is the popular CSS framework used for developing responsive and mobile-first websites. 
  2. Foundation: It is defined as a responsive front-end framework. It mainly provides a responsive grid, HTML, CSS UI components, templates, code snippets, and including typography, forms, buttons, navigation, as well as optional functionality that are provided by the JavaScript extensions.
  3. Semantic UI: It is defined as a modern front-end development framework that is powered by LESS and jQuery. It has a sleek and flat design look that will provide a lightweight user experience.
  4. Ulkit: It is defined as a lightweight and modular front-end framework used for developing fast and robust web interfaces.

9. Differentiate between the usage of an ID and a Class in CSS?

It  is used to identify one single element in the HTML It is used to identify more than one HTML element.

10. Explain the various types of Selectors in CSS?

A CSS selector is used to select the HTML element(s) you want to style.

  1. Simple selectors: It selects the elements based on name, id, class.
  2. Combinator selectors: It selects the elements based on a certain relationship between them.
  3. Pseudo-class selectors: It selects the elements based on a specific state.
  4. Pseudo-elements selectors: It selects and styles a part of an element.
  5. Attribute selectors: It selects the elements based on the attribute or attribute value.

 CSS Interview Questions and Answers

11. Define Embedded Style Sheet?

Embedded style sheets will allow us to define the styles for the entire HTML document in one place. Embedded style sheets are usually referred to when you embed style sheet information into the HTML document by using the <style> element.

12. What is the RGB stream?

In CSS, a color is usually specified as an RGB value; we use the formula: RGB(red, green, blue). Each of the parameters (red, green, and blue) mainly defines the intensity of the color (between 0 and 255). 

For example, RGB(255, 0, 0)  displays red because here, the red is set to its highest value (255), and the remaining ones are set to 0.

13. Define CSS Preprocessor?

A CSS preprocessor can be defined as a program that lets us generate the CSS from the preprocessor’s unique syntax. There are different CSS preprocessors to choose from, But most CSS preprocessors add some features that do not exist in pure CSS, like mixin, selector, nesting, inheritance selector, etc.

14.  Define Sass, Less, and Stylus? Why do we use them?

Sass(Syntactically Awesome Style Sheets) is the oldest CSS Preprocessor. It allows the frontend developers to make use of variables, if/else statements, inheritance, for/while/each loop, and other computational logic in the CSS code.

Less(Leaner style sheets) It was influenced by Sass. , It is a JavaScript library that aims to extend the default functionalities of CSS.  It is written in JavaScript, and we need Node.js to install and run the LESS compiler.

Stylus: It is written in Node.js, which helps developers to easily integrate it into Node projects. It was influenced by Sass and LESS. It merges the powerful logical abilities of Sass with a straightforward setup of LESS.

15. List the advantages of Embedded Style Sheets?


  1. We can create multiple tag types in a single document.
  2. Styles, in complex situations, are applied using Selector and Grouping methods.
  3. The extra download to receive style information is not necessary.

 CSS Interview Questions and Answers

16. What is VH/VW in CSS?

VH and VW are CSS units that measure the height and width in percentage w.r.t to the viewport. It is usually used in responsive design techniques. The measure VH is usually equal to 1/100 of the height of the viewport.  Suppose if the height of the browser is 1000px, then 1vh is equal to 10px.In the same way, if the width is 1000px, then 1 VW is equal to 10px.

17. List CSS style components?

The CSS style components are:

  1. Selector: It is the HTML element name, id name, the class name.
  2. Property: It is like a attribute such as background color,text-align,color,border, font-size,position etc.
  3. Values: It defines property or values that allocate for properties.

18. Mention the ways to assign a certain color to an element in CSS?

CSS  assigns a wide range of colors to elements by using different notations. They are:

Hexadecimal notation: The color in the hexadecimal string notation usually begins with the “#” character. After that, we write the hexadecimal digits of the color code. The string is case-insensitive.

RGB functional notation: In CSS, a color is usually specified as an RGB value; we use the formula: RGB(red, green, blue). Each of the parameters (red, green, and blue) mainly defines the intensity of the color (between 0 and 255). 

HSL functional notation: Designers and artists prefer to work with  Hue/Saturation/Luminosity(HSL) color method. On the web, HSL colors are usually represented using HSL functional notation. The HSL() CSS function is the same as that of the RGB() function in usage.

19. Differentiate between reset vs. normalize CSS?

Reset Normalize
Reset strips styling from elements so that you have more control over the styling of everything. Normalize.css is a set of styles based on what the developers thought would look good and make it look more consistent across browsers.

20. Why do we use CSS Opacity?

The opacity CSS property is used to set the opacity of an element. Opacity is again defined as the degree to which content behind an element is hidden, and it is the opposite of transparency.

 CSS Interview Questions and Answers

21. Define the z-index in CSS? 

The z-index property usually specifies the stack order of the element. The element that has greater stack order is always in front of the element that has a lower stack order.

Z-Index takes the following values:

  1. Auto: It sets the stack order equal to the parents.
  2. Number: It orders the stack order.
  3. Initial: It sets this property to the default value (0).
  4. Inherit: It Inherits the property from the parent element.

22. Name the command used for selecting all the elements of a paragraph?

 P [lang]: is the command used for selecting all the elements of a paragraph.

23. Define CSS Sprites? 

CSS Sprites are used for combining multiple images into a single image file that will be used on a website to increase its performance.

24. What do we use % unit?

It is used to define the percentage values.

25. Define inline, inline-block, and block?

Block Element: The block elements usually start on a new line. They take space for the entire row or width. The  block elements are <div>, <p>.

Inline Elements: Inline elements do not start on a new line, but they appear on the same line as that of the content and tags beside them. A few examples of inline elements are <strong>, <img> tags, <a>, and  <span>.

Inline Block Elements: Inline-block elements are the same as that of the inline elements, except that they have margins and padding added on all four sides.

 CSS Interview Questions and Answers

26. Can you tell us the property used to specify the background color of an element?

The background-color property specifies the background color of the element. 

    background-color: #b0d5de;    

27. List few benefits of using CSS Sprites?


  1. It reduces the number of HTTP requests. One of the reasons to use CSS sprites is to cut back on the HTTP requests.
  2. Improves SEO
  3. Reduces overall image size

28. Define a Pseudo element and Pseudo-class?

A pseudo-class defines a special state of the element. 

For example, it is used to Style an element when a user hovers over it. 

A pseudo-element in CSS is a keyword that is added to a selector that describes the special state of the selected element(s).

 For example, The hover is used to change the button’s color whenever the user’s pointer hovers over it.

29. Can you name the property for controlling the image repetition of the background?

We use the background-repeat property to repeat the background image horizontally and vertically. Some images are repeated only horizontally or vertically.

30. Can you name the property for controlling image positions in the background?

We use the background-position property to define the initial position of the background image. By default, the background image is usually placed on the top-left of the given webpage.

We can set the positions as mentioned below:

  1. top
  2. Bottom
  3. center
  4. left
  5. right

 CSS Interview Questions and Answers

31. Why do we use float property in CSS?

The float property of the CSS is used to places the element on the left side or right side of the container by allowing the text and inline elements to wrap around it. 

32. Do the margin-top or margin-bottom has an effect on inline elements?

No, it does not affect the inline elements. Inline elements go with the flow of the contents of the page.

33. Why use a ruleset?

The ruleset identifies that the selectors can be attached with other selectors. It has mainly two parts:

  1. Selector – It specifies the HTML element you want to style.
  2. Declaration Block – The declaration block consists of one or more declarations that are separated by a semicolon.

34. Name the various modules used in the current version of CSS?

  1. Selectors
  2. Box Model
  3. Backgrounds and Borders
  4. Text Effects
  5. 2D/3D Transformations
  6. Animations
  7. Multiple Column Layout
  8. User Interface

35. Can you explain the CSS position property? 

CSS position property

Absolute: We use this to place the element exactly where you want to place it. 

Relative: It allows using a z-index on the element and limits absolutely positioned child elements scope. Any child element will absolutely be positioned within that block. 

Fixed: Here, the element is positioned relative to a viewport or browser window. Viewport does not change if you scroll. Hence the fixed element will stay in the same position. 

Static: Static is the default for every single page element. 

Sticky: This positioning is a hybrid of relative and fixed positioning. 

36. Name the different media types allowed by CSS?

We have  four types of @media properties :

  1. print – for printers
  2. all – for all media type devices
  3. speech – for screenreaders that can “read” the page out loud
  4. screen – for computer screens, smartphones, tablets, etc.

37. Define DOM reflow?

Reflow usually occurs when you insert, update, or remove an element in the DOM. 

Reflow usually occurs when:

  1. We modify content on a page, e.g., the text in an input box.
  2. Insert, remove or update an element in the DOM.
  3. Move a DOM element.
  4. Animate a DOM element.
  5. When you take measurements of an element like offsetHeight or getComputedStyle
  6. When you change a CSS style

38. What is RWD?

RWD(Responsive web design) is defined as an approach to web design that makes web pages display well on various devices and window or screen sizes from minimum to maximum display size.

39. List the different Box Sizing Property?

The CSS  box-sizing property allows the users to include padding and border in the element’s total height and width.

The different properties are:

Content-box: Here, the default height and width values are applied to the element’s content only. The padding and border are added outside of the box.

Padding-box: Here, the width and height values are applied to the element’s content and its padding. The border is usually added to the outside of the box. 

Border-box: Here, the width and height values are applied to the content, border, and padding.

 CSS Interview Questions and Answers

40. Differentiate between logical tags and physical tags?

Logical tags Physical tags
They are useless for appearances. They are referred to as presentational markup.
They are old and concentrate on the content. They are the newer versions.

41. Why do we use the overflow property in CSS?

We use the overflow property to specify what should happen if content overflows the element’s box. This property is mainly used to specify whether to clip the content or to add the scrollbars when the element’s content is huge to fit in the given area. The overflow property works only for the block elements with a given height.

42. Define the grid system?

The CSS Grid Layout divides a page into major regions, or it defines the relationship in terms of position, size, and layer between the parts of the control built from HTML primitives. Like tables, the grid layout allows the developer to align elements into columns and rows.

43. What is tweening?

  1. It is usually defined as the process of generating intermediate frames between two images.
  2. It gives an impression that the first image has smoothly progressed into the second one.
  3. It is an important method that is used in all types of animations.
  4. In CSS3, We use the Transforms (matrix, translate, rotate, scale) to achieve tweening.

44. Name the different font-related attributes in CSS?

Below listed are the different font-related attributes available in CSS:

  1. Font-variant
  2. Font-weight
  3. Font-style
  4. Font-size/line-height
  5. Font-family
  6. Caption
  7. Icon

45. Define: root pseudo-class?

The: root selector enables us to target the highest-level “parent” element in the DOM or the document tree. It is defined in CSS Selectors Level 3 specification.

 CSS Interview Questions and Answers

46. Define contextual selectors?

The CSS Contextual selectors enable us to specify various styles for different parts of the document. We can assign styles directly to the specific HTML tags, or we can create independent classes and assign them to the tags in the HTML.

47. Define CSS flexbox?

The CSS flexbox layout enables the user to format HTML easily. Flexbox helps us to make it simple to align the items horizontally and vertically by using rows and columns. Items will “flex” to sizes to fill the space. It makes responsive design easy.

48. How does Calc work in CSS?

The calc() function enables the user to perform mathematical operations on the property values. . It can be used anywhere a  <frequency> , <length> ,<angle> <percentage> , , <time> , <number> , or <integer> is allowed.

.foo {
Width: calc(100px + 50px)

49. Define Vendor-Prefixes?

Browser vendors add prefixes to the nonstandard or experimental CSS properties and JavaScript APIs so that developers can experiment with fresh new ideas while, in theory preventing their experiments from breaking web developers’ code during the standardization process. Developers have to wait to include the unprefixed property until browser behavior is standardized.

50. Define file splitting?

Part of a CSS architecture is the file organization. A monolithic file is usually fine for very small projects or solo developers. For large project sites with various layouts and content types, it’s wiser to use the modular approach and split the CSS across various files under the same design.

Splitting the CSS across different files makes it easy to parcel the tasks out to teams. If one developer works on typography-related styles, then the other can focus on developing grid components. It helps the teams to split the work sensibly and increase overall production.

51. Explain how CSS works under the hood? 

When the browser displays the document, it combines the document’s content with the style information. It usually processes the document in two stages:

  1. The browser converts the HTML and CSS into the Document Object Model(DOM). The DOM defines the document in the computer’s memory. It usually combines the document’s content with its style.
  2. The browser is used to display the contents of the DOM.

52. How do you optimize a certain webpage for prints?

To create printable pages is to identify and control the “content area(s)” of the website. Most websites are usually composed of a header, footer, one main content area, and sidebars/sub-navigation. If you control the content area, then assume most of your work is done. The following are few tips to conquer the print media without changing the integrity of the website.

  1. Create a stylesheet for print.
  2. Avoid the unnecessary HTML tables.
  3. Know which portions of the page do not have any print value.
  4. Make use of page breaks.
  5. Size your page for print (max height etc.).

53. Define specificity? How do you calculate specificity?

A technique that determines which CSS rule should be applied to an element. It mainly determines which rules can take precedence. Inline style usually wins, then ID then the class value, the universal selector (*) has no specificity. ID selectors usually have a higher specificity than attribute selectors.

54. Are there any advantages of using translate() instead of absolute position?

The Translate() will not cause the browser to trigger repaint and layout. Instead, it only acts on the compositor. The absolute position will trigger the repaint or DOM reflow. Hence, translate() gives better performance.

 CSS Interview Questions and Answers

55. What is progressive rendering?

Progressive Rendering is defined as a technique where once you render the critical content on the server, you will start streaming it to the client without waiting for the non-critical content. You will then stream non-critical content later once it is rendered on the server.

56.  Define CSS Custom properties variables?

Custom properties, also called  CSS variables or cascading variables, are entities that are defined by CSS authors that consist of specific values that are to be reused throughout the document. Complex websites have huge amounts of CSS, with a lot of repeated values.

57. How can we restore the default value of a property?

The keyword initial is used to reset it to its default value.

58. Define Accessibility in CSS?

Accessibility defines how the software or hardware combinations are designed in such a way to make the system accessible to persons with disabilities, like visual impairment, limited dexterity, or hearing loss.

59. Differentiate between CSS grid vs. flexbox?

Grid Flexbox
Grid is designed for a two-dimensional layout (rows and columns at the same time) flexbox is designed for layout in one dimension (either a row or a column).

60. What is W3C?

The W3C(World Wide Web Consortium) is an international community where Member organizations, and the public, and a full-time staff work together in order to develop Web standards. 

Good luck with your CSS Interview, and we hope our CSS Interview Questions and Answers were of some help to you. You can also check out our HTML Interview Questions and Answers, which might be of some help to you.

Recommended Articles

Go to Source of this post
Author Of this post: Abdul Rahim
Title Of post: Top 60 CSS Interview Questions and Answers in 2021
Author Link: {authorlink}