Tailwind & Frequently Asked CSS Interview Questions

1. Why is Tailwind CSS popular for modern web design?

Ans: Modern web projects demand speed, flexibility, and clean code. Tailwind CSS is widely used for efficiently designing responsive web pages. It offers rapid development, highly customizable utilities, minimal CSS output, and strong community support with excellent documentation.

2. What does utility-first mean in Tailwind CSS?

Ans: In Tailwind CSS, the ‘utility-first approach’ refers to using predefined utility classes directly in HTML to style elements. This eliminates the need for writing custom CSS files. It encourages a modular, simplified design system and allows for faster and more efficient development by applying small, reusable classes inline.

3. How can you center an image using Tailwind CSS?

Ans: There are multiple ways to center an image using Tailwind CSS:

1. Using Flexbox:
Apply flex, justify-center, and items-center to the container to center the image both horizontally and vertically.

2. Using Margin Auto:
Apply m-auto to the image element for simple horizontal centering, especially when a fixed width is set or within a block-level container.

4. How is Tailwind CSS different from other CSS frameworks?

Ans: Tailwind CSS vs. Other CSS Frameworks: Key Differences

Feature Tailwind CSS Other CSS Frameworks
Core Philosophy Utility-first; promotes custom design from scratch Component-based; relies on pre-designed UI elements
Design Control Full design control; no opinionated default styles Limited control; predefined styles often need overriding
Setup Complexity Simple, but requires configuration for customization Easy setup with prebuilt components ready to use
Customization Extensive via configuration files Limited to theme variables and predefined options
Responsive Design Built-in responsive utilities; easy to customize breakpoints Fixed breakpoints; less flexible responsive options
Component Flexibility Developers build custom components as needed Provides styled components like buttons, navbars out of the box
File Size Management Optimized production builds with purged unused styles Larger files due to unused bundled component styles
Learning Curve Moderate; understanding utility class system is essential Low; easier to start with prebuilt components
Ideal For Developers building unique, tailored UI designs Projects needing fast setup with common design patterns

5. Do you get overscroll behavior customization through Tailwind CSS?

Ans: Yes, Tailwind CSS offers utility classes to customize overscroll behavior. Key examples include:

  • overscroll-auto – Applies the browser’s default scroll behavior.

  • overscroll-contain – Prevents scroll chaining by confining the scroll to the element itself.

  • overscroll-none – Completely disables scroll chaining, stopping overflow scroll at the element’s boundary.

6. How do you align form elements to the center using Tailwind CSS?

Ans: To center-align form elements using Tailwind CSS, use utility classes like justify-center and items-center along with flex and flex-col. These classes serve as alternatives to traditional CSS flex properties.

Example Syntax:

html
<div class="flex flex-col justify-center items-center">
...
</div>

7. What is the way of creating a fixed or sticky header using Tailwind CSS?

Ans: To create a fixed or sticky header in Tailwind CSS, use the fixed or sticky classes along with top-0 and inset-x-0 for proper positioning.

Syntax:

html
<header class="fixed top-0 inset-x-0">...</header>
<header class="sticky top-0 inset-x-0">...</header>

For a sticky header, ensure the parent element has the relative class to enable correct positioning.

  • fixed: Keeps the header at the top of the viewport even while scrolling.

  • sticky: Makes the header stick to the top only when it scrolls into view.

8. How can you align two elements to the left and right using Tailwind CSS?

Ans: In Tailwind CSS, you can align elements on opposite sides using Flexbox utility classes. Set the parent container to flex, then use justify-between to place one element on the left and the other on the right. To vertically center the items, add items-center.

For clearing floated content, use the flow-root utility—introduced in Tailwind CSS v2.0. If you’re using an earlier version, replace flow-root with clearfix for similar behavior.

9. How can you style elements based on state in Tailwind CSS?

Ans: State-Based Styling in Tailwind CSS

Tailwind CSS allows state-based styling using variant utilities such as hover, focus, and active.

Syntax:

css
hover:{utility}
focus:{utility}
active:{utility}

Description of Variants:

  • hover: Applies styles when the user hovers over the element.
    Example: hover:bg-blue-500

  • focus: Applies styles when the element is focused (e.g., via keyboard navigation or mouse click).
    Example: focus:outline-none

  • active: Applies styles when the element is in an active state (e.g., being clicked or tapped).
    Example: active:scale-95

10. How can you apply the Rotate property to elements with Tailwind CSS?

Ans: Tailwind CSS Rotation Utilities

Tailwind CSS provides utility classes for both clockwise and anti-clockwise rotations.

Clockwise Rotation Classes:
rotate-0, rotate-1, rotate-2, rotate-3, rotate-6, rotate-12, rotate-45, rotate-90, rotate-180

Anti-Clockwise Rotation Classes:
-rotate-0, -rotate-1, -rotate-2, -rotate-3, -rotate-6, -rotate-12, -rotate-45, -rotate-90, -rotate-180

Syntax:

html
<element class="rotate-{degree}">...</element>

Replace {degree} with the desired rotation value.

Frequently Asked CSS Questions

1. Tell us something about CSS3.

Ans: CSS3 is modular and supported by nearly all modern browsers. It introduces various graphics-related features, such as box-shadow, border-radius, and flexbox. Developers can create precise, multi-layered background effects using properties like background-image, background-position, and background-repeat.

2. What are CSS image scripts?

Ans: A group of images combined into a single file is called a CSS image sprite. It helps reduce load time by displaying multiple images from one file on a web page.

3. How is a CSS selector used?

Ans: With a CSS selector, we can target specific HTML content to apply styles, effectively bridging HTML files and style sheets. The CSS selector syntax is used to “select” HTML elements based on their class, ID, type, and other attributes.

4. Explain CSS specificity.

Ans:  CSS specificity is a ranking system that determines which style declaration is applied to an element. ID selectors have higher specificity, while the universal selector (*) has the lowest. Specificity is calculated based on four categories: inline styles, ID selectors, classes and attributes (including pseudo-classes), and element selectors (including pseudo-elements).

5. What are the properties of flexbox?

Ans: The properties of Flexbox include flex-direction, flex-wrap, flex-flow, justify-content, align-items, and align-content.

6. Define gradients in CSS.

Ans: A CSS property that enables smooth transitions between two or more specified colors. The two main types of gradients are linear and radial.

7. Tell us about the use of the CSS Box Model.

Ans: The CSS Box Model wraps each HTML element in a rectangular box consisting of content, padding, border, and margin. It allows precise control over layout by letting us add borders and define spacing between elements.

8. Differentiate between absolute and relative in CSS.

Ans: The main difference is that position: relative positions the element relative to its original position. For example, if we write right: 20px, the element shifts 20px to the left from its normal position.

In contrast, position: absolute positions the element relative to the nearest non-static parent. So, if we write right: 20px, the element will be placed 20px from the right edge of that parent element.

9. What are the position states in CSS?

Ans: The four position values in CSS are: static (default), relative, absolute, and fixed.

10. What is common between class and ID?

Ans: Both class and ID are used in HTML to apply CSS styles. An ID targets a specific, unique element, while a class can be used for multiple elements.