Examness

Web & Design

HTML & CSS इंटरव्यू प्रश्न

Layout, specificity, flexbox, grid and responsive design.

225 प्रश्न

  1. 1.

    What is the matrix() transform function?

    शुरुआती

    The matrix() function is a shorthand that combines all 2D transform operations (translate, rotate, scale, skew) into a single 6-value transformation matrix.

    Syntax:

    transform: matrix(a, b, c, d, tx, ty);
    ParameterDescription
    aScales horizontally (scaleX)
    bSkews vertically
    cSkews horizontally
    dScales vertically (scaleY)
    txTranslates horizontally
    tyTranslates vertically

    Equivalent transformations:

    /* These are equivalent */
    transform: translate(10px, 20px) rotate(30deg) scale(1.5);
    
    transform: matrix(
      1.299, 0.75,   /* a, b */
     -0.75,  1.299,  /* c, d */
      10,    20      /* tx, ty */
    );

    > Note: matrix() is mostly used internally by browsers and animation libraries. Prefer individual transform functions for readability.

    ↥ back to top

  2. 2.

    What is display: contents and what does it do?

    शुरुआती

    display: contents makes an element act as if it is not there for layout purposes — it disappears from the box tree, but its children remain and participate in the parent\'s layout as if they were direct children.

    Use case — unwrapping a semantic element for layout:

    <ul class="grid-list">
      <li class="group">       <!-- this wrapper breaks grid layout -->
        <a href="#">Item 1</a>
        <a href="#">Item 2</a>
        <a href="#">Item 3</a>
      </li>
    </ul>
    /* Without display: contents — the <li> is a grid item, not the <a> elements */
    .grid-list {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
    }
    
    /* With display: contents — <li> box is removed, <a> elements become grid items */
    .group {
      display: contents;
    }

    Important caveats:

    • The element itself becomes invisible to layout — padding, border, background, and margin on it have no visual effect.
    • The element is still in the DOM and accessible to JavaScript.
    • Accessibility warning: Applying display: contents to certain semantic elements ( , , ) can strip their ARIA roles in some browsers, breaking accessibility.
    /* Safe use: purely structural wrapper with no semantic role */
    .layout-wrapper { display: contents; }
    
    /* Unsafe use: strips button role in some browsers */
    button { display: contents; } /* ❌ avoid */

    ↥ back to top

    # 17. MISCELLANEOUS

  3. 3.

    What are the CSS animation properties?

    शुरुआती
    PropertyDescription
    animationShorthand for all animation properties
    animation-nameName of the @keyframes rule to apply
    animation-durationHow long one cycle of the animation takes (e.g., 1s, 500ms)
    animation-timing-functionSpeed curve of the animation (ease, linear, ease-in, ease-out, cubic-bezier(...))
    animation-delayDelay before the animation starts
    animation-iteration-countNumber of times the animation repeats (1, infinite, etc.)
    animation-directionWhether animation plays forward, backward, or alternates (normal, reverse, alternate, alternate-reverse)
    animation-fill-modeStyles applied before/after the animation runs (none, forwards, backwards, both)
    animation-play-stateWhether animation is running or paused (running, paused)

    Example:

    .bouncing-ball {
      animation: bounce 1s ease-in-out infinite alternate;
    }
    
    @keyframes bounce {
      from { transform: translateY(0); }
      to   { transform: translateY(-60px); }
    }

    ↥ back to top

  4. 4.

    What is UI/UX?

    शुरुआती

    1) UI or User Interface: is how a product or website is laid out and how you interact with it: Where the buttons are, how big the fonts are, and how menus are organized are all elements of UI.

    2) UX or User Experience: is how you feel about using a product or a website. So, your love for the way the new Apple Watch looks or your excitement that there\'s finally a tablet-sized iPhone to watch those Corgi videos you’re obsessed with are reflections of UX. So the new look of the Facebook news feed involves a change to UI, and the way you navigate that new page is the UX.

    ↥ back to top

  5. 5.

    What are common responsive breakpoints used in CSS?

    शुरुआती

    Breakpoints define the viewport widths at which your layout changes. Common breakpoints are loosely aligned with device categories, but should be based on your content rather than specific devices.

    Bootstrap 5 breakpoints (widely used reference):

    BreakpointClass prefixMin-width
    Extra smallxs< 576px
    Smallsm≥ 576px
    Mediummd≥ 768px
    Largelg≥ 992px
    Extra largexl≥ 1200px
    XXLxxl≥ 1400px

    Example:

    /* Extra small — default (mobile-first) */
    .grid {
      display: block;
    }
    
    /* Small (≥ 576px) */
    @media (min-width: 576px) {
      .grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
      }
    }
    
    /* Medium (≥ 768px) */
    @media (min-width: 768px) {
      .grid {
        grid-template-columns: repeat(3, 1fr);
      }
    }
    
    /* Large (≥ 992px) */
    @media (min-width: 992px) {
      .grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 2rem;
      }
    }

    ↥ back to top

  6. 6.

    What are the different css filters you can use?

    शुरुआती

    The filter CSS property applies graphical effects like blur or color shift to an element. Filters are commonly used to adjust the rendering of images, backgrounds, and borders.

    Example:

    img {
      -webkit-filter: brightness(200%); /* Safari 6.0 - 9.0 */
      filter: brightness(200%);
    }

    Filter Functions

    Sl.NoFilterDescription
    01.noneDefault value. Specifies no effects
    02.blur(px)Applies a blur effect to the image. A larger value will create more blur.
    03.brightness(%)Adjusts the brightness of the image.
    04.contrast(%)Adjusts the contrast of the image.
    05.drop-shadow(h-shadow v-shadow blur spread color)Applies a drop shadow effect to the image.
    06.grayscale(%)Converts the image to grayscale.
    07.hue-rotate(deg)Applies a hue rotation on the image. The value defines the number of degrees around the color circlethe image samples will be adjusted. 0deg is default, and represents the original image.
    08.invert(%)Inverts the samples in the image.
    09.opacity(%)Sets the opacity level for the image. The opacity-level describes the transparency-level
    10.saturate(%)Saturates the image.
    11.sepia(%)Converts the image to sepia.
    12.url()The url() function takes the location of an XML file that specifies an SVG filter, and may include an anchor to a specific filter element. for example filter: url(svg-url#element-id)
    13.initialSets this property to its default value.
    14.inheritInherits this property from its parent element.

    ↥ back to top

  7. 7.

    What is mobile-first design and why is it recommended?

    शुरुआती

    Mobile-first design means writing base CSS for the smallest screen first and then progressively enhancing the layout for larger screens using min-width media queries.

    Why it is recommended:

    1. Performance: Mobile devices receive only the base styles; larger screens load additional styles on top. Unused CSS is minimised for the most bandwidth-constrained devices.
    2. Progressive enhancement: Forces you to prioritise core content and functionality before adding enhancements.
    3. Simpler CSS: Overriding simple mobile styles upward is usually less complex than overriding complex desktop styles downward.
    4. SEO & Google: Google uses mobile-first indexing, so mobile-friendly pages rank better.

    Example — mobile-first layout:

    /* Base (mobile): single-column layout */
    .layout {
      display: grid;
      grid-template-columns: 1fr;
      gap: 1rem;
      padding: 1rem;
    }
    
    .sidebar {
      order: 2; /* Sidebar below content on mobile */
    }
    
    /* Tablet (≥ 768px): two-column layout */
    @media (min-width: 768px) {
      .layout {
        grid-template-columns: 1fr 2fr;
        padding: 2rem;
      }
    
      .sidebar {
        order: 0; /* Restore natural order */
      }
    }
    
    /* Desktop (≥ 1200px): three-column layout */
    @media (min-width: 1200px) {
      .layout {
        grid-template-columns: 250px 1fr 200px;
        gap: 2rem;
        max-width: 1400px;
        margin: 0 auto;
      }
    }

    ↥ back to top

  8. 8.

    What is transform-origin and how does it affect transformations?

    शुरुआती

    The transform-origin property specifies the point around which a transformation is applied. By default it is set to 50% 50% (the center of the element).

    Syntax:

    transform-origin: x-axis y-axis z-axis;

    Values:

    ValueDescription
    x-axisleft, center, right, a length, or a percentage
    y-axistop, center, bottom, a length, or a percentage
    z-axisA length value (used for 3D transforms)

    Example:

    /* Rotate around the top-left corner */
    .rotate-top-left {
      transform-origin: top left;
      transform: rotate(45deg);
    }
    
    /* Rotate around a custom point */
    .rotate-custom {
      transform-origin: 20px 80%;
      transform: rotate(45deg);
    }
    
    /* Default: rotate around center */
    .rotate-center {
      transform-origin: 50% 50%; /* default */
      transform: rotate(45deg);
    }

    ↥ back to top

  9. 9.

    What is progressive rendering?

    शुरुआती

    Progressive rendering is the name given to techniques used to improve the performance of a webpage (in particular, improve perceived load time) to render content for display as quickly as possible.

    Examples:

    • Lazy loading of images - Images on the page are not loaded all at once. JavaScript will be used to load an image when the user scrolls into the part of the page that displays the image.
    • Prioritizing visible content (or above-the-fold rendering) - Include only the minimum CSS/content/scripts necessary for the amount of page that would be rendered in the users browser first to display as quickly as possible, you can then use deferred scripts or listen for the DOMContentLoaded/load event to load in other resources and content.
    • Async HTML fragments - Flushing parts of the HTML to the browser as the page is constructed on the back end.

    ↥ back to top

  10. 10.

    What is the @media (prefers-color-scheme) feature and how do you use it?

    शुरुआती

    prefers-color-scheme detects whether the user has requested a light or dark color theme in their OS or browser settings. It enables CSS-only dark mode support.

    ValueDescription
    lightUser prefers a light theme (default)
    darkUser prefers a dark theme

    Example:

    /* Default (light) theme */
    :root {
      --bg-color: #ffffff;
      --text-color: #333333;
      --card-bg: #f5f5f5;
      --link-color: #0066cc;
    }
    
    /* Dark theme via media query */
    @media (prefers-color-scheme: dark) {
      :root {
        --bg-color: #1a1a1a;
        --text-color: #e0e0e0;
        --card-bg: #2a2a2a;
        --link-color: #66aaff;
      }
    }
    
    body {
      background-color: var(--bg-color);
      color: var(--text-color);
      transition: background-color 0.3s, color 0.3s;
    }
    
    .card {
      background-color: var(--card-bg);
      padding: 1rem;
      border-radius: 8px;
    }
    
    a {
      color: var(--link-color);
    }

    ↥ back to top

  11. 11.

    What is the :root pseudo-class and how is it different from the html selector?

    शुरुआती

    :root targets the root element of the document tree, which in HTML is the element. Despite targeting the same element, :root has higher specificity than the html type selector.

    Feature:roothtml
    What it selectsRoot element of the documentThe element
    Specificity0-1-0 (class-level)0-0-1 (type-level)
    Works in SVG/XMLYesNo
    Common useDeclaring CSS custom propertiesGeneral HTML styling

    Example:

    /* Commonly used to declare CSS custom properties globally */
    :root {
      --primary-color: #3498db;
      --font-size-base: 16px;
      --spacing-unit: 8px;
    }
    
    body {
      font-size: var(--font-size-base);
      color: var(--primary-color);
    }

    ↥ back to top

  12. 12.

    What is the purpose of the box-sizing property?

    शुरुआती

    The box-sizing CSS property sets how the total width and height of an element is calculated.

    • content-box: the default width and height values apply to the element\'s content only. The padding and border are added to the outside of the box.
    • padding-box: Width and height values apply to the element\'s content and its padding. The border is added to the outside of the box. Currently, only Firefox supports the padding-box value.
    • border-box: Width and height values apply to the content, padding, and border.
    • inherit: inherits the box sizing of the parent element.

    Example:

    box-sizing: content-box;
    width: 100%;
    border: solid rgb(90,107,204) 10px;
    padding: 5px;

    ↥ back to top

  13. 13.

    What is CSS Subgrid and what problem does it solve?

    शुरुआती

    Subgrid (CSS Grid Level 2) allows a grid item that is itself a grid container to inherit the track sizing of its parent grid rather than define its own independent tracks. This solves the long-standing problem of aligning content across nested grid items.

    The problem without subgrid:

    <div class="cards">        <!-- 3-column grid -->
      <div class="card">       <!-- each card is its own flex/grid, unaligned -->
        <h2>Title One</h2>
        <p>Short description</p>
        <button>Action</button>
      </div>
      <div class="card">
        <h2>Title Two With a Longer Name</h2>
        <p>A much longer description that wraps multiple lines and pushes the button down.</p>
        <button>Action</button>  <!-- buttons are misaligned across cards -->
      </div>
    </div>

    Solution with subgrid:

    /* Parent defines 3 columns */
    .cards {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 1.5rem;
    }
    
    /* Each card spans all 3 rows of the parent grid\'s row tracks */
    .card {
      display: grid;
      grid-row: span 3;               /* span 3 rows */
      grid-template-rows: subgrid;    /* inherit parent\'s row sizing */
      /* Now: title/description/button rows align perfectly across all cards */
    }
    
    .card h2      { align-self: start; }
    .card p       { align-self: start; }
    .card button  { align-self: end; margin-top: auto; }

    Browser support: Chrome 117+, Firefox 71+, Safari 16+.

    ↥ back to top

  14. 14.

    What is the property that is used for controlling image-scroll?

    शुरुआती

    The background-attachment property in CSS is used to specify the kind of attachment of the background image with respect to its container. It can be set to scroll or remain fixed. It can be applied to all HTML elements.

    Syntax

    background-attachment: scroll|fixed|local|initial|inherit;

    Property Values

    ValueDescription
    scrollThe background image will scroll with the page. This is default
    fixedThe background image will not scroll with the page
    localThe background image will scroll with the element\'s contents
    initialSets this property to its default value. Read about initial
    inheritInherits this property from its parent element. Read about inherit

    Example:

    <!DOCTYPE html>
    <html>
      <head>
        <style>
          body {
            background-image: url("../images/img_tree.gif");
            background-repeat: no-repeat;
            background-attachment: fixed;
          }
        </style>
      </head>
    <body>
      <h1>The background-attachment Property</h1>
    
      <p>The background-image is fixed. Try to scroll down the page.</p>
        ...
      <p>If you do not see any scrollbars, try to resize the browser window.</p>
    </body>
    </html>

    Live Demo: CSS background-attachment

    ↥ back to top

  15. 15.

    What are CSS @keyframes and how do they work?

    शुरुआती

    @keyframes is an at-rule that defines the intermediate steps (waypoints) of a CSS animation sequence. Each keyframe describes how the animated element should render at a given point during the animation.

    Syntax:

    @keyframes animation-name {
      from { /* starting styles */ }
      to   { /* ending styles */   }
    }
    
    /* OR using percentages for multiple steps */
    @keyframes slide-in {
      0%   { transform: translateX(-100%); opacity: 0; }
      60%  { transform: translateX(10px);  opacity: 1; }
      100% { transform: translateX(0);     opacity: 1; }
    }

    Applying the animation:

    .element {
      animation-name: slide-in;
      animation-duration: 0.6s;
      animation-timing-function: ease-out;
      animation-fill-mode: forwards;
    }

    ↥ back to top

  16. 16.

    What is animation-fill-mode and what are its values?

    शुरुआती

    animation-fill-mode controls what styles are applied to an element before the animation starts and after it ends.

    ValueDescription
    noneDefault. No styles are applied outside the animation\'s active period
    forwardsElement retains the styles of the last keyframe after the animation ends
    backwardsElement applies the styles of the first keyframe during the delay period
    bothApplies both forwards and backwards behaviour

    Example:

    .element {
      animation: fadeIn 1s ease 0.5s forwards;
    }
    
    @keyframes fadeIn {
      from { opacity: 0; }
      to   { opacity: 1; }
    }
    /* Without 'forwards', the element would snap back to opacity: 0 after the animation */

    ↥ back to top

  17. 17.

    What are web-safe fonts?

    शुरुआती

    Web-safe fonts are fonts that are pre-installed across most operating systems and browsers, ensuring consistent rendering without requiring an external font file.

    Common web-safe fonts:

    CategoryFonts
    SerifTimes New Roman, Georgia, Palatino
    Sans-serifArial, Helvetica, Verdana, Tahoma, Trebuchet MS
    MonospaceCourier New, Lucida Console
    p {
      font-family: Arial, Helvetica, sans-serif; /* fallback chain */
    }

    Always provide a generic family (serif, sans-serif, monospace) as the last fallback.

    ↥ back to top

  18. 18.

    What is CSS flexbox?

    शुरुआती

    The Flexible Box Layout Module, makes it easier to design flexible responsive layout structure without using float or positioning. Flexbox makes it simple to align items vertically and horizontally using rows and columns. Items will "flex" to different sizes to fill the space.

    Before the Flexbox Layout module, there were four layout modes:

    • Block, for sections in a webpage
    • Inline, for text
    • Table, for two-dimensional table data
    • Positioned, for explicit position of an element

    Flex Container:

    An area of a document laid out using flexbox is called a flex container. To create a flex container, we set the value of the area\'s container\'s display property to flex or inline-flex. As soon as we do this the direct children of that container become flex items.

    Flexbox Terminology:

    ↥ back to top

  19. 19.

    What is the ::placeholder pseudo-element?

    शुरुआती

    ::placeholder styles the placeholder text of an or element — the hint text shown when the field has no value.

    Example:

    input::placeholder {
      color: #aaa;
      font-style: italic;
      font-size: 0.9em;
    }
    
    /* Style placeholder on focus */
    input:focus::placeholder {
      opacity: 0.4;
    }

    > Note: Only a subset of CSS properties reliably apply to ::placeholder (color, font, opacity). Avoid using it to replace a proper element for accessibility reasons.

    ↥ back to top

  20. 20.

    What is the pointer-events property in CSS?

    शुरुआती

    pointer-events controls whether and how an element responds to mouse/touch/pointer interactions.

    ValueDescription
    autoDefault — normal pointer interaction
    noneElement ignores all pointer events (clicks, hover, cursor) — events pass through to elements below
    visiblePainted, visibleFill, etc.SVG-specific values

    Common use cases:

    /* Disable clicking on a button during loading */
    .button--loading {
      pointer-events: none;
      opacity: 0.6;
      cursor: not-allowed;
    }
    
    /* Make an overlay transparent to mouse events (click-through overlay) */
    .tooltip-overlay {
      position: fixed;
      inset: 0;
      pointer-events: none; /* clicks pass through to elements beneath */
    }
    
    /* Re-enable on a specific child inside a pointer-events:none parent */
    .parent { pointer-events: none; }
    .parent .clickable-child { pointer-events: auto; }
    
    /* Disable hover effects on an icon inside a button */
    button .icon {
      pointer-events: none; /* prevents icon from being the event target */
    }

    > Important: pointer-events: none only affects CSS and DOM pointer events. The element is still in the DOM, still participates in layout, and is still focusable via keyboard — so it is not equivalent to disabled for accessibility purposes.

    ↥ back to top