CSS interview questions

CSS interview questions | Freshers & Experienced

  • Satyam Jaiswal
  • 13th Nov, 2019

CSS Interview Questions

Q1. Explain what is CSS?

CSS stands for Cascading Style Sheets. It is used to describe the presentation of the documents usually written in the markup language like HTML. It is believed to be the base of the technology of the world wide web like HTML and JavaScript.

Q2. Enlist different versions of CSS?

There are mainly 3 versions of CSS are available. They are CSS 1, CSS 2 and CSS 3.

Q3. What are advantages/disadvantages of using External CSS?

There are some advantages of using External Style Sheets which are given below: -

  • It is easy to control the many documents at once from one file. By using this, the Code remains DRY and improves performance and comfort.
  • It is easy to create the classes which can be used on multiple HTML element types in several documents
  • Grouping and selector methods can be used to implement styles in difficult situations.

There are disadvantages of using External Style Sheets which are given below: -

  • There is a need for extra download to import the style information for each document.
  • It may increase the loading time of the webpage.
  • It is impossible to render the document until the external style sheet is loaded.
  • It is not viable if there are not sufficient styling conditions to justify an external sheet.

Q4. What are CSS sprites?

CSS Sprites is the way of combining several images into a single image file so that it can be used on a website efficiently. It helps to increase the performance of the website.

Q5. What are CSS selectors?

CSS Selectors are the component of the CSS ruleset which is used to select the content that you want to style. It selects the HTML element concerning its class, id, attributes, and types.

There are various types of selectors in CSS which are given below

  • CSS Element Selector
  • CSS Id Selector
  • CSS Class Selector
  • CSS Universal Selector
  • CSS Group Selector

Q6. What is use of @import in CSS?

Use of @import in CSS

  • It is used to import a style sheet into a different style sheet.
  • It is used to support media queries. By doing this, you can permit the import to be media-dependent.

Q7. What are Combinators in CSS?

Combinator in CSS tells the relation between two different simple selectors. It also tells the location of the content in the document.

There are many types of combinator which are given below.

  • descendant selector (space)
  • child selector (>)
  • adjacent sibling selector (+)
  • general sibling selector (~)

Q8. What is CSS Box Model and explain its elements?

CSS box model has many properties like border, padding, margin, and even the content. The CSS box model is utilized to build the layout and design of the web pages. Moreover, it can be utilized to customize the layout of different elements.

According to the CSS box model, every element renders as a rectangular box. The description of some properties of the CSS box model is given below:

  • Border Area: As the name represents, it is the area between the margin and the box's padding.
  • Margin Area: This area occupies space between the border and the margin.
  • Padding Area: It holds the element’s padding. It occupies the space around the content area and within the border-box.
  • Content Area: This area involves content like image, text, or other media content.

Q9. Explain Universal selector in CSS?

The CSS universal selector (*) is used to matches elements of any type.

Q10. In how many ways CSS be integrated on web page?

There are three ways of integrating CSS on the web page which is mentioned below: -

  • Inline: In this, Style property can be applied to possess CSS implemented HTML elements.
  • Embedded: In this, the Head element can possess the Style element inside which the code can be fixed.
  • Linked/ Imported: In this, CSS can be put in an external file and can be linked via a link element.

Q11. What is Alpha opacity in CSS?

Alpha channel is the color element that defines the degree of opacity of a color. In this way, it can tell how a pixel is rendered when mixed with another.

Q12. What are CSS margins?

The purpose of CSS margin properties is used to create space around elements, outside of the border. With the help of CSS, you have full control over the margins.

CSS has characteristics for defining the margin for each side of an element:

  • margin-top
  • margin-right
  • margin-bottom
  • margin-left

Q13. What is the viewport?

A viewport is an area of a web page that is visible to the users. Viewport area/space varies from device to device.

Q14. What is Tweening?

In CSS we use the term "animate". It is the most powerful and comfortable way to build animate objects. By using tweening, you can generate in-between frames.

Q15. What are CSS counters?

CSS counters are like variables that are managed by the CSS. These values are expanded by CSS rules so that they can be traced and can see how many times they are used. It allows the adjustment in the appearance of content concerning its location in a document.

CSS counters properties:

It has some properties which are mentioned below: -

  • counter-reset: It is applied to reset a counter.
  • counter-increment: It enlarged a counter value.
  • content: It is utilized to create content.
  • counter() or counters() function: These are related to combining the value of a counter to the element.

Q16. What is the property used to not allow highlighting?

User-select is the property used to not allow highlighting.

Q17. What is the default z-index of an element?

The default z-index of an element is 0 or auto

Q18. Enlist major advantages/disadvantages of using CSS preprocessors?

Advantages of using CSS Preprocessor

  • Ability to add variables, mixins, functions, etc: The main advantage of using CSS preprocessors is that you are able to add the variables and functions which the basic CSS can't allow. It not only facilitates easier and effective development but also makes your code more orderly and cleaner. CSS preprocessors bring new scope to your CSS.
  • Join Multiple Files: Another advantage of using CSS preprocessors is that it permits the joining of many stylesheets into one. With the help of this, the user can now create various files for each screen and then can compile them all in the main CSS file. The advantage of using this is that the main files need to be imported on the website and the rest of the internal files will be read from the server.
  • Avoid Repetitions: CSS preprocessors remove the limitation of basic CSS in which you have to write everything multiple times for each object. By using CSS preprocessors, you can save your time by writing the common style once which can be imported rather by re-writing.
  • Darken & Lighten functionality: CSS preprocessor provides many inbuilt functions and Darken and lighten function is one of them. The user can mention darkening color code and also the percentage
  • Nested Syntax: By using this feature, it is easy to target DOM elements and saves you a lot of time. In addition to this, it also makes it amazingly easy to edit CSS files.

