Css Interview Questions and Answers

Prepare Css interview questions for freshers and experienced candidates. This page includes important questions, answer previews, preparation guidance, related interview topics and cached content for faster page loading.

🎨
59+ Css questions available

About Css Interview Preparation

CSS (Cascading Style Sheets) is a style sheet language used for describing the look and formatting of HTML(Hyper Text Markup Language) and XML(Extensible Markup Language) documents including (but not limited to) colors, layout, and fonts

For better preparation, read each question carefully, understand the concept, prepare one real example, and connect your answer with your project or work experience.

Css Questions List

Quick list of important Css interview questions. Detailed answer previews are available below.

  1. What is CSS ?
  2. What is the origin of CSS ?
  3. What are the different variations of CSS ?
  4. What are the limitations of CSS ?
  5. What are the advantages of CSS ?
  6. What are CSS frameworks?
  7. How block elements can be centered with CSS1?
  8. In how many ways can a CSS be integrated as a web page?
  9. What benefits and demerits do External Style Sheets have?
  10. Discuss the merits and demerits of Embedded Style Sheets?
  11. What does CSS selector mean?
  12. Enlist the media types CSS allows?
  13. Differentiate logical tags from physical tags?
  14. Differentiate Style Sheet concept from HTML?
  15. Describe 'ruleset'?
  16. Comment on the Case-sensitivity of CSS ?
  17. Define Declaration block?
  18. Enlist the various fonts' attributes?
  19. Why is it easy to insert a file by importing it?
  20. What is the usage of Class selector?
  21. Differentiate Class selector from ID selector?
  22. What is Pseudo-elements ?
  23. What happens if 100% width is used along with floats all across the page?
  24. Enlist the various Media types used?
  25. What is CSS Box Model and what are its elements?
  26. What is contextual selector?
  27. Compare RGB values with Hexadecimal color codes ?
  28. Define Image sprites with context to CSS ?
  29. Compare Grouping and Nesting in CSS ?
  30. How can the dimension be defined of an element ?

Question 1: What is CSS ?

Answer: The full form of CSS is Cascading Style Sheets. It is a styling language which is simple enough for HTML elements. It is popular in web designing, and its application is common in XHTML also.

View detailed answer →

Question 2: What is the origin of CSS ?

Answer: Standard Generalized Markup Language marked the beginning of style sheets in 1980s.

View detailed answer →

Question 3: What are the different variations of CSS ?

Answer: =>CSS 1 =>CSS 2 =>CSS 2.1 =>CSS 3 =>CSS 4

View detailed answer →

Question 4: What are the limitations of CSS ?

Answer: Limitations are: *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

View detailed answer →

Question 5: What are the advantages of CSS ?

Answer: Advantages are: *Bandwidth*Site-wide consistency*Page reformatting*Accessibility*Content separated from presentation

View detailed answer →

Question 6: What are CSS frameworks?

Answer: It is a pre-planned libraries, which allows easier and more standards-compliant webpage styling, using CSS language.

View detailed answer →

Question 7: How block elements can be centered with CSS1?

Answer: Block level elements can be centered by: The margin-left and margin-right properties can be set to some explicit value: BODY { width: 40em; background: fluorescent; } P { width: 30em; margin-right: auto; margin-left: auto }   In this case, the left and right margins will be each, five ems wide since they split up the ten ems left over from (40em-30em). It was unnecessary for setting up an explicit width for the BODY element; it was done here for simplicity.

View detailed answer →

Question 8: In how many ways can a CSS be integrated as a web page?

Answer: CSS can be integrated in three ways: Inline: Style attribute can be used to have CSS applied HTML elements. Embedded: The Head element can have a Style element within which the code can be placed. Linked/ Imported: CSS can be placed in an external file and linked via link element.

View detailed answer →

Question 9: What benefits and demerits do External Style Sheets have?

Answer: Benefits: One file can be used to control multiple documents having different styles.Multiple HTML elements can have many documents, which can have classes.To group styles in composite situations, methods as selector and grouping are used. Demerits: Extra download is needed to import documents having style information.To render the document, the external style sheet should be loaded.Not practical for small style definitions.

View detailed answer →

