
Top Tailwind CSS MCQ Questions with Answers (Beginner to Advanced)
Practice Tailwind CSS with multiple choice questions and answers. Perfect for beginners and developers preparing for interviews.
1. How do you apply a background using Tailwind CSS?
- 'Bg-color-blue'
- 'Background-blue'
- 'Bg-blue-500'
- 'Background-color-blue-500'
Ans: 3) 'bg-color-500'
Explanations: The class bg-blue-500 sets the background color of an element to a specific shade of blue.
2. Which class would you use in Tailwind to center text horizontally?
- 'Text-center'
- 'Align-center'
- 'Text-middle'
- 'center-text'
Ans: 1) 'text-center'
Explanations: The text-center class in Tailwind CSS centers the text horizontally within its container.
3. What is the value in px for one spacing unit in Tailwind CSS?
- 4px
- 5px
- 8px
- 10px
Ans: 1): 4px
Explanations: In Tailwind CSS, the base unit for spacing is 0.25rem, which equals 4px (since 1rem is 16px by default).
4. Who inherits the spacing scale in Tailwind CSS?
- padding
- margin
- width
- All of these
Ans: 4) All of these
Explanations: In Tailwind CSS, the spacing scale applies to padding, margin, and width, as all are based on the same unit scale.
5. What is the valid value for the screens key in Tailwind CSS?
- sm
- md
- lg
- All of these
Ans: 4) All of these
Explanations: The screens key in Tailwind CSS can include values like sm, md, and lg to define responsive breakpoints for different screen sizes.
6. What is not a CSS pre-processor like Tailwind CSS?
- Sass
- Less
- Stylus
- None of the above
Ans: 4) None of the above
Explanations: Sass, Less, and Stylus are all CSS pre-processors, whereas Tailwind CSS is a utility-first CSS framework, not a pre-processor.
7. What is not a Pseudo-class in Tailwind CSS?
- The class :hover
- The class :focus
- The class :required
- None of these
Ans: 3): The class: required
Explanations: In Tailwind CSS, :hover and :focus are valid pseudo-classes for applying styles on hover and focus states, while :required is not a pseudo-class in Tailwind CSS.
8. What is the core concept behind Tailwind CSS?
- Writing custom CSS classes for each component.
- Predefined utility classes for rapid UI development.
- A grid-based layout system.
A responsive design framework.
Ans: 2): Predefined utility classes for rapid UI development.
Explanations: The Tailwind CSS provides a set of utility classes that can be directly applied to HTML elements.
9. How do you add a margin of 8 pixels to the top of an element in Tailwind CSS?
- margin-top-8
- mt-8
- top-margin-8
- Margin-top: 8px
Ans: 2): mt-8
Explanations: The Tailwind CSS uses a shorthand notation where "mt" stands for margin-top and the number indicates the size in predefined units.
10. Which of the following is a valid Tailwind CSS class for creating a centered container?
- contain
- center
- mx-auto
- align-center
Ans: 1): contain
Explanations: The "container" class creates a responsive container with a maximum width that automatically centers itself.
11. What is the purpose of the responsive design system in Tailwind CSS?
- To create different layouts for different screen sizes.
- To manage colors efficiently.
- To handle typography styles.
- To create custom components.
Ans: 1): To create different layouts for different screen sizes.
Explanations: Tailwind CSS offers utility classes with suffixes like sm, md, lg, xl, etc, to apply styles based on screen size.
12. How would you create a button with a blue background and white text in Tailwind CSS?
- <button class="bg-blue-500 text-white">Click me</button>
- <button style="background-color: blue; color: white;">Click me</button>
- <button class="button-blue">Click me</button>
- <button class="blue-button">Click me</button>
Ans: 1): <button class="bg-blue-500 text-white">Click me</button>
Explanations: bg-blue-500 sets the background color to a shade of blue, and text-white sets the text color to white.
13. Which Tailwind CSS class would you use to add padding of 4 units to all sides of an element?
- padding-4
- p-4
- all-padding-4
- padding
Ans: 2): p-4
Explanations: "p-4" is the correct Tailwind CSS class to add padding of 4 units to all sides of an element.
14. Which Tailwind CSS utility class would you use to create a vertical space of 8 units between elements?
- space-y-8
- margin-top-8
- gap-8
- spacing-y-8
Ans: 1): space-y-8
Explanations: The "space-y-8" adds a vertical space of 8 units between child elements of a flex or grid container.
15. What does the text-sm class do in Tailwind CSS?
- Sets the font size to small.
- Makes the text semi-bold.
- Adds a shadow to the text.
- Changes the text color to gray.
Ans: 1): Sets the font size to small.
Explanations: The "text-sm" sets the font size to a small size as defined in the Tailwind configuration.
16. Which Tailwind CSS class would you use to set the text color to red?
- text-red
- text-red-500
- bg-red
- color-red
Ans: 2): text-red-500
Explanations: In Tailwind CSS, the "text-red-500" sets the text color to a medium shade of red, where the 'text-colorName' is the color and the number indicates the shades.
17. What is the default breakpoint for lg in Tailwind CSS?
- 768px
- 1024px
- 1280px
- 1440px
Ans: 3): 1280px
Explanations: The lg breakpoint is set to 1280px, which is used to apply styles for large screens.
18. How can you use Tailwind CSS to hide an element on small screens but show it on medium and larger screens?
- hidden md:block
- block sm:hidden
- invisible md:visible
- none md:flex
Ans: 1): hidden md:block
Explanations: The hidden class hides the element on all screens, and the "md:block" class makes the element visible as a block on medium screens and larger.
19. What is the utility class to make text bold in Tailwind CSS?
- font-bold
- text-bold
- bold-text
- font-weight-bold
Ans: 1): font-bold
Explanations: The font-bold class applies the font-weight: bold; style to the text.
20. How can you apply a box shadow effect to an element in Tailwind CSS?
- Box-shadow-md
- Shadow-md
- Shadow-effect-md
- shadow-box-md
Ans: 2): Shadow-effect-md
Explanations: The "shadow-md" class applies a medium-sized box shadow to an element.