Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Apply mobile-first Responsive Classes in Tailwind


    In this lesson, we take a look at tailwind's mobile-first CSS architecture and learn how to apply styles to specific media queries only. We also discover a couple of ways we can define custom media queries in the config file.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: Tailwind's breakpoints are defined in the screen object in the config file. By default, you have small, medium, large, and extra large breakpoints. The properties in this object generate prefixed utility classes that target specific media queries.

    Here's an example. To apply a white color to the text on the small breakpoint, the class would be .sm then a colon followed by the utility class you want to apply. .md:text blue would apply blue text on medium and up.

    The utility classes are generated in a specific order, meaning that classes for large breakpoints will always override classes targeting smaller ones. This is a good practice of mobile-first CSS architecture.

    Here's a section with a light purple background applied globally. Let's split it on multiple lines for readability. We'll add some responsive classes. Let's target the small breakpoint and change the background to pink-light. We'll also change it on the medium breakpoint. Let's make it green. Finally, we'll make it blue on large screens.

    You can see the utility classes overriding the background color at their respective breakpoints, first pink, then green, and then blue. Pretty cool. By default, breakpoint values specify minimum widths. Anything wider than this value will be targeted.

    You can be more specific with your breakpoints. Let's create a range property here. We'll give it an object. We'll have min property of 500 pixels and a maximum width of 700 pixels. I'll quickly run Gulp to run the config file through PostCSS. Let's see if that works.

    I'll target the range breakpoint and apply the border black class as well as a border bottom level eight. Whenever we enter a mean of 500 pixels, we should see a black border on the bottom of our section. Here it is. Now, it should go away as we reach 700 pixel width. Excellent.

    You can be even more specific with your breakpoints. Say you want to pass multiple ranges. You can define an array in your property. Let's call this one skip. For the first index in this array, we'll copy our range here. The second index will be an object with a min value of 900 pixels.

    Let's recompile our config file once again. This time, we'll style the paragraph heading. At the skip media query, let's make the text in upper case characters. The upper case should be applied between 500 and 700 pixels and then again from 900 pixels and up.

    Keep an eye on our paragraph title now. As we enter the first range, it's upper case. Then back to normal. Once we reach 900 pixels, it's back to upper case.