Explore how dark mode and custom theming are implemented using Tailwind CSS utilities and strategies. This quiz helps you understand configuration, class usage, and best practices for accessible and flexible theming solutions.
Which configuration key must be set in the Tailwind CSS configuration file to enable dark mode classes using a class-based strategy?
Explanation: The correct way to activate dark mode with a class-based strategy is by using the darkMode: 'class' configuration option. Setting enableDark: true, mode: 'dark', or themeDark: 'enable' are not valid options and will not activate dark mode functionality. Only the first option matches Tailwind syntax for enabling dark mode via a class.
How do you apply a background color that changes to gray-800 only when dark mode is active, using Tailwind utility classes?
Explanation: The correct answer is bg-white dark:bg-gray-800, as the dark: prefix indicates the utility should only apply when dark mode is active. Options like bg-dark-gray-800 and bg-white bg-dark-gray-800 are not valid utility classes. The order and prefix usage in the third and fourth options do not follow Tailwind's convention.
Which section in the Tailwind CSS configuration file should you modify to define custom color palettes for your theme?
Explanation: To create custom color palettes, you should modify the colors object under the theme key in the configuration file. The distractors (custom, options, or settings) do not correspond to valid keys in Tailwind's config. Only the first option matches the expected structure, allowing for proper theming.
Why is it important to consider contrast ratios when defining dark mode color schemes for text and backgrounds?
Explanation: Contrast ratios are essential in dark mode to make sure text remains readable and accessible, ensuring compliance with accessibility standards. Creating gradients, syncing device settings, or reducing file size are not directly related to contrast ratio considerations. These other options address visual style, user preferences, or performance, not accessibility.
Which method allows you to toggle between light and dark themes on a website when darkMode is set to 'class' in the configuration?
Explanation: With darkMode set to 'class', toggling between themes is achieved by adding or removing the 'dark' class from a containing element, usually HTML or body. The second option is not a valid Tailwind utility. Using media queries works for 'media' mode, not 'class' mode. The fourth option does not have an effect in this context.