The class hidden md:block hides the element by default (small screens) and shows it starting at medium screens.
Other options either hide on medium or show on small incorrectly.
<div class="flex flex-col md:flex-row"> <div class="block md:hidden">A</div> <div class="hidden md:block">B</div> </div>
What will be visible on a large screen (≥ md)?
On large screens, md:flex-row arranges children horizontally.
block md:hidden hides A on medium and up, so A is hidden.
hidden md:block shows B on medium and up, so B is visible.
<button class="bg-blue-500 text-white p-4 hidden sm:inline-block">Click Me</button>
What will the user see on a small screen (less than 640px wide)?
hidden and sm:inline-block classes and when they apply.The hidden class hides the button by default.
The sm:inline-block class makes it visible starting at small screens (≥640px).
On smaller than 640px, the button remains hidden.
sr-only hides content visually but keeps it accessible to screen readers.
sm:not-sr-only makes it visible visually on small and larger screens.
Other options hide content visually but also remove accessibility or keep layout space.
hidden md:block preferred over block md:hidden for responsive visibility?1. hidden md:block 2. block md:hidden
Why is the first pattern generally better for responsive visibility toggling?
Using hidden md:block hides content by default (small screens) and shows it on medium and larger screens.
This approach avoids rendering unnecessary content on small devices, improving performance and accessibility.
The other pattern shows content by default and hides it later, which can cause layout shifts and accessibility issues.