DEV Community

suin
suin

Posted on

12 2 1 1 1

Visualize responsive breakpoint with TailwindCSS

When I was writing a responsive template using TailwindCSS, I felt that it is not easy to know which breakpoint is active.

So I made a simple component that visualizes which breakpoint is active. The following snippet is the implementation of the component:



<div class="fixed top-0 right-0 m-8 p-3 text-xs font-mono text-white h-6 w-6 rounded-full flex items-center justify-center bg-gray-700 sm:bg-pink-500 md:bg-orange-500 lg:bg-green-500 xl:bg-blue-500">
  <div class="block  sm:hidden md:hidden lg:hidden xl:hidden">al</div>
  <div class="hidden sm:block  md:hidden lg:hidden xl:hidden">sm</div>
  <div class="hidden sm:hidden md:block  lg:hidden xl:hidden">md</div>
  <div class="hidden sm:hidden md:hidden lg:block  xl:hidden">lg</div>
  <div class="hidden sm:hidden md:hidden lg:hidden xl:block">xl</div>
</div>


Enter fullscreen mode Exit fullscreen mode

Copying this and pasting to your TailwindCSS template, you will see the indicator of the breakpoint on top right in your browser.

Also, you can check the live demo at CodePen.

See the Pen Tailwind CSS Responsive Active Breakpoint Indicator by suin (@suin) on CodePen.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (4)

Collapse
 
elvarp profile image
ElvarP

updated to include 2xl support:

<div class="fixed top-0 right-0 flex items-center justify-center w-6 h-6 p-3 m-8 font-mono text-xs text-white bg-gray-700 rounded-full sm:bg-pink-500 md:bg-orange-500 lg:bg-green-500 xl:bg-blue-500 2xl:bg-purple-500">
    <div class="block sm:hidden md:hidden lg:hidden xl:hidden">al</div>
    <div class="hidden sm:block md:hidden lg:hidden xl:hidden">sm</div>
    <div class="hidden sm:hidden md:block lg:hidden xl:hidden">md</div>
    <div class="hidden sm:hidden md:hidden lg:block xl:hidden">lg</div>
    <div class="hidden sm:hidden md:hidden lg:hidden xl:block 2xl:hidden">xl</div>
    <div class="hidden sm:hidden md:hidden lg:hidden xl:hidden 2xl:block">2xl</div>
</div>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
dakira profile image
Matthias Niess • Edited

I used this so many times now. Just wanted to leave you a big thank you. It's easy to write this, but it's even easier to just google tailwind breakpoints every time I need this. :)

Collapse
 
mfatica profile image
Marco Fatica

mine shows only "al" at all sizes, do you know what's wrong?

Collapse
 
mfatica profile image
Marco Fatica

nevermind i found the answer, my page was zoomed

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay