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 Explain Flexbox vs Grid and when to use each. Medium
- Flexbox is one-dimensional: it distributes space along a single main axis (row or column). Best for toolbars, navigation, card content, alignment, and components whose size depends on their content.
- Grid is two-dimensional: it controls both rows and columns simultaneously. Best for page layouts, dashboards, galleries and any design with a defined track structure.
They compose: use Grid for the macro layout and Flexbox inside individual components.
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.flex { display: flex; align-items: center; justify-content: space-between; }
2 How does CSS specificity work and how do you resolve conflicts? Medium
Specificity ranks selectors as (inline, IDs, classes/attributes/pseudo-classes, elements/pseudo-elements). Higher wins; equal specificity falls back to source order (later wins). !important overrides normal declarations regardless of specificity and should be reserved for utilities or third-party overrides.
#nav .item a:hover -> (0, 1, 2, 2)
.item.active -> (0, 0, 2, 0)
Strategies to avoid wars: keep specificity low and flat, use single-class selectors, adopt a naming convention (BEM), or use cascade layers (@layer) and :where() (zero specificity) to control the cascade deliberately.
3 What is the difference between relative, absolute, fixed and sticky positioning? Medium
- static: default, follows normal flow.
- relative: stays in flow but offsets from its normal position; also establishes a containing block for absolutely positioned descendants.
- absolute: removed from flow, positioned relative to the nearest positioned ancestor (or the initial containing block).
- fixed: removed from flow, positioned relative to the viewport and unaffected by scrolling.
- sticky: behaves as relative until a threshold is crossed, then sticks within its scrolling ancestor; it needs a top/right/bottom/left value.
Common bug: an absolute child escapes to the viewport because no ancestor has position set. Add position: relative to the intended parent.
4 How do you make a site accessible and responsive? Medium
Accessibility essentials:
- Use semantic elements and a logical heading order.
- Provide alt text for meaningful images and empty alt for decorative ones.
- Ensure colour contrast of at least 4.5:1 for body text.
- Support full keyboard navigation with visible focus styles.
- Associate labels with inputs and announce errors with aria-live.
- Respect prefers-reduced-motion and prefers-color-scheme.
Responsive essentials:
- Set the viewport meta tag.
- Use fluid layouts (flex/grid), relative units (rem, %, clamp) and max-width.
- Mobile-first media queries plus container queries for component-level responsiveness.
- Serve responsive images with srcset/sizes and loading="lazy".
5 What are different types of list in HTML? Medium
HTML provides three primary elements for structuring lists of items, each serving a distinct semantic role:
### 1. Unordered Lists (<ul>)
Used for collections of items where the sequence does not convey procedural priority or hierarchy. Browsers render these with bullet points by default:
<ul>
<li>Cascading Style Sheets (CSS)</li>
<li>HyperText Markup Language (HTML)</li>
<li>JavaScript (JS)</li>
</ul>
### 2. Ordered Lists (<ol>)
Used for step-by-step instructions, ranked leaderboards, or sequential procedures where order is essential:
<ol type="1" start="1">
<li>Initialize Git repository</li>
<li>Configure remote origin</li>
<li>Commit and push changes</li>
</ol>
*Attributes:* type ("1", "a", "A", "i", "I"), start, and reversed.
### 3. Description / Definition Lists (<dl>)
Used to group pairs of terms (<dt>) and descriptions/values (<dd>), ideal for glossaries, metadata displays, or key-value pairings:
<dl>
<dt>DOM</dt>
<dd>Document Object Model — a tree representation of HTML nodes.</dd>
<dt>API</dt>
<dd>Application Programming Interface.</dd>
</dl>
6 What are the different types of input field in HTML? Medium
The HTML <input> element is one of the most versatile form controls, determined by its type attribute:
### Common Input Types and Behaviors:
text: Standard single-line plain text entry.password: Obscures characters with dots/asterisks for credential security.email: Validates email format and displays@symbol on mobile soft keyboards.number: Restricts entry to digits with optionalmin,max, andstepattributes.tel: Mobile phone number entry triggering numeric telephone keypad.url: Enforces valid URL protocol prefixes (http://orhttps://).checkbox: Toggle option for multiple selectable choices.radio: Mutually exclusive selection within a sharednamegroup.file: File upload picker withacceptandmultipleattribute support.date,time,datetime-local: Native calendar and clock pickers.range: Visual slider control between numeric bounds.color: Native hex color picker dialog.hidden: Stores invisible state transmitted upon form submission.submit,reset,button: Action buttons trigger submission or reset events.
7 What are void elements in HTML? Medium
Void elements (historically called self-closing or empty elements) are HTML elements that cannot have any child nodes (neither text nor nested elements) and must never have a closing tag (</...>).
### Complete List of HTML5 Void Elements:
<area>: Image map active region<base>: Base URL for relative paths<br>: Line break<col>: Column properties in a table<embed>: External application or plugin container<hr>: Thematic break (horizontal line)<img>: Image element<input>: Form control<link>: Document relationship metadata (e.g. stylesheets)<meta>: Document metadata<param>: Plugin parameter<source>: Media resource for<audio>and<video><track>: Text track for subtitles<wbr>: Word break opportunity
### HTML5 Syntax Note:
In modern HTML5, writing <br> or <br /> is functionally identical; the trailing slash is purely optional and originates from strict XML/XHTML compatibility.
8 Can we display web page inside a webpage or is nesting of webpage possible? Medium
Yes, nesting a webpage inside another webpage is possible in HTML using the <iframe> (Inline Frame) element:
<iframe
src="https://example.com/embed"
width="800"
height="450"
title="Interactive Sandbox"
loading="lazy"
sandbox="allow-scripts allow-same-origin"
referrerpolicy="no-referrer">
</iframe>
### Security Considerations & Clickjacking Defense:
- The
sandboxAttribute: Highly recommended when embedding third-party content. It restricts execution of untrusted scripts, form submissions, and popups. X-Frame-Options& CSPframe-ancestors:
Websites can block themselves from being framed using HTTP response headers (X-Frame-Options: DENY or frame-ancestors 'none') to protect against Clickjacking attacks. If a destination site sends this header, modern browsers will refuse to display it inside an iframe.
9 What are some of the advantages of HTML5 over its previous versions? Medium
HTML5 revolutionized the web platform by deprecating proprietary plugins (like Flash and Silverlight) and standardizing modern web application capabilities:
### Major Advantages:
- Semantic Structure Elements: Introduced
<header>,<footer>,<article>,<section>, and<nav>to replace generic<div>tags, vastly improving SEO and accessibility. - Native Multimedia Support: Introduced
<video>and<audio>tags for native media playback without external browser plugins. - Interactive Graphics (
<canvas>& SVG): Native 2D/3D hardware-accelerated rendering directly in the browser. - Client-Side Storage: Replaced restrictive 4KB cookies with
localStorage(5-10MB) and IndexedDB for offline Progressive Web Apps (PWAs). - Modern Form Controls: Native validation attributes (
required,pattern) and specialized input types (email,date,number). - Web APIs Integration: Geolocation API, WebSockets, Web Workers (background threading), and Drag-and-Drop.
10 What would happen if there is no text between the HTML tags? Medium
There would be nothing to format if there is not text present between the tags. Therefore, nothing will appear on the screen. Tags without closing tag like <img> do not require any text between them.
11 How do you change the color of bullets? Medium
The color of the bullet is always the color of the first text of the list. So, if we can change the color of the bullets by changing the color of the text.
12 What will happen if we don't put <!DOCTYPE HTML> tag? Medium
If we don't put <!DOCTYPE html> tag, the browser will not be able to identify that it is an HTML document and HTML5 tags will not function properly.
13 How can you make an image clickable in HTML? Medium
To make an image clickable, we have to use anchor tag with the image tag nested inside it and specify where we want to be directed to in "href" attribute when image in click.
14 What are the different tags used in an HTML table? Medium
| Tag Name | Definition |
| ----------- | -------------------------------------------------------------- |
| <table> | Defines a table |
| <caption> | Defines a title or caption for a table |
| <thead> | Defines the header of a table |
| <tbody> | Defines the body of a table |
| <tfoot> | Defines the footer of a table |
| <tr> | Defines a row in a table |
| <th> | Defines a header cell in a table |
| <td> | Defines a standard cell in a table |
| <colgroup> | Defines a group of columns in a table |
| <col> | Specifies column properties for each column within <colgroup> |
| <caption> | Defines a title or caption for a table |
15 What are the key attributes used in HTML tables? Medium
| Attribute | Description |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| border | Specifies the width of the border around the table. |
| cellpadding | Specifies the amount of padding to be added to the cells in the table. |
| cellspacing | Specifies the amount of space to be added between cells in the table. |
| width | Specifies the width of the table. |
| height | Specifies the height of the table. |
| align | Specifies the horizontal alignment of the table within its containing element. Possible values are left, center, right, and justify. |
| valign | Specifies the vertical alignment of the table within its containing element. Possible values are top, middle, bottom, and baseline. |
| bgcolor | Specifies the background color of the table. |
| bordercolor | Specifies the color of the border around the table. |
| border-collapse | Specifies whether the borders of the cells in the table should be collapsed into a single border or not. Possible values are collapse and separate. Default is separate. |
| border-spacing | Specifies the amount of space to be added between the cells in the table when the border-collapse property is set to separate. |
| caption | Specifies the title or caption of the table. |
| caption-side | Specifies the side of the table on which to place the caption. Possible values are top, bottom, left, and right. Default is top. |
| empty-cells | Specifies whether or not to display borders around empty cells in the table. Possible values are show and hide. Default is show. |
| frame | Specifies which sides of the table should have borders. Possible values are void, above, below, hsides, vsides, lhs, rhs, and box. |
| rules | Specifies which parts of the table's border should be shown. Possible values are none, groups, rows, cols, and all. Default is none. |
| summary | Specifies a summary of the contents of the table. |
| dir | Specifies the direction of the table's text. Possible values are ltr (left-to-right) and rtl (right-to-left). |
16 What are HTML entities? Medium
HTML entities are codes used to represent special characters in HTML that cannot be easily typed or displayed. Example: & represents (&)
17 What are HTML ARIA attributes and how are they used? Medium
| Attribute | Description | Example |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- |
| aria-label | Provides a short, descriptive label for an element that isn't already provided by its text content or associated label element. | <button aria-label="Search">🔍</button> |
| aria-describedby | References another element that provides additional information about the current element, such as instructions or help text. | <input type="text" aria-describedby="name-help"> <div id="name-help">Enter your full name</div> |
| aria-required | Indicates which form fields are mandatory and must be filled out before the form can be submitted. | <input type="text" aria-required="true"> |
| aria-expanded | Indicates whether a collapsible element like an accordion or dropdown menu is currently expanded or collapsed. | <button aria-expanded="true" aria-controls="menu">Menu</button> <div id="menu">...</div> |
| aria-disabled | Indicates whether an element is currently disabled or not, such as a disabled button. | <button aria-disabled="true">Submit</button> |
| aria-checked | Indicates whether a checkbox or radio button is currently checked or not. | <input type="checkbox" aria-checked="true"> |
| aria-haspopup | Indicates that an element has a pop-up or dropdown menu associated with it. | <button aria-haspopup="true" aria-controls="menu">Menu</button> <div id="menu">...</div> |
| aria-selected | Indicates that an element is currently selected or highlighted, such as a selected item in a list | <li aria-selected="true">Item 1</li> |
| aria-hidden | Indicates that an element is currently hidden or not visible to users, such as content that is only revealed when certain conditions are met. | <div aria-hidden="true">Hidden content</div> |
<br />
---
18 What are the possible ways to apply CSS styles to a web page? Medium
There are three standard methods to apply CSS styling to an HTML document:
### 1. External Stylesheet (Recommended Standard):
Link an external .css file in the <head> using <link>:
<link rel="stylesheet" href="/css/styles.css">
*Benefits:* Clean separation of concerns, browser caching across multiple pages, minimal HTML file sizes.
### 2. Internal / Embedded Styles:
Define rules inside a <style> block within the document <head>:
<style>
body { font-family: system-ui, sans-serif; }
</style>
*Use case:* Single-page email templates or critical path CSS injected for sub-second above-the-fold render speeds.
### 3. Inline Styles:
Apply styles directly to an element via the style attribute:
<p style="color: #2563eb; font-weight: 600;">Highlighted Note</p>
*Drawbacks:* Highest specificity, impossible to cache, clutters markup, prohibits media queries and pseudo-classes (:hover).
19 What are some new features in CSS3? Medium
CSS3 modularized the styling specification, introducing transformative layout engines and dynamic visual capabilities:
### Breakthrough Features in CSS3:
- Modern Layout Engines: Flexbox (1-dimensional) and CSS Grid (2-dimensional) replaced fragile float hacks and table layouts.
- Visual Effects:
border-radius(rounded corners),box-shadow(depth/elevation),linear-gradient()/radial-gradient(). - Motion & Transitions: Native
transitionand@keyframesanimations executed on GPU composite layers. - Responsive Media Queries:
@media (max-width: 768px)enabling mobile-first fluid web layouts. - Color Formats:
rgba(),hsla(), and modern wide-gamut colors (oklch(),color(display-p3)). - Custom Properties (CSS Variables):
--primary-color: #2563eb;enabling dynamic real-time theme switching.
20 What are the CSS selectors? Medium
CSS selectors declare which HTML elements a set of CSS rules applies to:
### Selector Categories:
- **Universal Selector (
*)**: Matches every DOM element. - Type / Tag Selector (
h1,p): Matches elements by HTML tag name. - Class Selector (
.btn-primary): Matches elements possessing that class. - ID Selector (
#header): Matches the unique element with that ID. - Attribute Selectors:
[data-state="active"],[href^="https://"]. - Combinators:
- Descendant (
div p): All paragraphs insidediv. - Child (
div > p): Immediate direct child paragraphs only. - Adjacent Sibling (
h2 + p): The paragraph immediately following anh2. - General Sibling (
h2 ~ p): All paragraphs sharing the same parent followingh2.
- Pseudo-Classes (
:hover,:focus,:nth-child()) and Pseudo-Elements (::before,::after).
21 Explain the difference between classes and IDs in CSS. Medium
Classes are used to group together elements with similar styles, while IDs are used to target specific elements on a page. IDs must be unique, while classes can be used multiple times on a page.
22 Explain box model in CSS. Medium
The box model in CSS is a way of representing elements as boxes with content, padding, borders, and margins. The content area is the actual content of the element, the padding is the space between the content and the border, the border is a line around the element, and the margin is the space between the border and the surrounding elements.
23 Explain the CSS display property and its values. Medium
The CSS display property controls how an element is displayed on a page. The possible values are block, inline, inline-block, none, and others.
24 Explain the CSS float property and its values. Medium
The CSS float property controls the alignment of an element in a page layout. The possible values include left, right, none, and inherit. When an element is floated left or right, other elements will flow around it.
25 What are CSS pseudo-classes? Give some examples. Medium
CSS pseudo-classes are selectors that target elements based on their state or position in the document. Some examples include :hover, :active, :focus, :first-child, :last-child, and :nth-child.
26 How do you define a CSS animation? Medium
We can define CSS animation by creating a set of keyframes that specify the start and end states of an animation. We can apply the animation to an element using the animation property in css.
27 How do you trigger a CSS animation to start and stop? Medium
You can trigger a CSS animation to start and stop using various CSS selectors and events. For example, you can use the :hover pseudo-class to start an animation when a user hovers over an element.
28 How do you create a responsive CSS animation? Medium
We can create responsive CSS animation by using relative units like percentages instead of fixed units like pixels. We can also use media queries to adjust the animation properties based on the size of the viewport.
29 How do you optimize CSS animations for performance? Medium
We can optimize CSS animation for performance by using techniques like reducing the number of elements being animated, minimizing the use of box-shadow and text-shadow, and using transform and opacity instead of top, left, bottom, and right.
30 How do you debug CSS animations and troubleshoot common issues, such as animations not playing or playing too quickly? Medium
We can debug CSS animations by checking for typos or syntax errors, checking browser's compatibility if it supports the property or not, checking for code that may override the animation.
31 Can you specify multiple CSS transitions for an element? Medium
Yes, you can transition multiple CSS properties simultaneously on an element by separating each transition declaration with a comma in the transition shorthand:
.card {
background-color: #ffffff;
transform: translateY(0);
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
/* Multiple distinct transitions */
transition:
background-color 0.2s ease-in,
transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
box-shadow 0.3s ease-out;
}
.card:hover {
background-color: #f8fafc;
transform: translateY(-4px);
box-shadow: 0 12px 24px rgba(0,0,0,0.15);
}
*Performance Tip:* Restrict transitions to GPU-accelerated properties (transform and opacity) to maintain a smooth 60 FPS without triggering CPU layout reflows.
32 What are gradients in CSS? Medium
It is a property of CSS which allows you to display a smooth transformation between two or more than two specified colors. There are two types of gradients in CSS. They are: Linear gradient and radial gradient.
33 How do you center an element using flexbox? Medium
To center an element using flexbox, we need to set the parent container's display property to flex and use the justify-content & align-items properties with the value of center.
34 How do you use the grid-template-columns and grid-template-rows properties to define the size and number of columns and rows in a grid? Medium
You can use the grid-template-columns and grid-template-rows properties to define the size and number of columns and rows in a grid. For example, you might define a grid with three columns, where the first column is 100 pixels wide, the second column is 50% of the available width, and the third column takes up the remaining space, with the following CSS:
grid-template-columns: 100px 50% 1fr;
35 How do you specify the number of columns in a grid using CSS? Medium
You can specify the number of columns in a grid by using the grid-template-columns property. For example, grid-template-columns: repeat(3, 1fr) will create a grid with three columns that are each one fraction of the available space.
36 How do you align items within a grid using CSS? Medium
You can align items within a grid using the justify-items and align-items properties. justify-items aligns items horizontally within a grid, while align-items aligns items vertically.
37 How do you delay the start of a CSS transition? Medium
You can delay the start of a CSS transition using the transition-delay property. This property specifies the amount of time to wait before starting the transition, in seconds or milliseconds. Example: transition-delay: 1s;
38 How do you apply a transition to multiple properties at once? Medium
You can apply a transition to multiple properties at once by separating the property names with commas in the transition-property property. example, transition-property: background-color, color, opacity;
39 What are CSS 2D Transforms? Medium
CSS 2D Transforms are a set of properties that allow you to transform the position, rotation, scaling, and skewing of an element in two dimensions, without affecting the surrounding elements.
40 Can you use negative values with CSS 2D transforms? If so, what effect do they have? Medium
Yes, you can use negative values with CSS 2D transforms. The effect of negative values depends on the function being used. For example, a negative value for the rotate() function will rotate the element counterclockwise instead of clockwise.
41 What are the properties of CSS 2D transform? Medium
The properties of CSS 2D Transforms are:
- transform: specifies the transformation functions to be applied to an element
- transform-origin: specifies the point around which the transformation should occur
- translate: moves an element along the x-axis and/or y-axis
- rotate: rotates an element clockwise or counterclockwise around a given point
- scale: increases or decreases the size of an element
- skew: skews an element along the x-axis and/or y-axis
42 Can you apply multiple transformations to the same element using CSS 2D transforms? Medium
Yes, you can apply multiple transformations to the same element using CSS 2D transforms. You can do this by separating each transformation function with a space in the transform property.
43 What are some important considerations when using text effects? Medium
Important considerations include making sure the text remains readable and legible, ensuring the effect is appropriate for the overall design, and avoiding overuse of effects.
44 How do you target all even or odd elements using a pseudo-selector in CSS? Medium
You can target alternating rows or elements using the :nth-child() structural pseudo-class with the keywords even or odd:
/* Zebra striping table rows */
tbody tr:nth-child(odd) {
background-color: #ffffff;
}
tbody tr:nth-child(even) {
background-color: #f8fafc;
}
### Algebraic Notation (An + B):
The even keyword is functionally equivalent to :nth-child(2n), matching elements at indices 2, 4, 6, 8...
The odd keyword is equivalent to :nth-child(2n+1), matching elements at indices 1, 3, 5, 7...
45 How do you target the first letter of a text element using a pseudo-selector in CSS? Medium
You target the initial character of a block-level text element using the ::first-letter pseudo-element, commonly used to create decorative editorial drop caps:
.article-intro::first-letter {
font-size: 3.5rem;
font-weight: bold;
float: left;
line-height: 0.8;
margin-right: 0.5rem;
color: #1e293b;
}
*Applicability:* ::first-letter applies only to block containers (such as p, div, article), not to inline elements (span).
46 How do you make images responsive in CSS? Medium
To make images responsive in CSS, you can use the max-width: 100% property, which will make the image scale down proportionally to fit the width of its container while maintaining its aspect ratio.
47 How does calc() work in CSS? Medium
The calc() function allows you to perform dynamic mathematical calculations directly in CSS property values, mixing different units together:
/* Mixing fixed pixels with fluid percentages */
.sidebar-layout {
width: calc(100% - 280px);
margin-left: 280px;
}
/* Fluid responsive typography */
h1 {
font-size: calc(1.5rem + 1vw);
}
### Essential Syntax Rules:
- Supports addition (
+), subtraction (-), multiplication (*), and division (/). - Whitespace is strictly mandatory around
+and-operators: calc(100% - 20px)is valid.calc(100%-20px)is invalid syntax because the browser parses-20pxas a negative number unit.
48 Are quotes mandatory in URL’s? Medium
In CSS url() functional notation, quotes (single ' or double ") are optional for standard alphanumeric URLs, but are mandatory in specific edge cases:
/* Valid without quotes */
background-image: url(/images/bg.webp);
/* Valid with quotes (Recommended best practice) */
background-image: url("/images/bg.webp");
### When Quotes Are Strictly Mandatory:
- If the URL contains whitespace or spaces:
url("my banner image.png"). - If the URL contains parentheses, single quotes, or double quotes.
- In inline SVG Data URIs:
url("data:image/svg+xml;utf8,...").
49 Explain what are web-safe fonts and fallback fonts. Medium
Web-safe fonts are fonts that are commonly installed on most devices and web browsers. Fallback fonts are alternative fonts specified in case the primary font is not available on the user's device.
50 How can we create custom cursor in CSS? Medium
To create a custom cursor in CSS, you can use the "cursor" property and set it to "url" with the path to the image file that you want to use as the cursor.
51 Which property is used to control the scrolling of an image in the background? Medium
The background-attachment property controls whether a background image scrolls along with the enclosing page content or remains fixed in a viewport position:
### Primary Values:
scroll(Default): The background image is fixed relative to the element itself and scrolls with the main page.fixed: The background image is pinned relative to the browser viewport, creating a smooth parallax scrolling effect as content moves over it:
.hero-banner {
background-image: url('/images/pattern.svg');
background-attachment: fixed;
background-position: center;
background-size: cover;
}
local: The background image scrolls with the element's internal scrollable contents.
52 Which CSS property is used to capitalize text or convert text to uppercase or lowercase letters? Medium
The text-transform property controls character capitalization and case formatting without altering the underlying raw HTML string:
### Available Values:
uppercase: Converts all letters to uppercase:HIREXTECH INTERVIEW.lowercase: Converts all letters to lowercase:hirextech interview.capitalize: Capitalizes the first letter of each word:Hirextech Interview.none: Preserves the original casing from the HTML markup.
.table-header {
text-transform: uppercase;
letter-spacing: 0.05em;
font-size: 0.75rem;
}
53 Describe a 'rule set' in CSS. Medium
It is an instruction that tells browser on how to render a specific element on the HTML page. It consists of a selector with a declaration block that follows.
54 How can you create a CSS-only dropdown menu? Medium
A CSS-only dropdown menu can be created by using the "hover" pseudo-class and the "display" property. When the user hovers over a parent element, the "display" property of the child element can be set to "block" or "inline-block" to reveal the dropdown menu.
55 What are the potential drawbacks of using CSS frameworks such as Bootstrap? Medium
While CSS frameworks (Bootstrap, Bulma, Foundation) accelerate early prototyping, they present distinct trade-offs in enterprise production environments:
### Key Drawbacks:
- Unused CSS Bloat: Large framework bundles include thousands of unused utility classes and components, degrading First Contentful Paint (FCP) unless aggressively purged.
- Generic Aesthetic ("Bootstrap Look"): Sites built with default framework themes look visually homogeneous and lack unique brand identity.
- Override Specificity Wars: Customizing deep framework styles often requires fighting high specificity rules or abusing
!important. - HTML Class Clutter: Older frameworks tightly couple HTML markup to presentational class names.
- Modern Trend: Modern teams frequently adopt zero-runtime or utility-first tools (like Tailwind CSS) or component primitives (Radix/Shadcn) which only ship classes actually used in source code.
56 How do you customize TailwindCSS to match a specific design system or brand guidelines? Medium
TailwindCSS provides a configuration file that can be customized to match a specific design system or brand guidelines. This file includes variables for colors, fonts, spacing, and more, which can be adjusted to match the project's needs.
57 Can you explain the difference between utility classes and component classes in TailwindCSS? Medium
Utility classes in TailwindCSS are small, single-purpose classes that provide a specific styling utility, such as padding, margin, or text alignment. Component classes, on the other hand, are larger classes that provide a collection of styles for a specific component, such as a button or card.
58 How do you optimize the file size of TailwindCSS in a production environment? Medium
TailwindCSS provides a purge option that removes any unused classes from the final CSS file, reducing its size. This option should be enabled in a production environment to minimize the CSS file size.
59 What are some common performance issues with TailwindCSS, and how do you optimize performance in your projects? Medium
Common performance issues with TailwindCSS include the size of the CSS file and the number of classes being generated. To optimize performance, it is important to enable the purge option in a production environment, use a caching mechanism to speed up builds, and avoid generating unnecessary classes.
60 Can you describe a situation where you would choose not to use SASS? Medium
A developer might choose not to use Sass if they prefer to stick with standard CSS for simplicity or if they are working on a small project where the added features of Sass may not be necessary.
61 What are variables in SASS? Medium
Variables in Sass (SCSS) store reusable styling values (colors, spacing units, fonts) identified by a dollar sign ($) prefix:
// Definition
$primary-blue: #2563eb;
$font-stack: 'Inter', system-ui, sans-serif;
$border-radius-lg: 12px;
// Usage
.hero-card {
background-color: $primary-blue;
font-family: $font-stack;
border-radius: $border-radius-lg;
}
### Difference Between Sass Variables and Native CSS Custom Properties:
- Sass Variables (
$var): Evaluated at build time. Once compiled to CSS, they become static values. Cannot be dynamically changed via JavaScript at runtime or affected by DOM cascading. - CSS Custom Properties (
--var): Evaluated dynamically by the browser engine at runtime. They participate in the cascade and can be modified on the fly in JavaScript or media queries.
62 What is SASS inheritance? Medium
Inheritance allows us to define a set of styles in one selector, called a "parent", and then extend those styles to another selector, called a "child". Example:
@mixin button-style($bg-color, $text-color) {
background-color: $bg-color;
color: $text-color;
display: inline-block;
padding: 8px 16px;
}
// Use the mixin to create different button styles
.button-primary {
@include button-style(#007bff, #fff);
}
.button-secondary {
@include button-style(#6c757d, #fff);
}
63 How do you use 'if' statements in SCSS? Medium
In SCSS, you can use the @if directive to add conditional logic to your styles. Example:
//declaring variable
$background-color: #333;
body {
@if $background-color == #333 {
background-color: $background-color;
} @else {
background-color: #fff;
}
}
64 What are some common mistakes that developers make when writing CSS, and how do you avoid them? Medium
Writing scalable, maintainable CSS is a hallmark of senior front-end engineering. Common pitfalls include:
### 1. Overusing !important
- *Mistake:* Using
!importantas a quick fix to resolve cascade conflicts. - *Fix:* Understand specificity scoring (Inline > ID > Class/Attribute > Tag) and adopt CSS cascade layers (
@layer) or flat BEM methodology.
### 2. Hardcoding Fixed Pixel Heights on Text Containers
- *Mistake:* Setting
height: 200pxon cards containing dynamic copy, causing text overflow when font size increases or translations expand. - *Fix:* Use
min-heightor allow container dimensions to expand fluidly via Flexbox/Grid.
### 3. Animating Layout-Triggering Properties
- *Mistake:* Animating
top,left,width, orheightwhich triggers CPU layout reflows and browser repaint cycles. - *Fix:* Strictly animate composite properties:
transform(translate3d,scale) andopacity.
### 4. Ignoring Responsive Breakpoints & Accessibility
- *Mistake:* Designing exclusively for desktop 1080p and forgetting mobile viewport meta tags or keyboard
:focus-visiblestyles.
65 How do you balance the need for visual aesthetics with the need for website or application functionality? Medium
I balance the need for visual aesthetics with the need for functionality by designing with the user in mind, testing designs with real users, and incorporating feedback and data into the design process.
66 How do you ensure that your CSS is optimized for search engine optimization (SEO)? Medium
We can ensure CSS is optimized for SEO by minimizing code bloat to improve load time, use relevant class names, avoiding inline styles, etc.
67 How do you ensure that your CSS is scalable and maintainable for large projects? Medium
We can ensure that our CSS is scalable and maintainable for large project by:
- Using proper naming convection for ID and classes.
- Using preprocessor like sass, less, etc.
- Using performance enhancing techniques like lazy-loading, etc.
68 How do you use CSS variables to create more flexible and dynamic designs, and what are some use cases where variables are particularly useful? Medium
CSS variables can improve maintainability and reduce repetition. Variables are particularly useful for theming, creating responsive designs, and making changes to global styles.
All 68 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.