Css Interview Questions
Css Interview Questions
Ans.
Embedded style sheet is CSS code written within the <style> tag in
the head section of an HTML document.
• Embedded style sheet is used to define styles for a single HTML
document.
• It is written within the <style> tag in the head section of the
HTML document.
• Styles defined in the embedded style sheet will only apply to the
HTML document it is written in.
View 1 answer
Yes
No
Q5. Create a responsive template using pure CSS(flex, grid,
media query) without using any library or framework!
Ans.
Creating a responsive template using pure CSS without any library or
framework.
• Start with a mobile-first approach
• Use media queries to adjust layout for different screen sizes
• Utilize flexbox and/or grid for layout and positioning
• Test on multiple devices and browsers
Add your answer
Q7. how do you display different color in atable using css for odd
even rows
Ans.
To display different colors in a table using CSS for odd and even
rows, you can use the :nth-child() selector.
• Use the :nth-child(odd) selector to target odd rows and apply a
specific color using the background-color property.
• Use the :nth-child(even) selector to target even rows and apply a
different color using the background-color property.
• For example, you can use CSS code like this: tr:nth-child(odd) {
background-color: #f2f2f2; } tr:nth-child(even) { background-
color: #fff...read more
Add your answer
Frequently asked in
Housing.com
Q10. What is the difference between display as flex and display as
grid?
Ans.
Flexbox is a one-dimensional layout model, while Grid is a two-
dimensional layout model.
• Flexbox is best suited for arranging items in a single row or
column.
• Grid is ideal for creating complex layouts with rows and
columns.
• Flexbox provides flexibility in distributing space among items.
• Grid allows precise control over the placement and sizing of
items.
• Flexbox is simpler and easier to understand, while Grid offers
more advanced features.
View 1 answer
Frequently asked in
IDC Technologies
Q13. What is HTML, PHP and CSS
Ans.
HTML, PHP, and CSS are programming languages used for creating
and designing websites.
• HTML (Hypertext Markup Language) is used for creating the
structure and content of web pages.
• PHP (Hypertext Preprocessor) is a server-side scripting
language used for creating dynamic web pages.
• CSS (Cascading Style Sheets) is used for styling and formatting
the layout of web pages.
• Example: HTML is used to create headings, paragraphs, and
lists on a webpage.
• Example: PHP is used to interact wi...read more
Add your answer
Frequently asked in
TCS
Q15. Difference between display-block and inline-block
Ans.
display-block takes up full width, while inline-block only takes up
necessary width.
• display-block elements start on a new line and take up the full
width available, like <div>
• inline-block elements do not start on a new line and only take up
as much width as necessary, like <span>
• display-block elements can have margin and padding applied on
all sides, while inline-block elements only have margin and
padding applied horizontally
Add your answer
Q20. What are the different attributes of the CSS position property?
Ans.
The CSS position property defines the positioning method of an
element.
• Static: Default position, elements are positioned according to the
normal flow of the document.
• Relative: Positioned relative to its normal position.
• Absolute: Positioned relative to the nearest positioned ancestor.
• Fixed: Positioned relative to the viewport, does not move when
the page is scrolled.
• Sticky: Acts like a combination of relative and fixed positioning.
Add your answer
Frequently asked in
Housing.com
Q21. What are pseudo classes
Ans.
Pseudo classes are keywords used in CSS to select and style elements
based on their state or position in the document.
• Pseudo classes start with a colon (:) followed by the keyword
• They are used to style elements based on their state, such as
:hover, :active, :focus
• They can also be used to select elements based on their position
in the document, such as :first-child, :last-child
• Pseudo classes can be combined with other selectors to create
more specific styles
Add your answer
Q22. Difference between flex and grid
Ans.
Flex is one-dimensional layout while Grid is two-dimensional layout.
• Flex is used for creating flexible and responsive layouts.
• Grid is used for creating complex and structured layouts.
• Flex is best suited for small-scale layouts while Grid is best
suited for large-scale layouts.
• Flex is easier to learn and implement while Grid requires more
advanced knowledge.
• Flex is supported by older browsers while Grid has limited
support in older browsers.
Add your answer
Frequently asked in
Accenture
Q24. Why we use SCSS ?
Ans.
SCSS is used to write more maintainable and scalable CSS code.
• SCSS allows for nesting of CSS rules, making it easier to read
and organize code.
• Variables and mixins in SCSS can be reused throughout the
codebase, reducing redundancy.
• SCSS also supports inheritance, allowing for more efficient and
modular code.
• It compiles to regular CSS, so it can be used in any web project.
• SCSS is widely used in modern web development frameworks
like React and Angular.
Add your answer
Frequently asked in
Cognizant
Q28. Explain the order of specifity in CSS classes, elements, ids,
etc
Ans.
Explanation of CSS specificity hierarchy
• Inline styles have the highest specificity
• IDs have higher specificity than classes and elements
• Multiple selectors with the same specificity are resolved by the
order in which they appear in the stylesheet
• The universal selector (*) has the lowest specificity
Add your answer
Frequently asked in
Cybage
Q30. What happened if u not mentioned any font style in css?
Ans.
If no font style is mentioned in CSS, the browser will use its default
font style.
• The browser will use its default font style if not specified in
CSS.
• The default font style may vary depending on the browser and
operating system.
• It is recommended to always specify a font style in CSS to
ensure consistent rendering across different platforms.
View 2 more answers
Q35. You were given CSS code and asked to debug it to make the
functionality work. Can you describe the process you followed and
the issues you encountered?
Ans.
I followed a systematic process to debug CSS code and resolve
functionality issues.
• Reviewed the CSS code to identify any syntax errors or typos
• Checked for any conflicting styles that may be overriding the
desired functionality
• Used browser developer tools to inspect elements and
troubleshoot layout issues
• Tested different scenarios to pinpoint the exact cause of the
problem
• Made necessary adjustments to the CSS code to fix the
functionality
Add your answer
Frequently asked in
Tata Communications
Q37. What are css elements?
Ans.
CSS elements are the building blocks of Cascading Style Sheets that
define the appearance of HTML elements.
• CSS elements are used to style HTML elements
• They include selectors, properties, and values
• Selectors target specific HTML elements, while properties
define their appearance
• Values determine the specific style of the property
• Examples of CSS elements include color, font-size, margin,
padding, etc.
Add your answer
Frequently asked in
Siemens
Q40. What is the use of seudo class in css
Ans.
Pseudo classes are used to define a special state of an element.
• Pseudo classes are preceded by a colon (:)
• They are used to style elements based on their state or position
• Examples include :hover, :active, :first-child, :nth-child
Add your answer
Frequently asked in
CitiusTech
Q49. What are the specificity rules in CSS?
Ans.
Specificity rules in CSS determine which styles are applied to an
element when multiple conflicting styles are present.
• Specificity is calculated based on the type of selector used (ID,
class, element) and the number of each type of selector.
• ID selectors have the highest specificity, followed by class
selectors, and then element selectors.
• Inline styles have the highest specificity and will always
override external stylesheets.
• Specificity is represented by a four-part value (a,...read more
Add your answer
Frequently asked in
CitiusTech
Q50. In how many ways can you display HTML elements?
Ans.
There are multiple ways to display HTML elements, including inline,
block, inline-block, and flex.
• Inline elements flow in a line with other elements and do not
start on a new line. Example: <span>
• Block elements start on a new line and take up the full width
available. Example: <div>
• Inline-block elements are similar to inline elements but can have
block-level properties. Example: <img>
• Flex elements use the flexbox layout model for more advanced
control over layout. Example: <d...read more
Add your answer
Frequently asked in
Practo
Q51. what is css and type of css?
Ans.
CSS stands for Cascading Style Sheets. It is used to style and layout
web pages.
• CSS is used to add colors, fonts, and layouts to web pages.
• There are three types of CSS: inline, internal, and external.
• Inline CSS is used to style a single element.
• Internal CSS is used to style a single web page.
• External CSS is used to style multiple web pages.
• CSS can be used to create responsive designs that adapt to
different screen sizes.
Add your answer
Q55. What are types of CSS and which has more priority
Ans.
Types of CSS include inline, internal, external, and imported. Inline
has the highest priority.
• Types of CSS: inline, internal, external, imported
• Inline CSS has the highest priority
• Internal CSS is defined within the HTML document
• External CSS is linked to the HTML document using a tag
• Imported CSS is used to import an external style sheet within
another style sheet
Add your answer
Frequently asked in
Accenture
Q61. Which version of css used
Ans.
CSS has multiple versions, the latest being CSS3.
• CSS1 was released in 1996
• CSS2 was released in 1998
• CSS3 is the latest version
• CSS3 has many new features like animations, transitions, and
flexbox
Add your answer
Q64. What are the different ways to link css? Which has the
highest priority?
Ans.
There are three ways to link CSS: inline, internal, and external. Inline
has the highest priority.
• Inline CSS is applied directly to an HTML element using the
'style' attribute.
• Internal CSS is defined within the 'style' tags in the head section
of an HTML document.
• External CSS is linked to an HTML document using the 'link'
tag with the 'rel' attribute set to 'stylesheet'.
• Inline CSS has the highest priority, followed by internal CSS,
and then external CSS.
Add your answer
Frequently asked in
CitiusTech
Q73. What are the css style specificities
Ans.
CSS specificity determines which style rules are applied to an
element.
• Specificity is calculated based on the number of selectors and
their types.
• Inline styles have the highest specificity.
• IDs have higher specificity than classes and attributes.
• The universal selector (*) has zero specificity.
• The !important keyword overrides specificity.
• Selectors with equal specificity are applied in the order they
appear in the stylesheet.
Add your answer
Frequently asked in
CitiusTech
Q74. What is Mixin in SCSS ?
Ans.
Mixin is a reusable block of code in SCSS that can be included in
other stylesheets.
• Mixin allows developers to define a set of CSS declarations that
can be reused throughout the stylesheet.
• It helps in reducing code duplication and makes the code more
maintainable.
• Mixin can take arguments and can be used to generate different
styles based on the arguments passed.
• Mixin can be defined using the @mixin directive and included
using the @include directive.
Add your answer
Frequently asked in
Accenture
Q76. How to use negative margin
Ans.
Negative margin is used to shift an element outside its container. It
can be used for layout and positioning.
• Negative margin can be used to create overlapping elements.
• It can be used to center an element horizontally or vertically.
• Negative margin can also be used to create a sticky footer.
• It should be used with caution as it can cause layout issues.
• Example: margin-top: -10px; will move the element 10 pixels
above its original position.
Add your answer
Frequently asked in
Capgemini
Q86. Tell the five background properties in CSS
Ans.
Background properties in CSS are used to control the background of
an element.
• background-color: sets the background color of an element
• background-image: sets an image as the background of an
element
• background-repeat: specifies how a background image should
repeat
• background-position: sets the starting position of a background
image
• background-size: specifies the size of the background image
Add your answer
Q87. What is the difference between display flex and display grid
Ans.
Display flex is for one-dimensional layouts, while display grid is for
two-dimensional layouts.
• Display flex is used for creating layouts in one direction (either
row or column)
• Display grid is used for creating layouts in two dimensions
(rows and columns)
• Flexbox is more suitable for small-scale layouts, while Grid is
better for larger layouts with more complex structures
Add your answer
Frequently asked in
Standard Chartered
Q91. What is linear gradient in Css?
Ans.
Linear gradient in CSS is a gradual transition between two or more
colors along a straight line.
• Linear gradient is created using the linear-gradient() function in
CSS.
• It allows for a smooth transition of colors from one point to
another along a straight line.
• You can specify the direction, angle, and color stops for the
gradient.
• Example: background: linear-gradient(to right, red, blue);
Add your answer
Q96. How to add internal and external css in html code Difference
between HTML5 & HTML
Ans.
Internal CSS is added within the <style> tag in the <head> section of
HTML, while external CSS is linked using the <link> tag.
• Internal CSS is added within the <style> tag in the <head>
section of HTML
• External CSS is linked using the <link> tag with the 'rel'
attribute set to 'stylesheet' and the 'href' attribute pointing to the
CSS file
• Example: <style> body { background-color: lightblue; }
</style> <link rel='stylesheet' href='styles.css'>
Add your answer
Q97. CSS Locators for website
Ans.
CSS Locators are used to target specific elements on a website for
styling or interaction.
• Use ID selector: #elementID
• Use class selector: .elementClass
• Use attribute selector: [attribute=value]
• Use descendant selector: parentElement childElement
• Use pseudo-class selector: element:hover
Add your answer
Frequently asked in
CitiusTech
Q103. Pseudo class vs Pseudo element
Ans.
Pseudo class selects elements based on their state, while pseudo
element selects parts of an element.
• Pseudo class is used to style elements based on their state, such
as :hover, :active, :focus.
• Pseudo element is used to style specific parts of an element,
such as ::before, ::after, ::first-line.
• Pseudo class starts with a single colon (:), while pseudo element
starts with a double colon (::).
Add your answer
Yes
No
Q105. Sudo selectors in css
Ans.
Sudo selectors in CSS are special selectors that allow you to target
elements based on their state or position in the document.
• Sudo selectors start with a colon (:), such as :hover, :active,
:focus, etc.
• They can be used to style elements based on user interaction,
like hovering over a button.
• Sudo selectors can also be used to target specific child elements,
like :first-child or :nth-child.
Add your answer
Frequently asked in
Capgemini
Q112. how do you develop CSS for different devices
Ans.
To develop CSS for different devices, use media queries, responsive
design principles, and testing on various devices.
• Use media queries to apply different CSS styles based on the
device's screen size
• Follow responsive design principles to ensure the layout adapts
to different devices
• Test the CSS on various devices to ensure compatibility and
responsiveness
Add your answer
Q114. How can you applied a certain css on three div element?
Ans.
You can apply a certain CSS on three div elements by using a
common class or ID for all three divs.
• Add a common class or ID to all three div elements
• Define the CSS properties for that class or ID in your stylesheet
• Apply the class or ID to each of the three div elements in your
HTML markup
Add your answer
Q115. What is difference between position relative and absolute
Ans.
Position relative is relative to its normal position, while position
absolute is relative to its nearest positioned ancestor.
• Position relative moves an element relative to its normal
position.
• Position absolute moves an element relative to its nearest
positioned ancestor.
• Position absolute elements are taken out of the normal flow of
the document.
Add your answer
Frequently asked in
Amdocs
Q119. What is use of margin-left and margin-top in css of fixed
layout
Ans.
margin-left and margin-top in CSS of fixed layout are used to define
the distance between the left and top edges of an element and its
containing element.
• margin-left sets the left margin of an element
• margin-top sets the top margin of an element
• These properties are commonly used in fixed layout to position
elements within a container
• They can be specified in pixels, percentages, or other length
units
• Example: margin-left: 20px; margin-top: 10px; will move the
element 20 pixels t...read more
View 1 answer
Frequently asked in
Aptara
Q120. What are the various selector in CSS.
Ans.
CSS selectors are used to target HTML elements and apply styles to
them.
• Type selectors target elements based on their tag name (e.g. h1,
p, div)
• Class selectors target elements with a specific class attribute
(e.g. .my-class)
• ID selectors target elements with a specific ID attribute (e.g.
#my-id)
• Attribute selectors target elements with a specific attribute value
(e.g. [href='https://www.example.com'])
• Pseudo-class selectors target elements based on their state or
position (e.g. ...read more
Add your answer
Q125. write the xpath or CSS code for selected value in the
amazon site
Ans.
XPath code for selected value in Amazon site
• Use the 'contains' function to locate the selected value
• Identify the unique attributes of the selected value to create a
specific XPath
• Consider using the 'text()' function to locate text within an
element
Add your answer
Frequently asked in
Wipro
Q129. What is CSS3 flexbox
Ans.
CSS3 flexbox is a layout module that provides a more efficient way to
align and distribute space among items in a container.
• Flexbox allows for flexible and responsive layouts without using
floats or positioning.
• It uses a parent container and child elements with flexible
properties to create the layout.
• Properties include justify-content, align-items, and flex-wrap.
• Flexbox is supported by all modern browsers.
• Example:
Item 1
Item 2
Add your answer
Frequently asked in
Tata Communications
Q130. Different between inline elements and block elements in css
Ans.
Inline elements flow in the same line, while block elements take up
the full width available.
• Inline elements do not start on a new line and only take up as
much width as necessary.
• Block elements start on a new line and take up the full width
available.
• Examples of inline elements include span, a, and strong.
• Examples of block elements include div, p, and h1.
Add your answer
Frequently asked in
Infogain
Q135. Different between Grid Flex box layout
Ans.
Grid layout is a two-dimensional layout system while Flexbox is a
one-dimensional layout system.
• Grid layout is best for overall page layout, while Flexbox is best
for aligning items within a container.
• Grid layout allows for precise placement of elements in rows
and columns, while Flexbox is more flexible in arranging items
in a single row or column.
• Grid layout is better suited for complex layouts with multiple
rows and columns, while Flexbox is ideal for simpler layouts
with ...read more
Add your answer
Frequently asked in
TCS
Q139. Pseudo class in CSS
Ans.
Pseudo classes in CSS are used to define the special states of an
element.
• Pseudo classes start with a colon (:)
• They are used to style elements based on user interaction or
element state
• Common pseudo classes include :hover, :active, :focus
Add your answer
Q141. What is css media queries and difference between min and
max
Ans.
CSS media queries are used to apply different styles based on device
characteristics. Min and max define the range of values.
• Media queries allow for responsive design by adapting to
different screen sizes and orientations
• Min-width and max-width are commonly used to define the
range of screen sizes
• Min-device-width and max-device-width are used to target
specific device characteristics
• Other media query features include min-height, max-height,
orientation, and resolution
Add your answer
Frequently asked in
Oracle
Q148. How to use positions in css
Ans.
CSS positions are used to control the layout of elements on a
webpage.
• Use 'static', 'relative', 'absolute', or 'fixed' to position elements.
• Elements with 'position: relative' are positioned relative to their
normal position.
• Elements with 'position: absolute' are positioned relative to the
nearest positioned ancestor.
• Elements with 'position: fixed' are positioned relative to the
viewport.
• Use 'top', 'bottom', 'left', and 'right' properties to further adjust
the position of elem...read more
Add your answer
Frequently asked in
G4S
Q155. CSS specificity.
Ans.
CSS specificity determines which CSS rule applies when multiple
rules target the same element.
• CSS specificity is calculated based on the number of ID
selectors, class selectors, and element selectors in a rule.
• ID selectors have the highest specificity, followed by class
selectors, and then element selectors.
• Inline styles have the highest specificity and override all other
styles.
• The !important keyword can be used to override all other styles,
but should be used sparingly.
• Spec...read more
Add your answer
Q156. What is the difference between CSS and SASS? what is the
use of Sass
Ans.
SASS is a preprocessor scripting language that is interpreted into
CSS, offering more features and flexibility.
• SASS is a preprocessor for CSS, allowing for variables, nesting,
and mixins to be used in stylesheets.
• SASS code needs to be compiled into CSS before being used in
a web project.
• SASS helps in writing cleaner and more organized CSS code,
making it easier to maintain and update styles.
• CSS is the styling language used for web development, while
SASS is a tool that extend...read more
Add your answer
Frequently asked in
LTIMindtree
Q157. elements of css
Ans.
Elements of CSS include selectors, properties, values, and units.
• Selectors are used to target specific HTML elements for styling.
• Properties define the style to be applied, such as color or font-
size.
• Values are the specific settings for the properties, like 'red' or
'20px'.
• Units specify the measurement type, such as pixels or
percentages.
Add your answer
Q162. What is html? What is css? Tell me about css and types
Ans.
HTML is a markup language used for creating the structure of web
pages. CSS is a styling language used for designing the appearance of
web pages.
• HTML stands for HyperText Markup Language
• HTML is used to create the structure of web pages using
elements like <div>, <p>, <h1>, etc.
• CSS stands for Cascading Style Sheets
• CSS is used to style the appearance of web pages by defining
properties like color, font size, layout, etc.
• Types of CSS include inline, internal, and external styles...read
more
Add your answer
Frequently asked in
ICICI Bank
Q163. Explain about CSS positions?
Ans.
CSS positions determine the layout of an element on a web page.
• There are four types of CSS positions: static, relative, absolute,
and fixed.
• Static is the default position and elements are positioned
according to the normal flow of the page.
• Relative positions elements relative to their normal position.
• Absolute positions elements relative to the nearest positioned
ancestor.
• Fixed positions elements relative to the viewport and remains in
the same position even when the page is s...read more
View 1 answer
Frequently asked in
Accenture
Q170. Difference between display flex and display block
Ans.
display flex allows for flexible layouts with items displayed in a row
or column, while display block stacks items vertically.
• display flex allows for items to be displayed in a row or column,
with the ability to adjust spacing, alignment, and order
• display block stacks items vertically, taking up the full width
available
Add your answer
Frequently asked in
ICICI Bank
Q179. different between grid and flex box
Ans.
Grid is a 2D layout system while Flexbox is a 1D layout system.
• Grid is used for complex layouts while Flexbox is used for
simpler layouts.
• Grid allows for precise placement of elements while Flexbox is
more flexible.
• Grid is better for aligning items in both rows and columns while
Flexbox is better for aligning items in a single row or column.
• Grid is supported in modern browsers while Flexbox has wider
browser support.
Add your answer
Frequently asked in
Exterro
Q187. From CSS - What is box model?
Ans.
Box model is a fundamental concept in CSS which defines the
spacing and dimensions of an element.
• The box model consists of content, padding, border, and margin.
• Content area is where the actual content of the element is
displayed.
• Padding is the space between the content and the border.
• Border surrounds the padding and content.
• Margin is the space outside the border, separating the element
from other elements.
• Example: div { width: 200px; padding: 20px; border: 1px solid
black; ma...read more
Add your answer
Frequently asked in
TCS
Q188. Difference in CSS Selectors like class, id
Ans.
Classes can be used multiple times, IDs are unique. Classes are
denoted by a dot, IDs by a hash.
• Classes can be used multiple times in a document, IDs can only
be used once
• Classes are denoted by a dot (.), IDs are denoted by a hash (#)
• Example: .class1 { color: red; } #id1 { font-size: 16px; }
Add your answer
Frequently asked in
TCS
Q189. xpath and CSS difference
Ans.
XPath is used to navigate through XML documents, while CSS is
used to style HTML elements.
• XPath is more powerful and flexible for navigating XML
documents
• CSS is more commonly used for styling HTML elements
• XPath uses path expressions to select nodes in an XML
document
• CSS uses selectors to target specific HTML elements
Add your answer
Q191. What are the benefits of CSS file for Web Designers?
Ans.
CSS files provide numerous benefits for web designers.
• CSS files separate the design and layout of a website from its
content, making it easier to update and maintain.
• They allow for consistent styling across multiple web pages,
saving time and effort.
• CSS files enable the use of responsive design techniques,
ensuring that websites look good on different devices and screen
sizes.
• They provide flexibility in terms of customization and allow for
easy experimentation with different ...read more
View 1 answer
Frequently asked in
Snapdeal
Q193. What is the difference between inline block and a normal
block in CSS
Ans.
Inline block is similar to inline but can have width and height
properties. Normal block takes up full width and creates a new line.
• Inline block elements can be aligned horizontally and vertically
within a line
• Normal block elements take up full width and create a new line
• Inline block elements can have width and height properties
• Examples of inline block elements are images and buttons
• Examples of normal block elements are paragraphs and
headings
Add your answer
Frequently asked in
AmbitionBox
Q195. What is justify content
Ans.
justify-content is a CSS property that defines how flex items are
aligned along the main axis of a flex container.
• It is used in CSS flexbox layout.
• It controls the alignment of flex items horizontally.
• Possible values include: flex-start, flex-end, center, space-
between, space-around, and space-evenly.
• Default value is flex-start.
Add your answer