Disadvantages of using CSS Preprocessor

  • Debugging is harder: The major drawback of the preprocessor is that it has a compilation step, which means CSS line numbers are unnecessary while debugging the code.
  • Compilation slows down development: Even if you are using the best computer tool on the fastest computer compilation takes a lot of time. So, this is also a major drawback
  • Produce very large CSS files: Even though the size of the file of the source is small, the generated CSS could be large
  • Tooling and developer convenience: Another drawback is that CSS Preprocessor needs additional tooling. Users have to use a specific editor just to use a particular tool that is not worthy. In addition to this, it also needs extra cost and a little bit of risk to upgrade and maintain the complexity which is brought by additional stuff.

Q19. What is difference between inline and inline-block in css?

Difference between inline and inline-block CSS

Inline Inline block
It ignores the top and bottom margins. It is subjected to the margin and padding
It is subjected to vertical-align property It ignores the vertical-align property
It ignores the width and height properties If height and width are not selected it is set automatically to set its elements
Examples: - <a>, <span>, <b>, <em> Examples:-. <p>, <div>, <form>, <header>

Q20. What is difference between "resetting" and "normalizing" CSS?

Difference between "resetting" and "normalizing" CSS

Resetting: Resetting means remove all default browser styling on elements. E.g. paddings, margins, font-sizes of all elements are reset to be the same. You will have to redeclare styling for general typographical components.

Normalize: Normalize means "You will get what you write". It stores valuable default styles instead of "unstyling" everything. It also fixes bugs for popular browser territories.

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

The z-index property tells about the stack position of an element. The element which has greater stack order remain in front of an element that has a lower stack order.

Q22. What are various Media types used in CSS?

Various types of media available in CSS are:

Media Type Description

Suitable/intended for all devises (default).


Intended for speech synthesizers.


Intended for braille tactile feedback devices.


Intended for paged braille printers.


Intended for handheld devices (typically small screen, monochrome, limited bandwidth). 


Intended for printed documents (applies to docs viewed in print preview mode too).

projection Intended for projected presentations (ie: projectors or print to transparencies).
screen Intended for computer screens.
tty Intended for media using a fixed-pitch character grid (ie: teletypes or terminals).
tv Intended for television-type devices.

Q23. Enlist the various fonts attributes available in CSS?

Various fonts attribute available in CSS are:

  • Font-family: To change the face of font, font-family is used.
  • Font-style: used to get a font italic or oblique.
  • Font-variant: used to build a small-caps effect.
  • Font-weight: used to enhance or diminish how bright or light a font appears.
  • Font-size: used to expand or reduce the size of a font.
  • Font: used to define the number of other font properties.

Q24. What are the valid media types available in CSS?

Media signifies the type of device that is used to display a webpage. For eg. a mobile screen or computer screen. As technology is expanding, devices like cell phones, handheld or even your wristwatch want to access the website which is making designing a website complex. Every user wants to make his/her site to look good across multiple devices. With the upcoming CSS level 2's which supports the media type, it is easy to use it and make your site view-friendly across various devices.

Different Media Types available in CSS are all, print, screen, and speech

Q25. What is primary difference between transition and transform?

Transitions: It supports property changes in CSS values so that it can run smoothly over a particularized duration.

Transforms: It supports elements styled with CSS to be transformed in 2D or 3D space.

Q26. What is the syntax for adding background-image?

The syntax for adding  background-image :

body {
 background-image: url("image-url");
 background-color: #cccccc;

Q27. What are gradients in CSS?

CSS gradients help you to display transitions between more than two colors. In order to create a linear gradient, you must represent at least two color stops. Color stops are the colors you desire to render smooth transitions among. In addition to the gradient effect, you can also set a starting point and a direction.

The syntax for creating the gradient in CSS is background-image: linear-gradient(direction, color-stop1, color-stop2, ...);

Q28. What is use of Opacity in CSS?

The opacity in CSS tells how transparent an element is. The values of elements can vary from 0 to 1 in which 0 represents completely transparent and 1 represents completely opaque(not transparent at all). BY default, the value of each element is 1. The opacity property of CSS makes it easy to alter the opacity of text, images, <div>s, and other elements.


Q29. What is RWD?

RWD stands for Responsive web design which was built to make your web page look amaze on all devices.

Q30. What is difference between id and class selector in CSS?

In CSS, an Id is used to identify/select only one element whereas Class is utilized to identify more than one element.

// defining a title selector
// some css
// defining a class selector
// some css

About Author :

  • Author of CSS interview questions

    Satyam Jaiswal

    Satyam is digital marketing expert, blogger from Allahabad Area. He loves to write technical articles and programming blog. He works on Onpage Seo, Social Media Groups and Off page Profile building

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.

Explore Popular Courses on Css

Start working with Landrick that can provide everything you need to generate awareness, drive traffic, connect.