Interview GURU

CSS interview questions

There are most popular CSS interview questions asked in many companies.

1. What is CSS?

CSS stands for Cascading Style Sheet. It is a popular styling language which is used with HTML to design websites. It can also be used with any XML documents including plain XML, SVG, and XUL.

2. How can you integrate CSS on a web page?

There are three methods to integrate CSS on web pages.
  1. Inline method - It is used to insert style sheets in HTML document
  2. Embedded/Internal method - It is used to add a unique style to a single document
  3. Linked/Imported/External method - It is used when you want to make changes on multiple pages.

3. What are the advantages of CSS?

  • Bandwidth
  • Site-wide consistency
  • Page reformatting
  • Accessibility
  • Content separated from presentation

4. What are the limitations of CSS?

  • Ascending by selectors is not possible
  • Limitations of vertical control
  • No expressions
  • No column declaration
  • Pseudo-class not controlled by dynamic behavior
  • Rules, styles, targeting specific text not possible

5. What are the CSS frameworks?

CSS frameworks are the preplanned libraries which make easy and more standard compliant web page styling. The frequently used CSS frameworks are: -
  • Bootstrap
  • Foundation
  • Semantic UI
  • Gumby
  • Ulkit

6. Why background and color are the separate properties if they should always be set together?

There are two reasons behind this:
  • It enhances the legibility of style sheets. The background property is a complex property in CSS, and if it is combined with color, the complexity will further increase.
  • Color is an inherited property while the background is not. So this can make confusion further.

7. What is Embedded Style Sheet?

An Embedded style sheet is a CSS style specification method used with HTML. You can embed the entire stylesheet in an HTML document by using the STYLE element.

body {   
    background-color: linen;   
h1 {   
    color: red;   
    margin-left: 80px;   

More details...

8. What are the advantages of Embedded Style Sheets?

  • You can create classes for use on multiple tag types in the document.
  • You can use selector and grouping methods to apply styles in complex situations.
  • No extra download is required to import the information.

9. What is a CSS selector?

It is a string that identifies the elements to which a particular declaration apply. It is also referred as a link between the HTML document and the style sheet. It is equivalent of HTML elements. There are several different types of selectors in CSS:
  • CSS Element Selector
  • CSS Id Selector
  • CSS Class Selector
  • CSS Universal Selector
  • CSS Group Selector

10. Name some CSS style components.

Some CSS Style components are:
  • Selector
  • Property
  • Value

11. What is the use of CSS Opacity?

The CSS opacity property is used to specify the transparency of an element. In simple word, you can say that it specifies the clarity of the image. In technical terms, Opacity is defined as the degree to which light is allowed to travel through an object. For example:

img.trans {   
    opacity: 0.4;   
    filter: alpha(opacity=40); /* For IE8 and earlier */   

More details...

12. Explain universal selector.

he universal selector matches the name of any of the element type instead of selecting elements of a specific type.

* {   
   color: green;   
   font-size: 20px;   

More details...

13. Which command is used for the selection of all the elements of a paragraph?

The p[lang] command is used for selecting all the elements of a paragraph.

14. Name the property used to specify the background color of an element.

The background-color property is used to specify the background color of the element. For example:

    background-color: #b0d4de;   

More details...

15. Name the property for controlling the image repetition of the background.

The background-repeat property repeats the background image horizontally and vertically. Some images are repeated only horizontally or vertically.

body {   
background-image: url("paper1.gif");   

More details...

16. Name the property for controlling the image position in the background.

The background-position property is used to define the initial position of the background image. By default, the background image is placed on the top-left of the webpage.

You can set the following positions:
  1. center
  2. top
  3. bottom
  4. left
  5. right

background: white url('good-morning.jpg');  
background-repeat: no-repeat;  
background-attachment: fixed;  
background-position: center;

17. Name the property for controlling the image scroll in the background.

The background-attachment property is used to specify if the background image is fixed or scroll with the rest of the page in the browser window. If you set fixed the background image, then the image not move during scrolling in the browser. Let's take an example with the fixed background image.

background: white url('bbb.gif');  
background-repeat: no-repeat;  
background-attachment: fixed;

More details...

18. What is the difference between class selectors and id selectors?

An overall block is given to class selector while id selectors take only a single element differing from other elements.

CSS Class Selector
.center {   
    text-align: center;   
    color: blue;   
CSS Id Selector
#para1 {   
    text-align: center;   
    color: blue;   

More details...

19. What are the advantages of External Style Sheets?

  • You can create classes for reusing it in many documents.
  • By using it, you can control the styles of multiple documents from one file.
  • In complex situations, you can use selectors and grouping methods to apply styles.

20. What are the benefits of CSS sprites?

If a web page has a large number of images that take a longer time to load because each image separately sends out an HTTP request. The concept of CSS sprites is used to reduce the loading time for a web page because it combines the various small images into one image. It reduces the number of HTTP requests and hence the loading time.

21. What is the difference between logical tags and physical tags?

  • Physical tags are referred to as presentational markup while logical tags are useless for appearances.
  • Physical tags are newer versions, on the other hand, logical tags are old and concentrate on content.

22. What is the CSS Box model and what are its elements?

The CSS box model is used to define the design and layout of elements of CSS.

The elements are:

  • Margin - It removes the area around the border. It is transparent.
  • Border - It represents the area around the padding
  • Padding - It removes the area around the content. It is transparent.
  • Content - It represents the content like text, images, etc.

23. How to restore the default property value using CSS?

In short, there is no easy way to restore to default values to whatever a browser uses.

The closest option is to use the 'initial' property value, which restores the default CSS values, rather than the browser's default styles.

24. What is the purpose of the z-index and how is it used?

The z-index helps to specify the stack order of positioned elements that may overlap one another. The z-index default value is zero and can take on either a positive or negative number.

An element with a higher z-index is always stacked above than a lower index.

Z-Index can take the following values:
  • Auto: Sets the stack order equal to its parents.
  • Number: Orders the stack order.
  • Initial: Sets this property to its default value (0).
  • Inherit: Inherits this property from its parent element.

25. What do you understand by W3C?

W3C stands for World Wide Web Consortium. Its purpose is to deliver the information of the World Wide Web. It also develops rules and guidelines for the Web.