Once I discuss layouts, I’m referring to the way you place objects on a web page. The CSS properties which can be extensively used right here embody:
show— typicallygridorflexthese daysmarginpaddingwidthpeakplacehigh,left,backside,proper
I typically embody border-width as a minor merchandise on this checklist as effectively.
At this level, there’s just one factor I’d wish to say.
Tailwind is de facto nice for making layouts.
There are various the reason why.
First: Structure kinds are extremely depending on the HTML construction
After we shift layouts into CSS, we lose the psychological construction and it takes effort to re-establish them. Think about the next three-column grid in HTML and CSS:
.grid {
show: grid;
grid-template-columns: 2fr 1fr;
.grid-item:first-child {
grid-column: span 2
}
.grid-item:last-child {
grid-column: span 1
}
}

Now cowl the HTML construction and simply learn the CSS. As you do this, discover it's essential to exert effort to think about the HTML construction that this is applicable to.
Now think about the identical, however constructed with Tailwind utilities:
You may virtually start to see the structure manifest in your eyes with out seeing the precise output. It’s fairly clear: A 3-column grid, first merchandise spans two columns whereas the second spans one column.
However grid-cols-3 and col-span-2 are kinda bizarre and foreign-looking as a result of we’re attempting to parse Tailwind’s methodology of writing CSS.
Now, watch what occurs once we shift the syntax out of the best way and use CSS variables to outline the structure as an alternative. The structure turns into crystal clear instantly:

Identical three-column structure.
Nevertheless it makes the structure a lot simpler to jot down, learn, and visualize. It additionally has different advantages, however I’ll allow you to discover its documentation as an alternative of explaining it right here.
For now, let’s transfer on.
Why not use 2fr 1fr?
It is sensible to jot down 2fr 1fr for a three-column grid, doesn’t it?
.grid {
show: grid;
grid-template-columns: 2fr 1fr;
}
Sadly, it received’t work. It's because fr is calculated based mostly on the accessible house after subtracting away the grid’s gutters (or hole).
Since 2fr 1fr solely accommodates two columns, the output from 2fr 1fr will likely be completely different from a typical three-column grid.

Alright. Let’s proceed with the explanations that make Tailwind nice for constructing layouts.
Second: No want to call layouts
I feel layouts are the toughest issues to call. I not often provide you with higher names than:
- Quantity + Columns, e.g.
.two-columns - Semantic names, e.g.
.content-sidebar
However these names don’t do the structure justice. You possibly can’t actually inform what’s occurring, even when you see .two-columns, as a result of .two-columns can imply a wide range of issues:
- Two equal columns
- Two columns with
1fr auto - Two columns with
auto 1fr - Two columns that spans whole of seven “columns” and the primary object takes up 4 columns whereas the second takes up 3…
You possibly can already see me tripping up when I attempt to clarify that final one there…
As a substitute of forcing ourselves to call the structure, we will let the numbers do the speaking — then the entire construction turns into very clear.
The variables paint an image.

Third: Structure necessities can change relying on context
A “two-column” structure may need completely different properties when utilized in completely different contexts. Right here’s an instance.

On this instance, you may see that:
- A bigger
holeis used between the I and J teams. - A smaller
holeis used inside the I and J teams.
The distinction in hole sizes is refined, however used to point out that the objects are of separate teams.
Right here’s an instance the place this idea is utilized in an actual mission. You possibly can see the distinction between the hole used inside the publication container and the hole used between the publication and quote containers.

If this form of structure is simply utilized in one place, we don’t need to create a modifier class simply to alter the hole worth. We are able to change it straight.
One other widespread instance
Let’s say you could have a heading for a advertising part. The heading would look nicer if you'll be able to fluctuate its max-width so the textual content isn’t orphaned.
text-balance may work right here, however that is typically nicer with guide positioning.
With out Tailwind, you may write an inline model for it.
Your subscription has been confirmed
With Tailwind, you may specify the max-width in a extra terse approach:
Your subscription has been confirmed

Fourth: Responsive variants could be created on the fly
“At which breakpoint would you modify your layouts?” is one other issue you’d wish to take into account when designing your layouts. I shall time period this the responsive issue for this part.
Most definitely, comparable layouts ought to have the identical responsive issue. In that case, it is sensible to group the layouts collectively right into a named structure.
.two-column {
@apply grid-simple;
/* --cols: 1 is the default */
@media (width >= 800px) {
--cols:2;
}
}
Nevertheless, you might have layouts the place you need two-column grids on a cell and a a lot bigger column rely on tablets and desktops. This structure model is often utilized in a website footer part.
For the reason that footer grid is exclusive, we will add Tailwind’s responsive variants and alter the structure on the fly.

Once more, we get to create a brand new structure on the fly with out creating a further modifier class — this retains our CSS clear and centered.
finest use Tailwind
This text is a pattern lesson from my course, Unorthodox Tailwind, the place I present you the way to use Tailwind and CSS synergistically.
Personally, I feel one of the simplest ways to make use of Tailwind is to not litter your HTML with Tailwind utilities, however to create utilities that allow you to create layouts and kinds simply.
I cowl way more of that within the course when you’re to search out out extra!









