1. Which build process ensures Tailwind CSS performs efficiently in large apps?
Using PostCSS with purge and minify ensures only used styles remain in production, reducing file size and boosting loading speed.
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
Cognizant · Tailwind CSS
Practice Tailwind CSS questions specifically asked in Cognizant interviews – ideal for online test preparation, technical rounds and final HR discussions.
Questions
49
Tagged for this company + subject
Company
Cognizant
View company-wise questions
Subject
Tailwind CSS
Explore topic-wise practice
Go through each question and its explanation. Use this page for targeted revision just before your Cognizant Tailwind CSS round.
Using PostCSS with purge and minify ensures only used styles remain in production, reducing file size and boosting loading speed.
For complete preparation, combine this company + subject page with full company-wise practice and subject-wise practice. You can also explore other companies and topics from the links below.
When you use 'extend', Tailwind keeps its default values and adds yours on top. Using 'theme' replaces the defaults entirely, which is useful if you want to create a fully custom design system.
theme: { extend: { colors: { brand: '#1E40AF' } } }The 'items-center' class aligns items along the cross axis of a flex container. It’s commonly used with 'flex' and 'justify-center' to fully center content both ways.
class='flex items-center justify-center h-screen'
The 'uppercase' class transforms text to all capital letters. Tailwind also includes 'lowercase' and 'capitalize' for other text transformations.
class='uppercase tracking-widest'
The 'hidden' class hides an element, and combining it with breakpoints controls visibility. For example, 'sm:hidden lg:block' hides content on small screens but shows it on large ones.
class='sm:hidden lg:block'
You can use 'first:' and 'last:' variants to style the first or last element in a list. It’s helpful for rounded corners or removing extra borders in grouped elements.
class='first:rounded-t last:rounded-b'
A card component usually uses 'shadow-lg' for depth, 'rounded-lg' for corners, padding for spacing, and a neutral background. Together they create clean, reusable blocks.
class='bg-white rounded-lg shadow-lg p-4'
Using Flexbox utilities 'flex justify-between items-center' creates a responsive navbar with evenly spaced items on both sides.
class='flex justify-between items-center px-6 py-4 bg-gray-800 text-white'
JIT mode compiles classes as you use them in your project instead of generating all possible combinations. It makes builds faster and CSS files smaller.
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch
To use Tailwind in your project, you install it using npm install tailwindcss and initialize it with npx tailwindcss init. This generates the configuration file for customization.
npm install tailwindcss npx tailwindcss init
Tailwind speeds up development by letting developers use small, reusable utility classes instead of writing long CSS files. This reduces context switching between HTML and CSS.
Tailwind is flexible. You can still use your own CSS for specific needs or extend Tailwind’s theme using tailwind.config.js for custom utilities.
Custom colors are added inside the theme.extend section of tailwind.config.js. This keeps existing Tailwind colors and adds your custom palette. You can then use these colors directly as class names like text-brand or bg-brand.
theme: { extend: { colors: { brand: '#0EA5E9' } } }Plugins extend Tailwind by adding new utilities, components, or variants. For example, the official typography and forms plugins enhance readability and form styling automatically.
plugins: [require('@tailwindcss/typography')]Tailwind uses 'flex-col' to make items align vertically. By default, 'flex' arranges children in a row. Changing it to column stacks them top to bottom.
class='flex flex-col gap-4'
The 'grid' class applies display: grid. You can then use 'grid-cols-' or 'grid-rows-' utilities to define columns or rows for your layout.
class='grid grid-cols-3 gap-6'
Tailwind provides classes like 'absolute', 'relative', and 'fixed' to control positioning. Using 'absolute' positions the element relative to its first positioned ancestor.
class='relative'><div class='absolute top-0 left-0'>
By default, grids fill rows first. The 'grid-flow-col' class makes grid items flow across columns instead, changing how new items are placed in the grid.
class='grid grid-flow-col gap-4'
Tailwind uses the 'font-' prefix for weight control. 'font-bold' applies font-weight: 700 to make text bold and visually stronger.
class='font-bold text-gray-800'
The 'bg-' prefix in Tailwind defines background colors. 'bg-red-500' applies a moderate red tone, while you can use different shades from 100 to 900 for variations.
class='bg-red-500 text-white'
The 'leading-' utilities control line height. For example, 'leading-tight' reduces spacing between lines while 'leading-loose' increases it, improving text readability.
class='text-lg leading-relaxed'
The 'mx-auto' class applies margin-left and margin-right as auto, which centers block elements like divs or containers horizontally.
class='w-1/2 mx-auto'
The 'bg-gradient-to-r' class creates a gradient background that flows from left to right. Combine it with 'from-' and 'to-' color utilities to control the gradient direction and colors.
class='bg-gradient-to-r from-blue-400 to-green-500'
The 'bg-no-repeat' class sets background-repeat to none. It’s commonly used with custom background images to prevent tile repetition.
class='bg-no-repeat bg-cover bg-center'
Tailwind’s border utilities define border thickness. 'border-2' applies a consistent 2-pixel border to all sides. You can also target specific sides like border-t or border-b.
class='border-2 border-gray-400'
Tailwind’s rounding scale ranges from rounded-none to rounded-full. 'rounded-sm' applies a small, subtle radius for a clean and minimal edge effect.
class='rounded-sm border border-gray-300'
Tailwind supports blend modes for creative effects. 'bg-blend-multiply' blends the background image and color by multiplying their values, adding depth or color tone.
class='bg-blend-multiply bg-blue-500 bg-[url(bg.jpg)]'
The 'animate-spin' class rotates the element continuously, often used for loading icons or progress indicators.
class='animate-spin h-6 w-6 text-blue-500'
The 'md:' prefix applies styles when the screen width is at least 768 pixels. Tailwind uses min-width breakpoints, meaning the style applies from that size and up.
class='bg-blue-300 md:bg-green-300'
Tailwind allows responsive styling by prefixing classes with breakpoints. For example, 'sm:p-2' applies at small screens, while 'lg:p-6' applies from 1024px and above.
class='p-1 sm:p-2 lg:p-6'
The 'media' strategy uses the CSS media query '(prefers-color-scheme: dark)' to automatically switch themes based on system preferences.
The 'focus:' variant activates when an input or button receives keyboard or mouse focus. It’s useful for accessibility and visual feedback in forms.
class='focus:outline-none focus:ring-2 focus:ring-blue-500'
The 'disabled:' prefix applies styles only when an element is disabled. For example, 'disabled:opacity-50' dims a button to show it's inactive.
class='bg-blue-500 disabled:bg-gray-400 disabled:cursor-not-allowed'
The 'peer' class marks an element that others can reference with 'peer-*' variants. It’s useful for form interactions like showing messages when a checkbox is checked.
<input type='checkbox' class='peer'><p class='peer-checked:block hidden'>Visible on check</p>
Tailwind’s 'placeholder:' variant lets you style placeholder text in input fields. For example, 'placeholder-gray-400' changes its color.
class='placeholder-gray-400 focus:placeholder-gray-600'
The 'duration-' utilities define how long a transition takes. For instance, 'duration-500' means the transition completes in 0.5 seconds.
class='transition duration-500 ease-in-out'
The 'ease-in' easing function starts the animation slowly and speeds up toward the end, giving a natural acceleration effect.
class='transition ease-in duration-300'
The 'rotate-45' utility rotates the element by 45 degrees clockwise. You can combine it with hover states for interactive rotation effects.
class='transform hover:rotate-45'
The 'animate-pulse' animation repeatedly fades elements in and out softly, often used to indicate loading or active states.
class='animate-pulse bg-gray-200 h-6 w-32'
Badges or tags are usually small inline-block elements with soft colors and full rounding for pill shapes. Tailwind utilities make them quick to style.
class='inline-block px-2 py-1 text-xs font-semibold rounded-full bg-green-100 text-green-800'
Tailwind provides various shadow depths. 'shadow-xl' gives more elevation, making elements pop visually on light backgrounds.
class='bg-white rounded-lg shadow-xl p-6'
In Next.js, you typically import Tailwind’s compiled CSS inside app.js or the root layout file. This ensures all components inherit its utility styles globally.
import '../styles/globals.css';
The @apply directive lets you create custom reusable class definitions by combining Tailwind utilities inside your CSS. It helps reduce duplication.
@layer components { .btn { @apply px-4 py-2 bg-blue-500 text-white rounded; } }Tailwind’s responsive utilities like 'w-full sm:w-1/2' make images fluid. Combined with Next.js's Image component, it ensures adaptive performance across devices.
class='w-full sm:w-1/2 rounded-lg'
Apply the class .form-select to a select element. It adds proper height, padding, and a styled arrow that matches the Bootstrap theme.
<select class='form-select'><option>One</option></select>
Add the class .form-switch to a .form-check wrapper. Keep the input as a checkbox. Bootstrap will automatically style it to look like a toggle switch.
<div class='form-check form-switch'> <input class='form-check-input' type='checkbox' id='notify'> <label class='form-check-label' for='notify'>Notifications</label> </div>
Inside an input group, wrap any prefix or suffix text in a span with the class .input-group-text. It keeps the text vertically aligned with the input and maintains consistent spacing.
<div class='input-group'> <span class='input-group-text'>₹</span> <input class='form-control' type='number'> </div>
Use .invalid-feedback for error text and .valid-feedback for success messages. These stay hidden until the input becomes invalid or valid within a validated form.
<div class='invalid-feedback'>Please enter a valid email.</div>
Bootstrap 5 no longer includes .form-row. To build horizontal forms, use the standard grid with .row and .col classes so labels and controls align responsively.
<div class='row g-3'> <label class='col-sm-3 col-form-label'>Email</label> <div class='col-sm-9'><input class='form-control' type='email'></div> </div>