Question 10: Discuss the merits and demerits of Embedded Style Sheets?

Answer: Merits of Embedded Style Sheets: Multiple tag types can be created in a single document.Styles, in complex situations, can be applied by using Selector and Grouping methods.Extra download is unnecessary. Demerits of Embedded Style Sheets: Multiple documents cannot be controlled.

View detailed answer →

Question 11: What does CSS selector mean?

Answer: A string equivalent of HTML elements by which declarations or a set of it, is declared and is a link that can be referred for linking HTML and Style sheet is CSS selector.

View detailed answer →

Question 12: Enlist the media types CSS allows?

Answer: The design and customization of documents are rendered by media. By applying media control over the external style sheets, they can be retrieved and used by loading it from the network.

View detailed answer →

Question 13: Differentiate logical tags from physical tags?

Answer: =>While physical tags are also referred to as presentational mark-up, logical tags are useless for appearances.=>Physical tags are newer versions while logical tags are old and concentrate on content.

View detailed answer →

Question 14: Differentiate Style Sheet concept from HTML?

Answer: While HTML provides easy structure method, it lacks styling, unlike Style sheets. Moreover, style sheets have better browser capabilities and formatting options.

View detailed answer →

Question 15: Describe 'ruleset'?

Answer: Ruleset : Selectors can be attached to other selectors to be identified by ruleset. It has two parts: *Selector, e.g. R and*declaration {text-indent: 11pt}

View detailed answer →

Question 16: Comment on the Case-sensitivity of CSS ?

Answer: Although, there are no case-sensitivity of CSS, nevertheless font families, URL’s of images, etc is. Only when XML declarations along with XHTML DOCTYPE are being used on the page, CSS is case -sensitive.

View detailed answer →

Question 17: Define Declaration block?

Answer: A catalog of directions within braces consisting of property, colon and value is called declaration block.e.g.: [property 1: value 3]

View detailed answer →

Question 18: Enlist the various fonts' attributes?

Answer: They are: *Font-style*Font-variant*Font-weight*Font-size/line-height*Font-family*Caption*Icon

View detailed answer →

Question 19: Why is it easy to insert a file by importing it?

Answer: Importing enables combining external sheets to be inserted in many sheets. Different files and sheets can be used to have different functions. Syntax: @import notation, used with <Style> tag.

View detailed answer →

Question 20: What is the usage of Class selector?

Answer: Selectors that are unique to a specific style, are called CLASS selectors. Declaration of style and association with HTML can be made through this. Syntax: Classnameit can be A-Z, a-z or digits..top {font: 14em ;}, class selector<Body class= “top”> this class is associated with element </body>

View detailed answer →

Question 21: Differentiate Class selector from ID selector?

Answer: While an overall block is given to class selector, ID selector prefers only a single element differing   from other elements.

View detailed answer →

Question 22: What is Pseudo-elements ?

Answer: Pseudo-elements are used to add special effects to some selectors.  CSS in used to apply styles in HTML mark-up. In some cases when extra mark-up or styling is not possible for the document, then there is a feature available in CSS known as pseudo-elements. It will allow extra mark-up to the document without disturbing the actual document.

View detailed answer →

Question 23: What happens if 100% width is used along with floats all across the page?

Answer: While making the float declaration, 1 pixel is added every time it is used in the form of the border, and   even more float is allowed thereafter.

View detailed answer →

Question 24: Enlist the various Media types used?

Answer: Different media has different properties as they are case insensitive. They are: *Aural – for sound synthesizers and speech*Print – gives a preview of the content when printed*Projection- projects the CSS on projectors.*Handheld- uses handheld devices.*Screen- computers and laptop screens.

View detailed answer →

Question 25: What is CSS Box Model and what are its elements?

Answer: This box defines design and layout of elements of CSS. The elements are: Margin: the top most layer, the overall structure is shownBorder: the padding and content option with a border around it is shown.  Background color affects the border.Padding: Space is shown. Background colour affects the border.Content: Actual content is shown.

View detailed answer →

Question 26: What is contextual selector?

Answer: Selector used to select special occurrences of an element is called contextual selector. A space separates the individual selectors. Only the last element of the pattern is addressed in this kind of selector. For e.g.: TD P TEXT {color: blue}

View detailed answer →

Question 27: Compare RGB values with Hexadecimal color codes ?

Answer: A color can be specified in two ways: *A color is represented by 6 characters i.e. hexadecimal color coding. It is a combination of numbers and letters and is preceded by #. e.g.: g {color: #00cjfi} *A color is represented by a mixture of red, green and blue. The value of a color can also be specified. e.g.: rgb(r,g,b): In this type the values can be in between the integers 0 and 255. rgb(r%,g%,b%): red, green and blue percentage is shown.

View detailed answer →

Question 28: Define Image sprites with context to CSS ?

Answer: When a set of images is collaborated into one image, it is known as ‘Image Sprites’. As the loading every image on a webpage consumes time, using image sprites lessens the time taken and gives information quickly. CSS coding: img.add { width: 60px; height: 55px; background: url (image.god) 0 0; } In this case, only the part needed is used. The user can save substantial margin and time through this.      

View detailed answer →

Question 29: Compare Grouping and Nesting in CSS ?

Answer: Grouping:  Selectors can be grouped having the same values of property and the code be reduced. h1 { color: blue; } h2 { color: blue; } p { color: blue; } It can be seen from the code that every element shares the same property. Rewriting can be avoided by writing each selector separated by a comma. Nesting: Specifying a selector within a selector is called nesting.   5678910111213141516171819202122232425P { color: red; text-align: left; } .marked { background-color: blue; } .marked p { color: green; }

View detailed answer →

Question 30: How can the dimension be defined of an element ?

Answer: Dimension properties can be defined by: *Height*Max-height*Max-width*Min-height*Min-width*Width

View detailed answer →

Question 31: Define float property of CSS?

Answer: By float property, the image can be moved to the right or the left along with the text to be wrapped around it. Elements before this property is applied do not change their properties.

View detailed answer →

Question 32: How does Z index function?

Answer: Overlapping may occur while using CSS for positioning HTML elements. Z index helps in specifying the overlapping element. It is a number which can be positive or negative, the default value being zero.

View detailed answer →

Question 33: What is graceful degradation?

Answer: In case the component fails, it will continue to work properly in the presence of a graceful degradation. The latest browser application is used when a webpage is designed. As it is not available to everyone, there is a basic functionality, which enables its use to a wider audience. In case the image is unavailable for viewing, text is shown with the alt tag.

View detailed answer →

Question 34: What is progressive enhancement?

Answer: It’s an alternative to graceful degradation, which concentrates on the matter of the web. The functionality is same, but it provides an extra edge to users having the latest bandwidth. It has been into prominent use recently with mobile internet connections expanding their base.

View detailed answer →

Question 35: How can backward compatibility be designed in CSS?

Answer: HTML sheet methods is collaborated with CSS and used accordingly.

View detailed answer →

Question 36: How can the gap under the image be removed?

Answer: As images being inline elements are treated same as texts, so there is a gap left, which can be   removed by: CSS img { display: block ; }

View detailed answer →

Question 37: What is Alternate Style Sheet?

Answer: Alternate Style Sheets allows the user to select the style in which the page is displayed using the view>page style menu. Through Alternate Style Sheet, user can see a multiple version of the page on their needs and preferences.

View detailed answer →

Question 38: CSS rule to disable text selection highlighting?

Answer: All of the correct CSS variations are:.noselect { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;}<p> Selectable text.</p><p class="noselect"> Unselectable text.</p>

View detailed answer →

Question 39: How to vertically center a div for all browsers?

Answer: Below is the best all-around solution build to vertically & horizontally center a fixed-width, flexible height content box. Tested and working for recent versions of FF, Opera, Chrome, & Safari, and MSIE 6+. HTML <div class="outer"><div class="middle"><div class="inner"> <h1>The Content</h1> <p>Once upon a midnight dreary...</p> </div></div></div>CSS .outer { display: table; position: absolute; height: 100%; width: 100%;} .middle { display: table-cell; vertical-align: middle;} .inner { margin-left: auto; margin-right: auto; width: /*whatever width you want*/;}To accommodate f...

View detailed answer →

Question 40: How to apply CSS to iframe?

Answer: There are two different things here: the style of the iframe block and the style of the page embedded in the iframe. You can set the style of the iframe block the usual way: <iframe name='iframe1' id="iframe1" src="empty.htm" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe> The style of the page embedded in the iframe must be either set by including it in the child page: <link type="text/css" rel="Stylesheet" href="Style/simple.css" /> Or it can be loaded from the parent page with Javascript: var cssLink = document.createElement("link") cssLink.href = "style.css"; cs...

View detailed answer →

Question 41: How do you get the footer to stay at the bottom of a Web page?

Answer: Sticky footer on Google: Have a <div> with class="wrapper" for your content. Right before the closing </div> of the wrapper place the <div class="push"></div>. Right after the closing </div> of the wrapper place the <div class="footer"></div>. * { margin: 0;}html, body { height: 100%;}.wrapper { min-height: 100%; height: auto !important; height: 100%; margin: 0 auto -142px; /* the bottom margin is the negative value of the footer's height */}.footer, .push { height: 142px; /* .push must be the same height as .footer */}

View detailed answer →

Question 42: List out the advantages of using CSS

Answer: Advantages of CSS: Easier to maintain and update. Greater consistency in design. More formatting options. Lightweight code.  

View detailed answer →

Question 43: When CSS was released?

Answer:  It was released on December 17, 1996; 24 years ago A short history of CSS until 2016. [Much of this content showed up before as section 20 of the book Cascading Style Sheets – structuring for the Web.] The adventure of CSS begins in 1994. Håkon Wium Lie works at CERN – the support of the Web – and the Web is beginning to be utilized as a stage for electronic distributing.

View detailed answer →

Question 44: Who developed CSS?

Answer: Håkon Wium Lie; Bert Bos; World Wide Web Consortium.   CSS stands for Cascading Style Sheets CSS describes how HTML elements are to be displayed on screen, paper, or in other media CSS saves a lot of work. It can control the layout of multiple web pages all at once External stylesheets are stored in CSS files  

View detailed answer →

Question 45: What are the different types of Selectors in CSS?

Answer: A CSS selector is the part of a CSS ruleset that actually selects the content you want to style. Different types of selectors are listed below. Universal Selector: The universal selector works like a wildcard character, selecting all elements on a page. In the given example, the provided styles will get applied to all the elements on the page. * { color: "green"; font-size: 20px; line-height: 25px; } Element Type Selector: This selector matches one or more HTML elements of the same name. In the given example, the provided styles will get applied to all the ul elements on the page. ul { line-style: none; border: solid 1px #ccc; } ID ...

View detailed answer →

Question 46: What is VH/VW (viewport height/ viewport width) in CSS?

Answer: It’s a CSS unit used to measure the height and width in percentage with respect to the viewport. It is used mainly in responsive design techniques. The measure VH is equal to 1/100 of the height of the viewport. If the height of the browser is 1000px, 1vh is equal to 10px. Similarly, if the width is 1000px, then 1 vw is equal to 10px.

View detailed answer →

Question 47: Difference between reset vs normalize CSS?. How do they differ?

Answer: Reset CSS: CSS resets aim to remove all built-in browser styling. For example margins, paddings, font-sizes of all elements are reset to be the same.  Normalize CSS: Normalize CSS aims to make built-in browser styling consistent across browsers. It also corrects bugs for common browser dependencies.

View detailed answer →

Question 48: What is the difference between inline, inline-block, and block?

Answer: Block Element: The block elements always start on a new line. They will also take space for an entire row or width. List of block elements are <div>, <p>. Inline Elements: Inline elements don't start on a new line, they appear on the same line as the content and tags beside them. Some examples of inline elements are <a>, <span> , <strong>, and <img> tags.  Inline Block Elements: Inline-block elements are similar to inline elements, except they can have padding and margins added on all four sides.

View detailed answer →

Question 49: How do you test the webpage in different browsers?

Answer: It’s most important to test a website in different browsers when you’re first designing it, or when making major changes. However, it’s also important to repeat these tests periodically, since browsers go through a lot of updates and changes.

View detailed answer →

Question 50: How do you specify units in the CSS?. What are the different ways to do it?

Answer: There are different ways to specify units in CSS like px, em, pt, percentage (%). px(Pixel) gives fine-grained control and maintains alignment because 1 px or multiple of 1 px is guaranteed to look sharp. px is not cascade. em maintains relative size. you can have responsive fonts. Em, will cascade 1em is equal to the current font-size of the element or the browser default. If u sent font-size to 16px then 1em = 16px. The common practice is to set default body font-size to 62.5% (equal to 10px). pt(point) are traditionally used in print. 1pt = 1/72 inch and it is a fixed-size unit. %(percentage) sets font-size relative to the font size of the...

View detailed answer →

Question 51: What does DOM reflow occur?

Answer: Reflow is the name of the web browser process for re-calculating the positions and geometries of elements in the document, for the purpose of re-rendering part or all of the document.  Reflow occurs when: Insert, remove or update an element in the DOM. Modify content on the page, e.g. the text in an input box. Move a DOM element. Animate a DOM element. Take measurements of an element such as offsetHeight or getComputedStyle. Change a CSS style.

View detailed answer →

Question 52: Different Box Sizing Property?

Answer: The box-sizing CSS property sets how the total width and height of an element are calculated. Content-box: The default width and height values apply to the element's content only. The padding and border are added to the outside of the box. Padding-box: Width and height values apply to the element's content and its padding. The border is added to the outside of the box. Currently, only Firefox supports the padding-box value. Border-box: Width and height values apply to the content, padding, and border.

View detailed answer →

Question 53: Can you name the four types of @media properties?

Answer: The four types of @media properties are: All → It’s the default property. Used for all media-type devices. Screen → Used for computer screen, mobile screen. Print → Used for printers. Speech → Used for screen readers.

View detailed answer →

Question 54: What does Accessibility (a11y) mean?

Answer: Accessibility refers to how software or hardware combinations are designed to make a system accessible to persons with disabilities, such as visual impairment, hearing loss, or limited dexterity. For example, a website developed with accessibility in mind might have text-to-speech capabilities. In the USA public websites have to have accessible compliance. It’s defined in 508 compliance. It gives the guidelines and best practices for all website users that should be met with key areas of accessibility.

View detailed answer →

Question 55: What does important mean in CSS?

Answer: The style is having the important will have the highest precedence and it overrides the cascaded property.  p {   color: red !important;  }  #thing {   color: green;  }    <p id="thing">Will be RED.</p>

View detailed answer →

Question 56: Distinguish between CSS2 and CSS3.

Answer:  The differences between CSS2 and CSS3 are as follows: CSS3 is divided into two various sections which are called a module. Whereas in CSS2 everything accedes into a single document with all the information in it. CSS3 modules are supported almost on every browser and on the other hand modules of CSS and CSS2 are not supported in every browser. In CSS3, we will find that many graphics related characteristics have been introduced like Border-radius or box-shadow, flexbox. In CSS3, a user can precise multiple background images on a webpage by using properties like background-image, background-position, and background-repeat styles.

View detailed answer →

Question 57: Why is the external style sheet useful?

Answer:  External style sheet is very useful as we write all the styling codes in a single file and it can be used anywhere by just referring to the link of that external style sheet file. So, if we do any changes in that external file, then the changes can also be observed on the webpage. Thus we can say that it is very useful and it makes your work easy while working on larger files.

View detailed answer →

Question 58: Explain the term Responsive web design.

Answer:  It is a method in which we design and develop a web page according to the user activities and conditions which are based on various components like the size of the screen, portability of the web page on the different devices, etc. It is done by using different flexible layouts and grids.

View detailed answer →

Question 59: What is CSS specificity?

Answer: CSS specificity is a score or rank that decides which style declaration has to be used to an element. (*) this universal selector has low specificity while ID selectors have high specificity. There are four categories in CSS which authorize the specificity level of the selector. Inline style IDs Classes, Attributes, and pseudo-classes. Elements and pseudo-elements.

View detailed answer →
Css interview preparation tip: Start with basic definitions, then prepare practical examples, common mistakes, project usage, scenario-based questions and HR discussion points.