HTML_CSS Interview Questions
HTML_CSS Interview Questions
1. What is HTML?
2. What are the basic building blocks of HTML?
3. What is the DOCTYPE declaration in HTML?
4. What is the difference between HTML elements, tags, and attributes?
5. What are some common HTML tags?
6. What is the purpose of the <head> tag in HTML?
7. What is the purpose of the <body> tag in HTML?
8. What is the difference between block-level elements and inline elements?
9. What is the difference between HTML and XHTML?
10. What is the purpose of the <div> tag in HTML?
11. What is the purpose of the <span> tag in HTML?
12. What is the purpose of the<meta> tag?
13. What is semantic HTML?
14. What are HTML entities?
15. What is the purpose of the alt attribute in <img> tags?
16. What is the purpose of the <img> tag in HTML?
17. What is the purpose of the src attribute in the <img> tag?
18. What are the various formatting tags in HTML?
19. Describe HTML layout Structure?
20. Are the HTML tags and elements the same thing?
21. What is the purpose of the href attribute in the tag?
22. What is the purpose of the target attribute in the tag?
23. What is the difference between a local and a session storage in HTML5?
24. What is the purpose of the tabindex attribute?
25. What is a self-closing tag? Give an example.
26. Explain the purpose of the <iframe> tag.
27. What is the purpose of the <noscript> tag?
28. What is the purpose of the <table> tag in HTML?
29. What are the <thead>, <tbody>, and <tfoot> tags used for?
30. What is the purpose of the <tr> tagin HTML?
31. What is the purpose of the <th> and <td> tags in HTML?
32. What is the purpose of the colspan and rowspan attributes in the <td> and <th>tags?
33. What is the purpose of the <audio> and <video> tags in HTML?
34. What is the purpose of the <canvas> tag in HTML?
35. What is the purpose of the <figure> and <figcaption> tags in HTML?
36. What are different types of lists in HTML?
37. What is the ‘class’ attribute in HTML?
38. What is the difference between the ‘id’ attribute and the ‘class’ attribute of HTML
elements?
39. In how many ways can we position an HTML element? Or what are the permissible
values of the position attribute?
40. What are forms and how to create forms in HTML?
41. Explain new input types provided by HTML5 for forms?
42. Can we display a web page inside a web page or Is nesting of web pages possible?
43. How is Cell Padding different from Cell Spacing?
44. How can we club two or more rows or columns into a single row or column in an
HTML table?
45. Is it possible to change an inline element into a block level element?
46. Explain the difference between GET and POST methods in HTML forms.
47. What are the new features in HTML5 compared to HTML4?
48. How can you add comments in HTML?
49. What is the purpose of the HTML <article> tag?
50. How can you create a line break in HTML?
51. How do you embed video in html?
52. What is the purpose of the <time> tag in HTML?
53. What is the purpose of the <pre> tag in HTML?
54. What is the purpose of the download attribute in the <a> tag?
55. What is the purpose of the <script> tag in HTML?
56. What is the difference between inline and external JavaScript?
57. What is the purpose of the title attribute in HTML?
58. What is the purpose of the <fieldset> and < legend> tags in HTML?
59. What is the purpose of the required attribute in form elements?
60. What is the purpose of the autocomplete attribute in form elements?
61. What is the purpose of the disabled attribute in form elements?
62. What is the purpose of the readonly attribute in form elements?
63. What is the purpose of the <progress> tag in HTML?
64. What is the purpose of the <details> and <summary> tags in HTML?
65. What is the purpose of the spellcheck attribute in form elements?
66. What is the purpose of the <meter> tag in HTML?
67. how can you create an external link that opens in a new tab?
68. Explain the difference between absolute and relative URLs.
69. How to include javascript code in HTML?
70. When to use scripts in the head and when to use scripts in the body?
71. How Do You Create A Table In Html?
72. What are the New tags in Media Elements in HTML5?
73. What are the significant goals of the HTML5 specification?
74. How to handle events in HTML?
75. What are void elements in HTML?
76. What is the difference between “display: none” and “visibility: hidden”, when used as
attributes to the HTML element.
CSS Technical Interview Questions
a. HTML stands for Hypertext Markup Language. It is the standard markup language used for
creating web pages.
a. The basic building blocks of HTML are tags, which are used to structure and define the
content of a web page.
a. The DOCTYPE declaration is used to specify the version of HTML that the web page is
written in. It helps the browser render the page correctly.
a. HTML elements are the individual components that make up a web page, such as headings,
paragraphs, and images. Tags are used to mark the beginning and end of HTML elements.
Attributes provide additional information or modify the behavior of HTML elements.
a. Some common HTML tags include <h1> to <h6> for headings, <p> for paragraphs,
<a> for links, <img> for images, <ul> and <li> for unordered lists, and <table> for
tables.
6. What is the purpose of the <head> tag in HTML?
a. The <head> tag is used to contain meta-information about the HTML document,
such as the title, character encoding, and linked stylesheets or scripts.
a. Block-level elements start on a new line and take up the full width available,
whileinline elements do not start on a new line and only take up the necessary width
todisplay the content.
a. XHTML is stricter than HTML and follows XML syntax rules. XHTML
documents must be well-formed, meaning all elements must be properly nested and
closed.
a. The <div> tag is a container used to group and style HTML elements. It is commonly
used for layout and organization purposes.
a. The <span> tag is an inline container used to apply styles or manipulate specific
portions of text within a larger block of content.
a. The <meta> tag provides metadata about the HTML document, such as character
set, author, description, and keywords.
a. Semantic HTML is using HTML tags that convey meaning beyond just
formatting to both the browser and developer, making the structure of the webpage
more understandable.
a. HTML entities are special codes used to display characters that have a special
meaning in HTML, such as , &, ©, etc.
15. What is the purpose of the alt attribute in <img> tags?
a. The alt attribute specifies alternative text for an image if the image cannot be
displayed. It is important for accessibility and SEO.
17. What is the purpose of the src attribute in the <img> tag?
a. The src attribute specifies the source file or URL of the image.
a. Every web page has different components to display the intended content and a specific UI.
But still, there are few things which are templated and are globally accepted way to structure the
web page, such as:
20. Are the HTML tags and elements the same thing?
a. No. HTML elements are defined by a starting tag, may contain some content and a closing
tag.
For example,<h1> Heading 1</h1> is a HTML element but just <h1> is a starting tag and
</h1> is a closing tag.
a. The href attribute specifies the URL of the page the link goes to. It is used to create hyperlinks.
a. The target attribute specifies where to open the linked document. For example, "_blank"
opens the link in a new window or tab.
23. What is the difference between a local and a session storage in HTML5?
a . Local storage stores data with no expiration date, while session storage stores data only for
the duration of the page session.
a. The tabindex attribute specifies the order in which elements are focused when using the
keyboard to navigate through a webpage.
a. A self-closing tag is an HTML tag that doesn't require a separate closing tag.
29.What are the <thead>, <tbody>, and <tfoot> tags used for?
a. The <thead> tag is used to group the header content in a table. The <tbody> tag is
used to group the body content, and the <tfoot> tag is used to group the footer content.
32.What is the purpose of the colspan and rowspan attributes in the <td> and
<th>tags?
a. The colspan attribute specifies the number of columns a cell should span, and the
rowspan attribute specifies the number of rows a cell should span.
Example:
2.Unordered List (`<ul>`): This type of list is used when the order of items is not
important. Each item in an unordered list is marked with a bullet point by default, but this can
also be customized using CSS.
Example:
3.Definition List (`<dl>`): This type of list is used to define terms and their corresponding
descriptions. It consists of a series of term-definition pairs. Each term is enclosed in a <dt> tag,
and each definition is enclosed in a <dd> tag.
Example
These are the primary types of lists in HTML. Additionally, there are nested lists,
where one type of list is contained within another, which can be achieved by placing
one list inside another list element (`<ol>`, `<ul>`, or`<dl>`).
a. The class attribute is used to specify the class name for an HTML element. Multiple elements
in HTML can have the same class value. Also, it is mainly used to associate the styles written in
the stylesheet with the HTML elements.
38.What is the difference between the ‘id’ attribute and the ‘class’ attribute of HTML
elements?
a. Multiple elements in HTML can have the same class value, whereas a value of id attribute of
one element cannot be associated with another HTML element.
39.In how many ways can we position an HTML element? Or what are the permissible
values of the position attribute?
a. There are mainly 6 values of position attribute that can be used to position an HTML element:
1. static: Default value. Here the element is positioned according to the normal flow of the
document.
2. Absolute : Here the element is positioned relative to its parent element. The final position is
determined by the values of left, right, top, bottom.
3. Fixed : This is similar to absolute except here the elements are positioned relative to the
element
4. Relative : Here the element is positioned according to the normal flow of the document and
positioned relative to its original/ normal position.
6. Inherit : Here the element inherits or takes the property of its parent
a. The HTML form is used to collect the user inputs. HTML provides a
<form> tag to create forms. To take input from the user we use the <input> tag inside the form
so that all collected user data can be sent to the server for processing. There are different input
types like ‘ button ’ , ‘checkbox’, ‘number’, ‘text’, ‘password’, ‘submit’ etc.
41.Explain new input types provided by HTML5 for forms?
⚫ Email - Accepts one or more email addresses using type = "email" ⚫ Number - Accepts
a numerical value with additional checks like min and max using type = "number"
42.Can we display a web page inside a web page or Is nesting of web pages possible?
a. Yes, we can display a web page inside another HTML web page. HTML provides a tag using
which we can achieve this functionality.
43.How is Cell Padding different from Cell Spacing?
a. Cell Spacing is the space or gap between two consecutive cells. Whereas, Cell Padding is the
space or gap between the text/ content of the cell and the edge/ border of the cell. Please refer to
the above figure example to find the difference.
44. How can we club two or more rows or columns into a single row or column in an
HTML table?
a. HTML provides two table attributes “rowspan” and “colspan” to make a cell span to multiple
rows and columns respectively.
a. Yes, it is possible using the “display” property with its value as “block”, to change the inline
element into a block-level element.
46. Explain the difference between GET and POST methods in HTML forms.
a. GET method sends data through the URL, while POST method sends data in the HTTP
request body. GET is used for retrieving data, while POST is used for submitting data.
a. HTML5 introduces new semantic elements, audio and video support, local storage, canvas for
drawing graphics, and enhanced form controls.
a. <article> is used to define a self-contained piece of content, such as a news article, blog post,
or forum post.
a. The <time> tag is used to represent a specific time or date. It can be used for machine-
readable dates, event schedules, or time-related content.
a. The <pre> tag is used to display preformatted text, preserving both spaces and line breaks as
they appear in the HTML code.
54. What is the purpose of the download attribute in the <a> tag?
a. The download attribute is used to specify that a hyperlink should be downloaded instead of
navigated to when clicked. It specifies the filename of the downloaded file.
a. The <script> tag is used to embed or reference JavaScript code within an HTML document.
Inline JavaScript is directly embedded within the HTML document using the <script> tag, while
external JavaScript is saved in a separate .js file and linked to the HTML document using the src
attribute of the <script> tag.
a. The title attribute is used to provide additional information or a tooltip text for an element. It is
displayed when the user hovers over the element.
58.What is the purpose of the <fieldset> and < legend> tags in HTML?
a. The <fieldset> tag is used to group related form elements together, and the < legend> tag is
used to provide a caption or description for the <fieldset> .
a. The required attribute is used to specify that a form input field must be filled out before
submitting the form.
60. What is the purpose of the autocomplete attribute in form elements?
a. The autocomplete attribute is used to control whether a form input field should have
autocomplete suggestions or not.
a. The disabled attribute is used to make a form input field or button non-editable or non-
clickable. It prevents user interaction with the element.
a. The readonly attribute is used to make a form input field non-editable. It allows the user to
view the value but not modify it.
a. The <progress> tag is used to represent the progress of a task or the completion of a process,
such as a file upload or a download.
64. What is the purpose of the <details> and <summary> tags in HTML?
a. The <details> tag is used to create a collapsible section that can be toggled open or closed.
The <summary> tag is used to provide a summary or heading for the collapsible section.
a. The spellcheck attribute is used to enable or disable spell checking for a form input field.
a. The <meter> tag is used to represent a scalar measurement within a known range, such as a
progress bar, disk usage, or temperature.
67. how can you create an external link that opens in a new tab?
a. Absolute URLs specify the full web address of a resource, including the protocol (http/https).
Relative URLs specify the path to a resource relative to the current page.
69. How to include javascript code in HTML?
a. HTML provides a <script> tag using which we can run the javascript code and make our
HTML page more dynamic
70. When to use scripts in the head and when to use scripts in the body?
a. If the scripts contain some event-triggered functions or jquery library then we should use them
in the head section. If the script writes the content on the page or is not inside a function then it
should be placed inside the body section at the bottom. In short, follow below three points:
2. Place normal scripts that do not write anything on the page, in the head section until there is
any performance issue.
3. Place scripts that render something on the web page at the bottom of the body section.
a. Using the <table> tag with <tr> for rows, <td> for data cells and <th> for header cells.
a. ➢ <audio> - Used for sounds, audio streams, or music, embed audio content without any
additional plug-in.
➢<source> - Used for multiple media resources in media elements, such as audio, video, etc.
➢ <track> - Used for subtitles in the media elements such as video or audio.
73. What are the significant goals of the HTML5 specification?
a. These were the target area of the HTML5 specs: Introduction of new element tags to better
structure the web page such as tag. Forming a standard in cross-browser behavior and support
for different devices and platforms Backward compatible with the older version HTML web
pages Introduction of basic interactive elements without the dependency of plugins such as tag
instead of the flash plugin.
a. HTML allows event trigger actions in browsers using javascript or JQuery. There are a lot of
events like ‘ onclick ’ , ‘ ondrag ’ , ‘onchange’, etc.
75. What are void elements in HTML?
a. HTML elements which do not have closing tags or do not need to be closed are Void elements.
For Example: <br/> ,<hr/> and <img/> etc…,
76. What is the difference between “display: none” and “visibility: hidden”, when used as
attributes to the HTML element.
a. When we use the attribute “visibility: hidden” for an HTML element then that element will
be hidden from the webpage but still takes up space. Whereas, if we use the “display: none”
attribute for an HTML element then the element will be hidden, and also it won’t take up any
space on the webpage.
CSS
Interview Questions and Answers
1. What do you understand about the universal * selector ?
a. The universal * selector in CSS matches and applies styles to all elements on a webpage.
It's a way to target everything at once.
2. What is Cascading?
a. Cascading in CSS refers to how styles from various sources combine and interact to
determine the final appearance of elements. This process involves prioritizing styles based on
specificity, inheritance, and order of declaration
a. A ruleset in CSS consists of a selector and a set of declarations. The selector determines
which HTML elements the rule applies to, and the declarations specify the styling
properties and values for those elements. It defines how elements should be styled on a
webpage
a. The CSS Box Model is a concept that defines how elements on a webpage are structured
in terms of size and spacing.
It consists of four main elements:
Margin : Space outside the element, providing separation from other elements
a. CSS (Cascading Style Sheets) is a language used to style and format HTML documents,
controlling their appearance on the web. It separates the visual design from the
document's structure.
There are different versions:
CSS1 : Introduced basic styling properties.
CSS3 : Modular update with various modules for advanced features like transitions, flexbox,
grid and more
CSS4 : Not an official version but represents ongoing module-based updates for advanced
styling capabilities.
- transitions,
It offers improved typography, rounded corners, shadows, and better control over styling
effects. CSS3 allows for responsive design through media queries. Its modular approach and
expanded features make it more versatile and powerful compared to CSS2.
a. An "RGB stream" refers to a continuous flow of color data in the form of Red, Green,
and Blue components. Each parameter (red, green, and blue) defines the intensity of the
color with a value between 0 and 255. rgb(red, green, blue) | rgb(255, 255, 255) =
Generate white color rgba(red, green, blue, alpha) alpha for transparent
• Bootstrap
• Foundation
• Materialize
• Bulma
• Semantic UI
• Tailwind CSS
• UIKit
• Pure.css
• Material-UI
a. Class: Used to group multiple elements together for applying the same styling. Can be
applied to multiple elements, and you target it in CSS using a dot (.)
ID: Used to uniquely identify a single element. Each ID must be unique in the document.
You target it in CSS using a hash (#).
11. What are CSS Sprites ? What are the benefits
a. CSS sprites involve combining multiple images into one and using CSS background
positioning to display specific parts of the combined image.
Fewer Requests : Reduced HTTP requests.
a. Responsive web design (RWD) is an approach to web design & development that
aims to create websites that automatically adapt and provide an optimal viewing
experience on various devices & screen sizes, including desktops, laptops, tablets,
and smartphones.
○ Create Print Stylesheet: Make a separate CSS stylesheet for printing. @media print {
... }.
○ Remove Unnecessary Elements: Hide irrelevant items like menus.
○ Adjust Fonts and Colors: Opt for legible fonts and colors.
○ Remove Background Images: Avoid printing background images.
○ Control Page Breaks: Use CSS to prevent awkward content splits.
○ Increase Margins and Padding: Add white space for readability.
○ Test Printing: Print and adjust to ensure content fits well.
○ Offer Printer-Friendly Format: Provide simplified content version.
○ PDF Option: Offer downloadable PDFs for printing.
○ Headers and Footers: Use CSS for page info.
○ Check Images: Ensure graphics are print-friendly
a. CSS applies styles to HTML elements, controlling their appearance. Browsers load HTML
and CSS, create a render tree(DOM) of elements, compute styles, calculate layout, paint, and
render the page. This process ensures proper visual presentation of content.
a. Logical Tags:
● Semantic, structural.
● Examples: , , .
Physical Tags:
● Presentational.
a. CSS specificity is a rule used by web browsers to determine which style rules should be
applied to an element when multiple conflicting styles are present. It's a way of resolving
conflicts when multiple selectors target the same element with different styles.
CSS Specificity:
To calculate specificity:
a. In CSS, a gradient is a smooth transition between two or more colours, creating a gradual
blend from one color to another. Gradients can be applied as backgrounds, borders, or text
colours. They offer design flexibility and depth to elements on a webpage.
● Radial Gradient
a. CSS provides several position properties that allow you to control the placement and
positioning of elements on a webpage. Here are the different position properties and their
possible values:
Position:
static (default): Elements follow the normal document flow.
relative: Positioned relative to its normal position.
absolute: Positioned relative to its closest positioned ancestor or to the containing blocks. It's
removed from the normal document flow.
fixed: Positioned relative to the viewport. It remains fixed even when Scrolling.
sticky: It sticks an element to a specific position on the page based on the user's scroll, creating a
"sticky" effect
top, right, bottom, left:
Used with position: relative or position: absolute to adjust element's position from its normal or
initial position.
z-index:
Specifies the stacking order of positioned elements. Elements with higher values appear on top
of elements with lower values.
overflow:
Specifies what happens if content overflows an element's box. Values include visible, hidden,
scroll, and auto.
display:
Controls how an element is displayed. Values include block, inline, inline-block, none, and
more. Float & clear is not recommended
22. What are the advantages and disadvantages of using external style sheets?
● External Dependency: Requires an additional HTTP request, which can marginally impact
page load time.
● Rendering Delay: External styles must load before content is styled, possibly causing a brief
flash of unstyled content (FOUC).
● Multiple Files: More files to manage can complicate project structure.
● Less Suitable for Small Styles: For tiny projects, inline or internal styles might be more
efficient.
● Limited Offline Access: May lead to unstyled pages if the external stylesheet isn't cached]
24. What are the different ways to hide elements using CSS ?
a. "Cascading" in CSS refers to the process of combining and applying multiple styles to an
element, where the styles can come from different sources like the browser default styles, user-
defined styles, and external stylesheets.
● Create CSS File: Make a separate .css file for your styles.
● Write Styles: Define styles in the CSS file.
● Link CSS to HTML: In the HTML <head> add<link> to your CSS file:
<link rel="stylesheet"type="text/css"href="styles.css">
Separates your styles from your HTML for better organization and reusability.
a. "Float" is a CSS property that aligns elements horizontally. However, it can lead to layout
instability, clearing problems, collapsed parent containers, complexity, challenges in responsive
design, and compromised HTML structure. Modern layout techniques like Flexbox and Grid are
often preferred over "float" due to these disadvantages. 36. List out the media types in CSS
a. The z-index in CSS controls the layering of elements. A higher value places an element above
others. It's useful for managing overlapping content and creating complex layouts.
38. Which property is used to set the cursor pointer?
a. The cursor property in CSS is used to set the appearance of the mouse cursor when it's
hovering over an element. Different Values :
● display: none; :
○ Completely removes the element from the layout, including space it occupied.
● visibility: hidden; :
○ Hides the element but preserves its space in the layout.
a. In simpler terms, shadow DOM lets you create self-contained components with their own
private "sandboxed" DOM and styles, reducing conflicts and making it easier to create reusable,
customizable, and encapsulated elements on a web page. It's commonly used when building
custom elements or widgets that need to behave independently and avoid interfering with other
parts of the page Learn in depth…
a. Pseudo Element : Pseudo elements are virtual elements in CSS that allow you to style
specific parts of an element's content without adding extra HTML. They are indicated by double
colons (::). Here's a list of common pseudo elements:
Pseudo Classes : Pseudo classes are special keywords in CSS that target specific states or
behaviors of elements that can't be selected with regular selectors. They are indicated by a single
colon (:). Here's a list of common pseudo classes:
● :focus: Applies when an element gains focus (e.g., through tab navigation).
● :target: When an anchor link's target matches the current URL fragment.
a. Data attributes, in short, are custom attributes that can be added to HTML elements to store
additional information. They start with the prefix "data-" followed by a descriptive name,
allowing JavaScript and CSS to access and manipulate this information without affecting the
core functionality
In this case, the data-user-id attribute stores the value "123", which could be used by JavaScript
to perform actions related to that user.
● display: inline: Flows within content don't start a new line, no width/height control.
● Large Screens: Above 1440px width (e.g., 4K monitors). 46. Difference B/W “:last-child"
and ”list-of-type” Selector
● :last-child Selector: Targets the last child element within its parent.
● :nth-of-type Selector: Targets elements of a specific type based on their position within their
parent.
● em: Relative to the font size of the nearest parent element with a defined font size.
● rem: Relative to the root (html) element's font size, providing a consistent base value.
● Mobile First: Design approach starts with mobile screens and progressively enhances for
larger screens. Initially minimal design, then adds complexity.
● Desktop First: Design starts with desktop screens and adapts downward for smaller screens.
Initially complex, then simplifies for smaller screens.
a. Opacity makes elements transparent. It's used for fading effects, overlays, and blending with
backgrounds in CSS.
● Viewport Height (vh): Represents a percentage of the height of the device's viewport. 1vh is
1% of the viewport height. Useful for responsive vertical sizing.
● Viewport Width (vw): Represents a percentage of the width of the device's viewport. 1vw is
1% of the viewport width. Useful for responsive horizontal sizing.
53. Explain about General sibling selector & adjacent sibling selectors
a. General Sibling Selector (~): It selects all elements that are siblings of a specified element. It
targets elements that share the same parent and appear after the specified element, regardless of
their hierarchy level.
Adjacent Sibling Selector (+): It selects an element that is immediately preceded by a specified
element. It targets the first element that directly follows the specified element, sharing the same
parent.
The li ~ li selector targets all li elements that are siblings of another li (excluding the first one). It
turns their text color blue.
The li + li selector targets the second li element, which directly follows another li element. It
makes the second li element bold.
a. BEM (Block Element Modifier) is a method for organizing CSS code. It breaks down
components into three parts:
a. A CSS preprocessor is a tool that extends the capabilities of standard CSS by introducing
variables, functions, nesting, and more. It allows developers to write cleaner, more organized
stylesheets and then compiles them into standard CSS that browsers can understand.
Examples :
● Sass/Scss
● Less
● Stylus
● PostCSS
a. CSS Bootstrap is a front-end framework with ready-made CSS styles, components, and
layouts. It speeds up web development by offering a consistent, responsive design system for
creating modern websites and apps without starting from scratch.
a. A CSS reset is a set of CSS rules that aim to neutralize or reset default browser styles applied
to HTML elements. It's used to establish a consistent baseline for styling across different
browsers, ensuring that your styles start from a clean slate without any unexpected variations
caused by default browser styles.
● Margin is the space outside an element, influencing the spacing between elements in a layout.
a. The font-variant CSS property modifies how text looks by altering the font style. It's used to
make specific typographic adjustments within text elements.
For instance:
It's useful for highlighting text, like titles, using small caps. Keep in mind, not all fonts support
this style, and results vary based on the chosen font.
62. What are the common CSS properties related to styling tables
● border-collapse: Defines whether table borders should be collapsed into a single border or
separated.
● border-spacing: Specifies the space between adjacent cell borders when border-collapse is set
to separate.
● table-layout: Determines the algorithm used to layout table cells, affecting the distribution of
column widths. ○ table-layout: auto; (default) - Cells size based on content.
○ table-layout: fixed; - Column widths are set by the first row or CSS.
● caption-side: Specifies where the table caption (if present) should be positioned.
● empty-cells: Controls whether or not to display borders and background on empty table cells.
a. The :not selector in CSS selects elements that don't match a specific criterion. It's used to
exclude certain elements from a styling rule. For instance,
a. CSS combinators are symbols used to define relationships between HTML elements when
applying styles:
● General sibling (~): Selects elements after a specified element with the same parent.
● object-fit: Specifies how an image/video should fit within its container while preserving its
aspect ratio.
a. The calc() function in CSS allows you to perform mathematical calculations within property
values. It's particularly useful for dynamic sizing and positioning in responsive designs.
For example:
● font-size: calc(14px + 2vmin); calculates font size based on viewport size. calc() helps create
adaptable and precise styles without resorting to external calculations.
a. CSS counters enable automatic numbering or labeling of HTML elements without manual
numbering:
● Displaying: Use content with ::before or ::after to show the counter value
● Usage: Apply counters to various HTML elements (headings, lists) for automatic numbering
or labeling.
68. What is a CSS grid system?
a. A CSS grid system is a layout technique that uses a grid of rows and columns to arrange and
align elements on a web page. It simplifies design by providing a structured framework for
creating responsive layouts with consistent spacing and positioning.
69. Write down a selector that will match any links ending in .zip, .ZIP, .Zip etc..
a. To match links that end in .zip, .ZIP, .Zip, etc., you can use the following case-insensitive
attribute selector in CSS
The $= selector checks if the attribute value ends with a specific string. The i flag makes the
selector case-insensitive, so it will match .zip, .ZIP, .Zip, and other variations.
70. How select every element whose href attribute value begins with “https”, .pdf & CSS:
71. Is there any reason you'd want to use translate() instead of absolute positioning, or vice-
versa? And why?
● Z-Index: It's easier to control the stacking order of elements with absolute positioning and the
z-index property.
● Complex Layouts: For intricate layouts, absolute positioning provides better control over
element placement.
Example : Let's say you have a simple animation where you want a square element to smoothly
move from the left side of the screen to the right side.
In this example, the @keyframes rule defines the animation steps. The .square class is animated
using the slide animation, which moves the square horizontally from 0% (left) to 100% (right)
over 3 seconds. Tweening calculates the in-between positions, making the movement smooth and
continuous.
73. What are the differences between ‘reset’ and ‘normalize’ in CSS?
● Normalize CSS: Preserves useful browser defaults while ensuring consistent styling.
75. Explain the concept of CSS Flexbox & its main advantages in web layout design.
a. CSS Flexbox enables flexible and responsive layouts. It arranges elements in containers along
axes, offering:
76. How do you vertically center an element within a flex container using Flexbox?Provide
the necessary CSS properties and values.
a. To vertically center an element within a flex container using Flexbox, you can use the align-
items property with the value center. Here's the necessary CSS:
77. Describe the purpose of the flex-grow, flex-shrink, and flex-basis properties in the flex
shorthand property. Provide an example
a. The flex shorthand property in CSS Flexbox combines three properties: flex-grow, flex-shrink,
& flex-basis.
● flex-grow: It defines how much an item can grow compared to other flex items. It accepts a
unitless value representing a proportion. An item with a higher value grows more than others.
● flex-shrink: It controls the ability of an item to shrink if the container is too small. Similar to
flex-grow, it's unitless and indicates the ratio of shrinking for each item.
● flex-basis: This sets the initial size of an item before flex-grow and flex-shrink
● flex-shrink: 0: The item won't shrink to less than its initial size.
● flex-basis: 200px: The item starts with an initial size of 200 pixels.
This setup ensures that the item grows to fill available space but doesn't shrink, maintaining a
minimum width of 200 pixels. These properties are especially useful for creating flexible layouts
where items should distribute space differently while maintaining specific sizing behaviors.
78. In what situations would you use the align-items and align-content properties in a flex
container? Provide examples
a. Align-items:
● This property is used to align flex items individually along the cross-axis.
● It's suitable for scenarios where you want consistent alignment for each individual item.
● It's useful when you have multiple lines of items in a multi-line flex container.
● Example: Distributing space between lines of items with space between them.
79. Explain the difference between the flex-direction values row and column, and how they
influence the arrangement of flex items. Provide a use case for each value.
80. Explain the concept of CSS Grid layout and how it differs from other layout systems
like Flexbox.
a. CSS Grid layout is a powerful two-dimensional layout system in CSS that allows you to
create complex grid-based layouts with rows and columns. It offers precise control over both the
horizontal and vertical alignment of items.
● Layout Complexity: Flexbox suits simple layouts, Grid excels in complex structures with
rows and columns.
● Alignment: Grid provides advanced alignment control, allowing complex alignments and
content justification across the grid.
81. How do you define a grid container and grid items using CSS Grid? Provide an
example of a basic grid layout.
a. 1. Define the Grid Container: Apply display: grid; to the parent element to create a grid
container.
2. Define Grid Columns and Rows: Use properties like grid-template-columns and grid-
template-rows to set the size of columns and rows.
3. Place Grid Items: Use grid-column and grid-row to specify item positions in the grid.
Example of a basic grid layout
In this example, the .grid-container becomes a grid container with two columns and two rows.
.grid-item elements are placed in the grid using these columns and rows. The grid-gap adds
spacing between items, resulting in a basic grid layout.
82. What are the differences between implicit and explicit grids in CSS Grid? Give an
example of when each type might be used.
a. Implicit Grid:
● Implicit grid tracks are created automatically when you place grid items outside the explicitly
defined grid using properties like grid-row or grid-column.
● This occurs when items exceed the number of tracks defined in the explicit grid.
● Use Case: When items need to overflow and wrap in a grid without having to manually define
every track
Explicit Grid:
● Explicit grid tracks are defined using properties like grid-template-columns and grid-template-
rows.
● Use Case: When you want precise control over the number and size of tracks in your grid.
84. In what scenarios would you use the properties grid-gap, grid-row, and grid-column?
Provide examples
a. ● @keyframes Rule: Define animation steps using @keyframes, setting styles at specific
points.
Delay: Time before animation starts. Iteration Count: Number of animation cycles.
Example:
86. What is the difference between CSS transitions and CSS animations? Provide examples
a. CSS Transitions:
CSS Animations:
● Use keyframes for complex, automatic animations.
● Intermediate States:
○ Keyframes create intermediate states between start and end, adding fluidity.
● Multiple Keyframes:
a. The animation property in CSS is a shorthand property that combines several individual
animation-related properties to define the behavior of an animation applied to an Element.
89. How can you optimize CSS animations for performance? What techniques or best
practices would you consider to ensure smooth animations without causing performance
bottlenecks?
● Use Hardware Acceleration: Apply animations to properties like transform and opacity for
smoother rendering using the GPU.
● Use Debouncing and Throttling: Control animation triggers to prevent excessive updates.
● Optimize Images: Use appropriate image formats and sizes to reduce load times.
● Use CSS Transitions: Use transitions for simpler animations, as they often perform better.
90. What are CSS media queries, and how do they work? Provide an example
a. CSS media queries are a feature that allows you to apply styles based on the characteristics of
the user's device or screen. They enable you to create responsive designs that adapt to different
screen sizes, orientations, and other attributes.
Media queries work by evaluating the conditions you specify and applying the associated styles
if those conditions are met.
91. Explain the concept of breakpoints in the context of media queries. How do you decide
on appropriate breakpoints for different devices?
a. Breakpoints in the context of media queries refer to specific screen widths at which you
adjust your styles to create a responsive design. They are the points where your layout needs to
adapt to fit different devices or screen sizes.
Deciding on breakpoints:
● Device Research: Know common sizes and trends for devices.
92. What is the difference between min-width and max-width in media queries?
a. min-width:
● Styles will be applied when the viewport width is equal to or greater than the specified value.
max-width:
● Specifies the maximum width at which the styles should apply.
● Styles will be applied when the viewport width is equal to or smaller than the specified value.
In essence, min-width targets larger screens, while max-width targets smaller screens.
93. How can you use media queries to target different devices, such as smartphones, tablets,
and desktops?
94. What is the purpose of the meta viewport tag in responsive web design? How does it
relate to media queries, and why is it important for mobile devices?
a. The meta viewport tag in responsive web design is a crucial element that controls how a web
page is displayed on different devices, particularly mobile devices. It provides instructions to the
browser regarding the initial zoom level and how content should be scaled to fit the viewpo
● width=device-width ensures the website's width matches the device's width,
● initial-scale=1.0 prevents the page from being zoomed in initially. This helps ensure the
website is responsive and readable on mobile devices.
95. What are CSS transitions and how do they work? Provide an example
a. CSS transitions allow smooth property changes over time. They work by defining a property,
duration, timing, and event. When triggered (e.g., on hover), the property gradually changes to
the new value.
● The ease-in-out timing function ensures a smooth acceleration and deceleration effect during
the transition.
96. How can you transition multiple properties simultaneously using CSS? Provide an
example of transitioning both opacity and transform properties.
a. You can transition multiple properties simultaneously by listing them within the transition
property, separated by commas. Here's an example of transitioning both the opacity and
transform properties:
In this example:
● The opacity property changes smoothly from 0.5 to 1.
● The transform property transitions smoothly from its initial state to a scaled state (1 to 1.2) on
:hover.
● Both transitions have a duration of 0.3 seconds and use the ease-in-out timing function.
97. Explain the concept of event-triggered transitions. How do you use pseudo-classes like
:hover to create interactive transitions?
a. Event-triggered transitions are CSS transitions that are activated by specific events, such as
hovering over an element or clicking it. These transitions enable you to create interactive effects
that enhance user experience without the need for JavaScript.
● This creates a fade-in effect when the user interacts with the element. By combining event-
triggered pseudo-classes like :hover with transitions, you can add interactivity and engagement
to your designs.
98. What are CSS variables (custom properties)? How do they differ from traditional
variables in programming languages?
a. CSS variables, also known as custom properties, are a way to store and reuse values in CSS.
They allow you to define a value once and reuse it throughout your stylesheet
CSS variables are defined using the -- prefix followed by a name, like --main-color or --font-
size.
100. What is the @font-face rule in CSS? How do you use it to include custom fonts in your
web pages?
a. The @font-face rule in CSS is used to define custom fonts that can be used on a web page. It
allows you to include external font files and use them in your styles.
This is particularly useful when you want to use non-standard fonts that may not be available on
all users' devices.
● src: Defines the source of the font files. This includes URLs to font files like WOFF, WOFF2,
TTF, or EOT formats.
● font-display: Specifies how the font should be displayed while it's loading.
● unicode-range: Allows you to specify a range of characters that should be included in the
font.
Example usage of @font-face:
With @font-face, you can use web fonts that aren't installed on users' systems, ensuring
consistent typography across different devices and platforms.