DEV Community

Cover image for You Don't Need The Flex
James 'Dante' Midzi
James 'Dante' Midzi

Posted on

1 1

You Don't Need The Flex

I find it very amusing that this is going to be my first post of the year. But it has bothered me enough that I must speak about it.

No one can deny the godsend that tailwind has been. We are able to prototype faster and get things done quickly.

I have noticed in the upsurge of Tailwind, has come with a forgetting and overlooking of some properties inherent in CSS and HTML.


Block and Inline Elements

Yes, I am afraid we have to go there...

Block-Level Element

I actually fail to understand how people forgot about the block element aspect of HTML. I see someone doing this:

<div class="flex flex-col">
    <p>One</p>
    <p>Two</p>
    <p>Three</p>
</div>
Enter fullscreen mode Exit fullscreen mode

And all they wanted to do was have elements one after each other - stack them. They already do that! That is what HTML inherently does.

Block-level elements always start a new line.

Yes, of course I understand there are certain instances where you want your element to only take up as little space as possible - what flex does - but paying attention to what they have done, that is rarely the case.

Have a gander a some block elements

<div>    <p>    <main>    <section>    <header>    <nav>    <h1>-<h6>
Enter fullscreen mode Exit fullscreen mode

To quote something Kevin Powell said (I am paraphrasing):

"Don't undo the styling and then end up redoing it again. Use the HTML to your advantage"

Inline-Level Element

For posterity, it is only right I talk about inline elements as well. In HTML, there are certain elements that are not block. These elements only take up as much width as necessary. As such you can place them side by side - they do not naturally stack.

Some inline elements you are familiar with:

<a>    <img>    <input>    <span>    <button>
Enter fullscreen mode Exit fullscreen mode

Wrapping Up

So next time you are trying to stack elements, don't just rush to add flex. Put your elements on the page and see if they stack as you want. Unhand the flex and think about what you want your resulting outcome to be.

And if what I said, doesn't make sense, here is a link to w3schools with examples you can play around with.


Thank you for reading, let's connect!

Thank you for visiting this little corner of mine. Let's connect on Twitter, Discord and LinkedIn

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay