CSS Interview Questions For Freshers

In how many ways can we add CSS to our HTML file?

CSS is used to style HTML elements on web pages, like setting background colors, font sizes, and colors.

There are three types of CSS:

  1. Inline CSS: Style information is directly added to HTML elements using the “style” attribute. This style applies only to that specific element.
  2. Internal or Embedded CSS: Style rules are written within the HTML file, typically in the <head> section. This method is useful when you want to style a single HTML document uniquely.
  3. External CSS: Style rules are stored in a separate CSS file with a .css extension. This file is then linked to the HTML document using the <link> tag. Changes made in this file affect the styling across multiple web pages.

Each type of CSS has its own advantages and use cases, depending on the specific needs of the website or web application.

Which type of CSS holds the highest priority?

When you apply styles directly to HTML elements using inline CSS, those styles have the highest priority. They override any styles defined in internal or external style sheets.

Next in priority are styles defined in the internal or embedded CSS. These styles override those defined in external style sheets but are overridden by inline styles.

Lastly, styles from external style sheets have the lowest priority. If no styles are applied inline or internally, then the styles from the external style sheet are used.

 How can we add comments in CSS?

Comments are the statements in your code that are ignored by the compiler and are not executed. Comments are used to explain the code. They make the program more readable and understandable.

What does the ‘a’ in rgba mean?

RGBA includes an “Alpha” component that determines how transparent an element is. The Alpha value ranges from 0.0 to 1.0, where 0.0 means fully see-through (completely transparent) and 1.0 means fully opaque (not transparent at all

What is CSS Box Model?

The CSS box model is a container that contains multiple properties including borders, margin, padding, and the content itself. It is used to create the design and layout of web pages. It can be used as a toolkit for customizing the layout of different elements. The web browser renders every element as a rectangular box according to the CSS box model.

Box-Model has multiple properties in CSS. Some of them are given below:

  • borders
  • margins
  • padding
  • Content