CSS interview questions and Answers

Last updated on Feb 07, 2024
  • Share
CSS interview questions

Cascading Style Sheets (CSS) is a style sheet language or a mechanism used for enhancing its style by adding colors, fonts, and spacing to your web documents. We have a collection of CSS interview questions that helps in crack your interviews. It is designed to enable the separation of content for improving content accessibility and providing more flexibility in the specification of presentation and reducing complexity in the structural content. The specifications of CSS are maintained and managed by the W3C.

Most Frequently Asked CSS interview questions

Here in this article, we will be listing frequently asked CSS interview questions and Answers with the belief that they will be helpful for you to gain higher marks. Also, to let you know that this article has been written under the guidance of industry professionals and covered all the current competencies.

Q21. What is hover effect in css? How we can apply on tags?
Answer

It select and style a link when you mouse over it. An :hover is used to select elements when you mouse over them.

Example

a:hover{
background-color: yellow;
}

Q22. What is the use of z-index in CSS?
Answer

It specifies the stack order of an element. An element with greater stack order is always in front of an element with a lower stack order. z-index only works on positioned elements like position:absolute, position:relative, or position:fixed.

Q23. What are the difference between "display:none" and "visibility:hidden" in CSS?
Answer

visibility:hidden : Ithides an element, but it will still take up the same space as before. The element will be hidden, but still, affect the layout.

display:none : It hides an element as well as doesn't preserve the space.

Q24. How to make scroll bars with the help of CSS?
Answer

The CSS overflow property specifies whether to clip content or to add scrollbars when the content of an element is too big to fit in a specified area.

Property of overflow is given below :-

  • visible
  • hidden
  • auto
  • scroll
Example

overflow: scroll
div {
overflow: scroll;
}

overflow-x and overflow-y
div {
overflow-x: hidden; /* Hide horizontal scrollbar */
overflow-y: scroll; /* Add vertical scrollbar */
}

Q25. What is the limitations of CSS?
Answer

CSS has various limitations as a programming language thats are as follows:

  • CSS cannot perform any logical operations like if/else or for/while or +/-.
  • We can not read any files using CSS.
  • It can not interact with databases.
  • CSS can not request a web page.
Q26. What are the difference between "position:absolute" & "position:relative" in CSS?
Answer

Both Postions(absolute & relative) are having different features. Once we set Position then you can able to use top, right, bottom, left attributes.

An absolute position element is positioned relative to the first parent element that has a position other than static.

Absolute : In case of position absolute, an element searches for the nearest available coordinate axes among its parent elements. The element is then positioned by specifying offsets from this co-ordinates axis. It removed from document normal flow.

Relative : In case of position relative, an element creates its own co-ordinates axes, at a location offset from the view port co-ordinate axis. It is Part of document flow but shifted.

Q27. What are the difference between Internal & External CSS?
Answer

Internal CSS are the ones that we can write within the same file i.e the HTML code and CSS code are placed in the same file.

External CSS are that we can write in a separate file than the html code i.e the HTML file is separate like(index.html) and CSS file is separate like(style.css).

Q28. How to write css for 3rd child of every <ul> tags?
Answer

nth-child(n) : It matches every element that is the nth child, regardless of type, of its parent.

Example

ul:nth-child(3) {
background: red;
}

 

Q29. What is responsive?
Answer

It is about making a website look good on all devices like desktops, tablets, and phones etc. In responsive HTML and CSS is automatically resize a website.

Q30. What is the used of !important? How we can use it?
Answer

The !important css rule is used for overriding the previously assigned CSS declarations.

Example

#sidebar {
   font-size: 12px !important;
}

Latest Version : CSS version 4 was released in March 2017.

Advantages

  • Saves time
  • Pages load quickly
  • Easy to maintain
  • Superior styles in HTML
  • Compatible with multiple devices
Development History

CSS was proposed by Hakon Wium Lie in October 1994. The first released was made public in December 1996.

Reviewed and verified by Umesh Singh
Umesh Singh

My name is Umesh Singh having 11+ experience in Node.JS, React JS, Angular JS, Next JS, PHP, Laravel, WordPress, MySQL, Oracle, JavaScript, HTML and CSS etc. I have worked on around 30+ projects. I lo...