CSS Interview Questions

Tharani Dayadhi Karunathilaka.
3 min readJun 19, 2020

CSS stands for Cascading Style Sheet

01. What are the three methods to integrate CSS on a web page?

  1. Inline method
  2. Embedded/Internal method
  3. Linked/Imported/External method

02. Can you name some CSS style components?

  • Selector
  • Property
  • Value

03. Can you name the property used to specify the background color of an element?

Background-color property

Example:-

<style>

h2 , p{

background-color: #b0d4de; }

</style>

04.What is the difference between a class selector and an id selector?

An overall block is given to class selector

Id selectors take only a single element differing from other elements.

CSS Class Selector

Both lines are blue color because this applies color to the center class.

CSS Id Selector

Here only color change happen to #para1 id

05. Can you name some advantages of External Style Sheets?

  • We can create classes for reusing in many documents.
  • We can control the styles of multiple documents from one file.
  • We can use selectors and grouping methods to apply styles.

06. What is the CSS Box model?

We use it to define the design and layout of elements of CSS. We can also define the space between the elements.

07. What are the elements of the Box model?

  • 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 content like text, images, etc.

08. What are the two types of gradients in CSS?

  • Linear Gradient
  • Radial Gradient

09. What are the position states used in CSS?

  • Static(default)
  • Relative
  • Fixed
  • Absolute

10. How is the concept of inheritance applied in CSS?

It is used in CSS to define the hierarchy from the top level to the bottom level.

Example:

Body {font-size: 15pt;}

Here, the body will take the font size as 15pt.

Inherited properties can be overridden by the children’s class if the child uses the same name.

Body {font-size: 15pt;}
H1 {font-size: 18pt;}

All the paragraph text will be displayed using the property and will be defined in the body except for the H1 style which will show the text in font 18 only.

--

--