HTML & CSS Interview Questions and Answers
Semantics, accessibility, layout systems, responsive design and modern CSS.
Whether you are preparing for entry-level HTML & CSS interview questions for freshers or senior software engineer interview questions addressing concurrency, scalability, and system architecture, this track provides peer-reviewed model answers with syntax walkthroughs, edge cases, and practical interview tips.
1 What is the CSS box model? Easy
Every element is a box made of four layers: content, padding, border and margin. By default width applies to the content box, so padding and border are added on top (content-box). box-sizing: border-box makes width include padding and border, which is why most codebases set it globally.
*, *::before, *::after { box-sizing: border-box; }
Margin collapsing, percentage widths relative to the containing block, and negative margins are common follow-up questions.
2 What are semantic HTML elements and why do they matter? Easy
Semantic elements describe their meaning rather than only their appearance: header, nav, main, article, section, aside, footer, figure, time, button.
Benefits:
- Accessibility: screen readers announce landmarks and roles, letting users navigate by region.
- SEO: crawlers understand document structure and importance.
- Maintainability: code is self-documenting.
- Free behaviour: button, a, input and form come with keyboard handling and built-in semantics, whereas clickable divs require manual ARIA and key handlers.
Rule: use the native element that matches the meaning; only add ARIA when no native element exists, and never override correct native semantics.
3 What is HTML and what are it's basic components? Easy
HTML (Hyper Text Markup Language) is the standard markup language for creating web pages. It's basics components includes element, tags and attribute.
4 What is the purpose of Doctype in HTML? Easy
The Doctype declaration specifies the type of document being used and tell the web browser how to interpret the pages content. It is located at the top of the HTML document.
5 What is semantic HTML? Easy
Semantic HTML uses specific HTML elements to provide additional information about the structure and content of the page, making it more accessible and easy to read.
6 What is the difference between div element and span element? Easy
The div element is a block-level element that is used to group and organize other HTML elements while span element is an inline-element that is used to apply style or attribute to a specific part of a block-level element.
7 What is the difference between <b> and <strong> tags in HTML? Easy
The <B> tag is used to apply bold formatting to text, while the <strong> tag is used to indicate that the text is important and carries stronger semantic meaning than <b>.
8 What is the difference between a GET request and POST request? Easy
The GET request is used to retrieve data from a web server, while a POST request is used to submit data to a web server. GET requests are less secure and have limit on the amount of data that can be sent while POST request have no limit and are more secure.
9 How do you create a hyperlink in HTML? Easy
Hyperlinks are created using the anchor element (<a>) paired with the essential href (Hypertext Reference) attribute:
<!-- External Link with Security Hardening -->
<a href="https://hirextech.com/categories" target="_blank" rel="noopener noreferrer">
Explore Technical Interview Categories
</a>
<!-- Internal Anchor Navigation -->
<a href="#salary-insights">Jump to Salary Section</a>
<!-- Email and Telephone Triggers -->
<a href="mailto:support@hirextech.com">Email Support</a>
<a href="tel:+18005550199">Call Support</a>
### Critical Security Best Practice:
Whenever using target="_blank" to open a new browser tab, you must include rel="noopener noreferrer". Without this, the newly opened tab can access the original window's window.opener object, introducing vulnerability to reverse tabnabbing phishing attacks.
10 What is the purpose of the alt attribute in HTML? Easy
The alt attribute is used to provide a text description of an image for users who are unable in to see the image, such as those who use screen readers.
11 What is the difference between <link> tag and <a> tag? Easy
The anchor tag <a> is used to create a hyperlink to another web page or to a certain part of a web page and these links are clickable, whereas, link tag <link> defines a link between a document and external resource and these are not clickable.
12 What is the canvas element in HTML5? Easy
The <canvas> element provides a scriptable bitmap drawing surface in HTML. It acts as an empty resolution-dependent drawing container that JavaScript manipulates via procedural drawing APIs:
### Rendering Contexts:
- 2D Context (
getContext('2d')): Used for drawing paths, boxes, text, gradients, and 2D games. - WebGL / WebGL2 (
getContext('webgl')): Hardware-accelerated 3D graphics rendering powered by the client GPU (used by Three.js and Babylon.js).
### Code Example:
<canvas id="myCanvas" width="400" height="200"></canvas>
<script>
const canvas = document.getElementById('myCanvas');
const ctx = canvas.getContext('2d');
// Draw rectangle
ctx.fillStyle = '#2563eb';
ctx.fillRect(20, 20, 150, 100);
</script>
*Difference from SVG:* Canvas renders pixels onto a raster bitmap (faster for thousands of moving particles or video frame manipulation), whereas SVG is an XML DOM tree of vector shapes (infinitely scalable and individually inspectable in the DOM).
13 What is an HTML form? Easy
An HTML form (<form>) is a document container designed to collect user input and transmit it securely to a web server or client-side JavaScript handler.
### Core Form Anatomy:
<form action="/api/feedback" method="POST" enctype="application/x-www-form-urlencoded">
<label for="username">Full Name:</label>
<input type="text" id="username" name="username" required>
<button type="submit">Submit Feedback</button>
</form>
### Essential Form Attributes:
action: Target URL endpoint where data is sent upon submission.method: HTTP verb used for transmission:GET: Appends form data as URL query parameters (?name=John), suitable for search queries.POST: Packages data in the HTTP request body, required for sensitive data or database mutations.enctype: Encoding format (multipart/form-datais mandatory when uploading files).
14 What is the difference between HTML form's "action" and "method" attributes? Easy
The "action" attribute specifies the URL to which the form data is submitted, while the "method" attribute specifies the HTTP method when submitting the form data(either "GET" or "POST").
15 What is the purpose of <head> tag? Easy
The <head> tag in HTML is used to provide metadata about document, such as title of page, links and other information that is not directly displayed on the web page. This information is used by browser and search engine to understand the content and structure of the web page.
16 What is the purpose of the <meta> tag in HTML? Easy
The <meta> tag is used to provide additional information about the webpage, such as author, keywords, description which is used by search engines to understand the content of the page.
17 What is the purpose of the <script> tag in HTML? Easy
The <script> tag is either used to embed client-side script(Javascript), or it points to an external script file through the src attribute.
18 What is the purpose of the viewport meta tag? Easy
The viewport meta tag informs mobile browsers how to control the page's dimensions and scaling relative to the physical device screen:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
### Why It Is Mandatory for Responsive Web Design:
- Disables Desktop Zoom Emulation:
Without this tag, mobile browsers assume the website is built for a 980px desktop monitor and scale the page down, resulting in microscopic, unreadable text.
width=device-width: Sets the width of the virtual viewport to match the physical screen width of the device in CSS pixels.initial-scale=1.0: Establishes a 1:1 ratio between CSS pixels and device-independent pixels upon initial page load.
*Accessibility note:* Avoid setting user-scalable=no or maximum-scale=1.0 as doing so prevents visually impaired users from zooming in, violating WCAG accessibility guidelines.
19 What is the purpose of the <noscript> tag in HTML? Easy
The <noscript> tag in used to display text for those browsers which does not support script tag or the browser disabled the script by user.
20 What is the purpose of the <fieldset> tag in HTML? Easy
The <fieldset> tag is used in HTML forms to logically group related form controls and labels together, both visually and semantically:
<fieldset>
<legend>Billing Address Information</legend>
<label for="street">Street Address:</label>
<input type="text" id="street" name="street">
<label for="zip">Postal Code:</label>
<input type="text" id="zip" name="zip">
</fieldset>
### Key Advantages:
- Accessibility (Screen Readers):
The child <legend> provides context. Screen readers announce the legend before each input within the fieldset, which is crucial for grouped radio buttons or complex shipping forms.
- Mass Disabling:
Setting <fieldset disabled> automatically disables all form controls nested inside it simultaneously, eliminating the need to set disabled on every input individually.
21 What is the difference between HTML tag and HTML element? Easy
HTML tag is just opening or closing entity. For example <p> and </p> are called HTML tags. <br />
HTML element consists of opening tag, closing tag and content(optional for content-less tags). For example: <p> This is the content </p>, this complete thing is called HTML element.
22 What is HTML5 web storage? Easy
HTML5 Web Storage is a mechanism in modern web browsers that allows web applications to store data locally within the user's browser. It provides two storage options: Local Storage and Session Storage.
23 What is the use of "target" attribute in HTML? Easy
The target attribute on <a>, <form>, or <area> tags specifies where to display the linked document or form submission response:
### Permitted Keywords:
_self(Default): Opens the document in the current browsing context (same tab/window)._blank: Opens the document in a new browser tab or secondary window._parent: Opens the linked document in the parent browsing context (useful when breaking out of an<iframe>)._top: Opens the linked document in the topmost browsing context, dismissing all nested frames.frameName: Opens the document inside a specifically named iframe:<iframe name="preview">.
*Security Best Practice:* Always combine target="_blank" with rel="noopener noreferrer" to protect against window.opener exploits.
24 What is the use of "em" tag? Easy
The "em" tag is a semantic tag which is used to apply emphasis to a word or phrase within a paragraph. <br />
Example: The sentence "I really enjoyed cycling" could be written using the "em" tag to emphasize the word "really": "I <em>really </em> enjoyed the concert last night."
25 What is the purpose of <header> tag? Easy
The <header> tag is used to defined the header section of a webpage which includes site logo, navigation menu, and other introductory content.
26 What is the purpose of <nav> tag? Easy
The <nav> element represents a section of a page whose purpose is to provide navigation links, either within the current document or to external pages:
<nav aria-label="Main Navigation">
<ul>
<li><a href="/categories">All Categories</a></li>
<li><a href="/mock-interview">Mock Practice</a></li>
<li><a href="/pricing">Pro Access</a></li>
</ul>
</nav>
### Semantic Importance:
- Screen Readers & Assistive Tech: Screen readers identify
<nav>as a landmark region, enabling users with visual impairments to bypass header banners and jump directly to site navigation using landmark shortcut keys. - SEO: Search engine crawlers (like Googlebot) prioritize
<nav>links to map site hierarchy and identify primary internal link graphs. - *Usage note:* Not all links belong in
<nav>. It should be reserved for major navigational blocks, not footer legal disclaimers.
27 What is the purpose of <main> tag? Easy
The <main> element represents the dominant, central content unique to the document.
### Rules of Usage:
- Content inside
<main>should be unique to that specific page and exclude content repeated across multiple pages (such as global navigation links, copyright footers, sidebars, and logo banners). - A document must not have more than one non-hidden
<main>element. - It must not be nested inside
<header>,<footer>,<nav>, or<article>.
### Accessibility Role:
Exposes an explicit ARIA landmark (role="main"), enabling keyboard and screen reader users to skip repeated navigation bars and jump straight to the primary topic.
28 What is the purpose of <article> tag? Easy
The <article> element represents a complete, self-contained composition in a document that is independently distributable or reusable (e.g. in syndication, RSS feeds, or news aggregators):
### Typical Use Cases:
- A technical interview question and solution entry
- A blog post or news article
- A forum post or user comment
- An interactive product card
### Structure Example:
<article class="interview-question">
<header>
<h2>What is the event loop in JavaScript?</h2>
<span class="difficulty-badge">Hard</span>
</header>
<div class="solution-body">
<p>Detailed architectural explanation...</p>
</div>
<footer>
<time datetime="2026-09-20">Updated Sept 2026</time>
</footer>
</article>
29 What is the purpose of <section> tag? Easy
The <section> element represents a standalone thematic grouping of content, typically with a heading (<h2>-<h6>):
### How <section> Differs from <div> and <article>:
<div>: Has no semantic meaning; purely used as a styling wrapper or flex/grid layout container.<section>: Represents a logical chapter or thematic block (e.g. "Introduction", "Code Example", "Common Pitfalls", "Interviewer Evaluation Rubric").<article>: Represents an independently distributable piece of content that could stand completely alone outside the page context.
### Semantic Rule of Thumb:
If the content represents a logical outline heading in the document's table of contents, wrap it in a <section>.
30 What is the purpose of <aside> tag? Easy
The <aside> tag is used to define content that is related to the main content of a webpage, but is not directly part of it. It is often used to provide additional information to the main content.
31 What is the purpose of <footer> tag? Easy
The <footer> tag is used to define the footer section of a webpage which contains copyright information, contact details, and other legal content.
32 What is the purpose of <figure> tag? Easy
The <figure> element represents self-contained content, optionally accompanied by a caption (<figcaption>), that is referenced as a single unit from the main text flow:
<figure>
<img src="/diagrams/event-loop.webp" alt="JavaScript Call Stack and Event Queue Diagram">
<figcaption>Figure 1: Visual representation of the Microtask vs Macrotask Queue.</figcaption>
</figure>
### Advantages:
- The content can be moved away from the primary text flow (e.g. into an appendix or sidebar) without affecting the document's flow.
- Accommodates not only images, but also code blocks, diagrams, data tables, audio clips, or quotes.
33 What is the purpose of <figcaption> tag? Easy
The <figcaption> element provides a semantic caption or legend for its parent <figure> element:
### Usage Rules:
- Must be nested as either the first child or the last child of a
<figure>element. - Automatically associates the caption text with the media element for assistive technologies, allowing screen readers to announce the caption as the official description of the figure.
34 What is the purpose of <blockquote> tag? Easy
The <blockquote> tag is used to indicate that a section of text is being quoted from another source. It is used to highlight a particularly important quote.
35 What is <datalist> tag? Easy
The <datalist> tag is new addition to HTML5, and it is used to provide a list of pre-defined options for an input field. It allows us to create dropdown list of options.
36 What is the use of <option> tag? Easy
The <option> tag is used to define an option in a dropdown list. The 'value' attribute in <option> tag is specifies the value of the option that will be submitted when the form is submitted.
37 What is the purpose of the "data-\*" attribute in HTML? Easy
The data=\* attribute allows us to store additional information about an HTML element that is not otherwise displayed on the page, but may be useful to scripts that interact with the page.
38 What is the purpose of <legend> tag? Easy
The <legend> tag provides semantic caption or title for a <fieldset> element. It is optional but better for better to have for accessibility.
39 What is the purpose of the <picture> element in HTML5, and how is it used to optimize images? Easy
The <picture> element in HTML5 is used to provide multiple versions of an image at different resolutions or sizes, and allows the browser to choose the best version to display based on the user's device and viewport size.
40 What is CSS? Easy
CSS stands for Cascading Style Sheets. CSS is used to define styles for web pages, including the design, layout and variations in display for different devices and screen sizes.
41 What is universal selector in CSS? Easy
The universal selector is a css selector that can be used to apply styles to all elements on a page or to reset styles for all elements to their default values
42 What is the difference between margin and padding in CSS? Easy
Margin is the space between the border of an element and the surrounding elements, while padding is the space between the content of an element and its border.
43 What is the CSS position property and its values? Easy
The CSS position property controls how an element is positioned on a page. The possible values are static, relative, absolute, fixed, and sticky
44 What is the difference between absolute and relative positioning in CSS? Easy
Relative positioning moves an element relative to its current position without affecting the position of other elements, while absolute positioning positions an element relative to its closest parent element, potentially affecting the position of other elements.
45 What is the CSS clear property? Easy
The CSS clear property controls whether an element is allowed to float next to another element or not. The possible values include left, right, both, and none. When an element is cleared, it will be moved below any floated elements.
46 What is the CSS z-index property? Easy
The CSS z-index property controls the stacking order of elements on a page. Elements with a higher z-index value are displayed on top of elements with a lower z-index value. The default value of z-index is auto.
47 What is CSS animation? Easy
A CSS animation allows elements to transition smoothly between different style configurations over time using keyframes, without writing custom JavaScript animation loops:
@keyframes pulse {
0% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.05); opacity: 0.8; }
100% { transform: scale(1); opacity: 1; }
}
.badge-live {
animation: pulse 2s infinite ease-in-out;
}
### Core Animation Properties:
animation-name: The@keyframesidentifier.animation-duration: Total time for one complete cycle (e.g.300ms,2s).animation-timing-function: Acceleration curve (ease,linear,cubic-bezier()).animation-iteration-count:1,3, orinfinite.animation-fill-mode:forwardsretains the styles of the final keyframe after completion.
48 What is transition in CSS? Easy
A transition in CSS is a way to create animation effects when a property of an HTML element changes, allowing developers to smoothly animate changes to an element's style over a specified duration.
49 What is the difference between linear and radial gradient in CSS? Easy
A linear gradient creates a smooth transition between two or more colors in a straight line while the radial gradient creates a smooth transition between two or more colors in a circular shape.
50 What is flexbox? Easy
Flexbox is a CSS3 layout module which provides more flexible and efficient way to align arrange and align the elements within the container. It is widely supported by the modern web browser.
51 What is the difference between flex-grow and flex-shrink properties in Flexbox? Easy
flex-grow is a property in Flexbox that specifies how much a flex item should grow relative to the other items in the container, while flex-shrink specifies how much a flex item should shrink relative to the other items when there is not enough space available in the container.
52 What is the difference between flex-wrap: nowrap and overflow: hidden in CSS? Easy
flex-wrap: nowrap prevents flex items from wrapping to the next line when they overflow the container, while overflow: hidden hides any content that overflows the container's boundaries.
53 What is the `gap` property in Flexbox, and how is it used to add spacing between flex items? Easy
The gap property in Flexbox sets the spacing between flex items, both horizontally and vertically. It is a shorthand for row-gap and column-gap.
54 What is CSS grid? Easy
CSS Grid Layout is a powerful two-dimensional layout system designed for simultaneously controlling both rows and columns:
.dashboard-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1.5rem;
}
### Grid vs Flexbox:
- Flexbox: One-dimensional (handles items along either a row OR a column).
- CSS Grid: Two-dimensional (positions items across intersecting horizontal and vertical tracks).
### Key Terminology:
- Grid Container: Element with
display: grid. - Grid Tracks: Columns and rows defined via
grid-template-columnsandgrid-template-rows. - Fractional Unit (
fr): Represents a fraction of the available free space in the grid container. - Grid Template Areas: Named layout regions (
"header header" "sidebar main" "footer footer").
55 What is the difference between grid-row and grid-column in CSS Grid? Easy
grid-row is used to position an item within a row, while grid-column is used to position an item within a column. Both properties can take a value of either a number or a named grid line.
56 What is a CSS transition? Easy
A CSS transition enables you to create gradual, interpolated animations between two visual states of an element when a CSS property value changes (such as on :hover, :focus, or dynamic class toggling):
.cta-button {
background-color: #2563eb;
color: #ffffff;
transition: background-color 0.25s ease-in-out;
}
.cta-button:hover {
background-color: #1d4ed8;
}
### The 4 Transition Sub-Properties:
transition-property: Names which properties to animate (background-color,transform,opacity).transition-duration: Duration of animation (200ms,0.5s).transition-timing-function: Mathematical easing curve (ease,linear,cubic-bezier).transition-delay: Delay before animation starts.
57 What is the purpose of the `transition-property` property in CSS transitions? Easy
The transition-property CSS property specifies the exact names of the CSS properties that should animate when their values change:
/* Recommended: Explicitly named properties */
.box {
transition-property: transform, opacity;
transition-duration: 300ms;
}
### Why You Should Avoid transition-property: all:
- Performance Overhead: Specifying
allforces the browser to monitor and interpolate every single animatable property on every DOM reflow, degrading rendering performance. - Unintended Side Effects: Accompanying properties (such as width or margins) might animate unexpectedly during screen resizing, resulting in jittery UI layouts.
58 What is the function of the `transition-timing-function` property in CSS transitions? Easy
The transition-timing-function property specifies the rate of change of the transition over time. This can be used to control the speed of the transition and how it accelerates and decelerates. Example: ease-in, ease, ease-out.
59 What is the difference between the `translate()` and `rotate()` functions? Easy
The translate() function is used to move an element along the x-axis and/or y-axis, while the rotate() function is used to rotate an element clockwise or counterclockwise around a given point.
60 What is the difference between RGB and RGBA colors? Easy
RGBA is similar to RGB, but it includes an additional alpha value that represents the opacity of the color. The alpha value is a number between 0 and 1, with 0 being completely transparent and 1 being completely opaque.
61 What is CSS filter? Easy
CSS filters are a set of visual effects that can be applied to HTML elements using CSS. Filters can be used to adjust the appearance of an element in various ways, such as changing its color, blurring or sharpening it, adjusting its brightness or contrast, and more.
62 What is a CSS sprite? Easy
A CSS sprite is a technique used to combine multiple images into a single image file, reducing the number of HTTP requests required to load the page and improving loading times.
63 What is the :not() pseudo-class used for in CSS? Easy
The :not() functional pseudo-class (known as the negation pseudo-class) matches elements that do not match the selector argument provided inside its parentheses:
/* Style all buttons except disabled ones */
button:not(:disabled) {
cursor: pointer;
background-color: #2563eb;
}
/* Style list items except the last one with a divider */
li:not(:last-child) {
border-bottom: 1px solid #e2e8f0;
}
/* CSS Selectors Level 4: Supports comma-separated selector lists */
p:not(.lead, .disclaimer) {
font-size: 1rem;
}
*Note:* The specificity of :not() is determined by the highest specificity selector inside its argument list.
64 What is the :visited pseudo-class used for in CSS? Easy
The :visited pseudo-class styles anchor links (<a>) that the user has already navigated to in their browser history:
a:visited {
color: #7c3aed; /* Purple indicator for visited links */
}
### Strict Browser Privacy Restrictions:
To prevent malicious websites from sniffing a user's browsing history by styling links and reading back computed styles with JavaScript, modern browsers enforce strict security restrictions on :visited:
- Only color-related properties are permitted:
color,background-color,border-color,outline-color, and SVGfill/stroke. - Alpha transparency components are ignored.
- JavaScript methods like
getComputedStyle()will always lie and report the unvisited color.
65 What is the :active pseudo-class used for in CSS? Easy
The :active pseudo-class represents an element in the process of being activated by the user.
### When Is It Triggered?
- The moment a user presses and holds the primary mouse button down on an element, lasting until the mouse button is released.
- During physical touch tap on mobile touchscreen displays.
### Classic Button Press Animation:
.btn {
transform: scale(1);
transition: transform 0.1s ease;
}
.btn:active {
transform: scale(0.96); /* Provides physical tactile click sensation */
}
### The LVHA Ordering Rule:
When styling links, define pseudo-classes in this exact order to prevent cascade overriding:
:link:visited:hover:active(LoVe HAte mnemonic)
66 What is the :lang() pseudo-class used for in CSS? Easy
The lang() pseudo-class is used to target elements based on the language attribute of the HTML document. For example, you can use :lang(en) to target all elements in English, or :lang(fr) to target all elements in French.
67 What is the :checked pseudo-class used for in CSS? Easy
The :checked pseudo-class is used to target form elements that have been selected by the user, such as checkboxes or radio buttons. This can be used to change the appearance or behavior of the selected element.
68 What is the @media rule in CSS? Easy
The @media rule in CSS allows developers to apply styles to a web page based on the size of the device or screen being used to view it, making it more responsive.
69 What is the difference between fluid and fixed layouts in CSS? Easy
A fluid layout in CSS adjusts its width and height based on the size of the screen, while a fixed layout has a set width and height. Fluid layouts use percentages to set their dimensions, while fixed layouts use pixels.
70 What is the difference between min-width and max-width in CSS media queries? Easy
In CSS media queries, min-width sets the minimum screen width at which a set of styles will be applied, while max-width sets the maximum screen width at which a set of styles will be applied. For example, if you use min-width: 768px, the styles will only be applied to screens that are 768 pixels wide or larger, while if you use max-width: 768px, the styles will only be applied to screens that are 768 pixels wide or smaller.
71 What is the difference between responsive and adaptive design in CSS? Easy
Responsive design in CSS adapts to different screen sizes and devices by using flexible grids, fluid images, and media queries to adjust the layout and content of the website. Adaptive design in CSS, on the other hand, uses predefined layout sizes and breakpoints to adjust the layout and content based on the screen size and device being used.
72 What is the overflow property in CSS used for? Easy
The overflow property specifies what should happen if content overflows an element’s box. It's possible values are: auto, none, scroll, visible.
73 What is the difference between `visibility:hidden` and `display:none`? Easy
visibility:hidden means the tag is not visible, but the space is allocated for it on the page. display:none means the tag will not appear at all and there will be no space allocated for it between the other tags.
74 What is the purpose of CSS content property? Easy
The content property is used exclusively in conjunction with the ::before and ::after pseudo-elements to generate decorative or supplementary visual content without adding extra HTML DOM elements:
/* Generating an icon or badge indicator */
.required-field::after {
content: " *";
color: #ef4444;
font-weight: bold;
}
/* Clearing floats (Micro clearfix) */
.clearfix::after {
content: "";
display: block;
clear: both;
}
*Accessibility Note:* Content generated via CSS content was historically invisible to screen readers; today, screen readers may read it. Never insert critical textual information solely via content.
75 What is the "line-height" property in CSS? Easy
The line-height property defines the height of an inline line box, determining the vertical distance between baselines of consecutive lines of text:
### Value Formats:
- Unitless Number (Best Practice):
body { line-height: 1.5; }
A unitless number acts as a proportional multiplier of the element's current font-size. Child elements inherit the multiplier rather than a fixed computed pixel size, preventing text overlapping if children declare larger font sizes.
- Lengths (
px,rem):line-height: 24px;(Rigid, breaks on dynamic font scaling). - Percentages (
150%): Can cause inheritance calculation issues in nested headers.
76 What is specificity in CSS? Easy
Specificity in CSS is a way of determining which CSS rule applies to an element. It is based on the number of selectors and their types in a CSS rule. Specificity is calculated using a formula: inline styles have the highest specificity, followed by IDs, classes, and then elements.
77 What is the word-wrap property in CSS3? Easy
The word-wrap property (renamed in modern CSS specifications to overflow-wrap) specifies whether the browser may break long unbreakable character sequences (such as lengthy URLs, hash strings, or file paths) onto a new line to prevent horizontal layout overflow:
.card-content {
/* overflow-wrap is the standard; word-wrap is legacy alias */
overflow-wrap: break-word;
word-wrap: break-word;
}
### Difference from word-break: break-all:
overflow-wrap: break-wordonly breaks a word if the entire word cannot fit onto a line by itself.word-break: break-allaggressively breaks words at the exact right margin boundary regardless of whether the word could fit unbroken on the next line.
78 What is Tailwind CSS? Easy
TailwindCSS is a utility-first CSS framework that provides pre-defined CSS classes that can be used to rapidly build custom user interfaces.
79 What is CSS preprocessor? Easy
A CSS preprocessor is a tooling program that extends standard CSS syntax with programmatic capabilities (such as variables, functions, mixins, and nested rules), compiling the code into standard, browser-compatible CSS before runtime:
### Popular Preprocessors:
- Sass / SCSS: The industry standard preprocessor.
- Less: JavaScript-based preprocessor.
- Stylus: Expressive, Python-inspired syntax.
### Key Preprocessor Features:
- Nesting: Structuring selectors to mirror HTML hierarchy.
- Mixins: Reusable blocks of styles passed with arguments.
- Partials & Modules: Splitting styles into files (
_variables.scss,_buttons.scss) and importing via@use. - *Modern Context:* Many native CSS features (CSS variables, native CSS nesting
@scope, color functions) have adopted ideas originally introduced by preprocessors.
80 What is the difference between a CSS preprocessor and a post-processor? Easy
A CSS preprocessor generates CSS code from source code written in a higher-level scripting language, whereas a post-processor takes existing CSS code and applies transformations or optimizations to it. In other words, a preprocessor is used during development, while a post-processor is used after development to optimize performance.
81 What is SASS? Easy
Sass is a CSS preprocessor that adds functionality to CSS, such as variables, nesting, and more. It allows us to write more efficient code and simplifies task like browser compatibility.
82 What is the difference between SASS and SCSS? Easy
Sass and SCSS are both CSS pre-processors and are very similar, but they have different syntax. Sass has a more concise and less verbose syntax, with no curly braces and no semicolon whereas SCSS has a syntax that is almost identical to standard CSS, with curly braces and semicolons
83 What is SASS nesting? Easy
Sass nesting is a feature that allows us to write CSS selectors that are nested within one another which makes our code easier to read and understand.
All 83 questions loaded
Frequently Asked Questions About HTML & CSS Interviews
What do hiring managers evaluate in HTML & CSS technical rounds?
Technical interviewers look for foundational fluency, idiomatic syntax, clarity when communicating complex logic, and awareness of performance trade-offs (e.g. memory footprint, render performance, and network latency) in production environments.
What are the best interview tips for practicing HTML & CSS questions?
Use active recall: summarize each answer in your own words before revealing the model solution. Focus on explaining why a certain approach is chosen rather than just memorizing code syntax.