<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Morteza Darzi</title>
    <description>The latest articles on DEV Community by Morteza Darzi (@githubmor).</description>
    <link>https://dev.to/githubmor</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F972436%2Fc9ca5478-e4aa-452f-a327-3fdcae3f9859.jpg</url>
      <title>DEV Community: Morteza Darzi</title>
      <link>https://dev.to/githubmor</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/githubmor"/>
    <language>en</language>
    <item>
      <title>What the Heck Are @layer in Tailwind? (And How I Finally Got It)</title>
      <dc:creator>Morteza Darzi</dc:creator>
      <pubDate>Tue, 13 May 2025 04:01:06 +0000</pubDate>
      <link>https://dev.to/githubmor/what-the-heck-are-layer-in-tailwind-and-how-i-finally-got-it-380j</link>
      <guid>https://dev.to/githubmor/what-the-heck-are-layer-in-tailwind-and-how-i-finally-got-it-380j</guid>
      <description>&lt;p&gt;At first, I didn’t really understand what the purpose of the layers in Tailwind’s CSS system was. I saw @layer base, @layer components, and @layer utilities in examples and documentation, but I didn’t know when or why to use them, or what would happen if I ignored them completely. I was just adding my custom CSS and utility classes to the app.css file without structure, and it seemed to work—until I started running into problems with class conflicts, ordering issues, and styles not applying consistently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the Purpose of Layers&lt;/strong&gt;&lt;br&gt;
After some deep searching and asking ChatGPT for clarity, I finally understood the concept of Tailwind's CSS layering system. It’s not just about organizing code—it has a real technical impact on how styles are interpreted and prioritized during the build process. Tailwind internally uses PostCSS, and these @layer directives are essential to ensure that custom styles merge correctly with Tailwind’s own layers, without being purged or overridden unexpectedly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Goes in Each Layer&lt;/strong&gt;&lt;br&gt;
The @layer base section is where you should define low-level, element-based styles—things like default typography, custom fonts, or resetting browser styles. These are similar to global HTML element rules (like body, h1, a, etc.), and they should feel like the foundation of your design system. Technically, putting your base styles here ensures Tailwind knows they're part of the base layer and avoids conflicting with component or utility layers.&lt;/p&gt;

&lt;p&gt;Then there’s @layer components, which is the perfect place for your custom reusable class-based styles—like buttons, input fields, form groups, cards, badges, and so on. These aren’t global resets; they’re building blocks made up of utility classes. The key technical benefit here is that they are injected in the right order relative to Tailwind’s own components and utilities, and they’re also preserved during purging, because Tailwind knows to expect them.&lt;/p&gt;

&lt;p&gt;Lastly, there’s @layer utilities, where you can define your own utility classes—small, single-purpose classes like .text-shadow or .scrollbar-hide that you use similarly to Tailwind's built-in utilities. Again, this ensures these classes are injected after components and that the cascade order respects Tailwind’s utility-first principles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why It Matters&lt;/strong&gt;&lt;br&gt;
What I also learned is that writing CSS outside of any @layer block can still technically work, but it breaks Tailwind’s layering system. If you define a .btn style outside of @layer components, it might get purged during production builds, or worse, get overridden by utility styles later in the cascade. So it’s not just about being organized—it’s about making sure your styles are safe, consistent, and predictable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Technical Gotchas to Watch Out For&lt;/strong&gt;&lt;br&gt;
There are also some technical rules to watch out for. For example, never use &lt;a class="mentioned-user" href="https://dev.to/apply"&gt;@apply&lt;/a&gt; on classes that you didn’t register through a layer—especially inside utilities—because it could lead to circular references or broken builds. And be careful with overriding HTML element tags like p, h1, or body in the wrong layer—they belong in base, and doing otherwise can result in unexpected behavior.&lt;/p&gt;

&lt;p&gt;After learning all this, I went back and reorganized my app.css file. I moved all font-face definitions and HTML element styling into @layer base, grouped my custom UI component classes into @layer components, and separated out utility-style helpers like .scrollbar-hide or .tes into @layer utilities. Now my styles load in the right order, nothing gets purged, and it’s much easier to maintain and understand the file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Thoughts&lt;/strong&gt;&lt;br&gt;
In short, mastering Tailwind’s layering system in your CSS file is the key to making your custom styles work harmoniously with Tailwind’s utility-first engine. It’s not just syntax—it’s structure, safety, and sanity for your project.&lt;/p&gt;

</description>
      <category>tailwindcss</category>
      <category>css</category>
      <category>react</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Why You Should Use Only One &lt;caption&gt; in React Tables (and How to Add a Footer)</title>
      <dc:creator>Morteza Darzi</dc:creator>
      <pubDate>Sat, 03 May 2025 05:16:59 +0000</pubDate>
      <link>https://dev.to/githubmor/why-you-should-use-only-one-in-react-tables-and-how-to-add-a-footer-111m</link>
      <guid>https://dev.to/githubmor/why-you-should-use-only-one-in-react-tables-and-how-to-add-a-footer-111m</guid>
      <description>&lt;p&gt;When working with tables in React (or plain HTML), you might run into a situation where you want to display two captions: one at the top and another at the bottom. I recently faced this exact problem in my React app. Here’s what I discovered, why it happens, and how to solve it in a way that works across all browsers.&lt;/p&gt;

&lt;p&gt;🚩 The Problem: Multiple &lt;/p&gt; Elements Don’t Work Consistently&lt;br&gt;
According to the HTML specification, a &lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt; must have at most one , and it must be the first child of the &lt;table&gt; element. If you try to add more than one , or place a  anywhere except as the first child, browser behavior becomes unpredictable:

&lt;p&gt;Chrome: Sometimes renders both captions, even if the second is after the &lt;/p&gt;
&lt;tbody&gt;.

&lt;p&gt;Firefox: Only renders the first &lt;/p&gt;, and ignores any others, or those not in the correct position.

&lt;p&gt;This means your table might look fine in Chrome, but the second caption will be missing in Firefox. This is because each browser implements the HTML spec in its own way, and only the first &lt;/p&gt; (as the first child) is guaranteed to be shown everywhere.

&lt;p&gt;🧑‍💻 My Experience&lt;br&gt;
While building a React table, I tried to add a second &lt;/p&gt; at the bottom for extra context. It worked in Chrome, but when I checked in Firefox, the second caption was simply not rendered. Even moving the second  below the &lt;/tbody&gt;
&lt;tbody&gt; inside the &lt;table&gt; didn’t help-Firefox still ignored it. That’s when I realized this is a cross-browser issue, not a bug in my code.

&lt;p&gt;✅ The Solution: Use One &lt;/p&gt; + Custom Footer&lt;br&gt;
If you want a second caption or footer, don’t use a second . Instead, use a single semantic  for accessibility, and render any additional content outside the table, styled as needed (especially easy with Tailwind CSS).

&lt;p&gt;Here’s How You Can Do It in React + Tailwind:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function MyTable({ data, footer }) {
  return (
    &amp;lt;div className="overflow-x-auto"&amp;gt;
      &amp;lt;table className="min-w-full border border-gray-300"&amp;gt;
        {/* Top Caption (semantic, accessible) */}
        &amp;lt;caption className="caption-top text-lg font-semibold mb-2"&amp;gt;
          Main Table Caption
        &amp;lt;/caption&amp;gt;
        &amp;lt;thead&amp;gt;
          &amp;lt;tr&amp;gt;
            &amp;lt;th className="border-b px-4 py-2"&amp;gt;Header 1&amp;lt;/th&amp;gt;
            &amp;lt;th className="border-b px-4 py-2"&amp;gt;Header 2&amp;lt;/th&amp;gt;
          &amp;lt;/tr&amp;gt;
        &amp;lt;/thead&amp;gt;
        &amp;lt;tbody&amp;gt;
          {data.map((row, i) =&amp;gt; (
            &amp;lt;tr key={i}&amp;gt;
              &amp;lt;td className="border-b px-4 py-2"&amp;gt;{row.col1}&amp;lt;/td&amp;gt;
              &amp;lt;td className="border-b px-4 py-2"&amp;gt;{row.col2}&amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
          ))}
        &amp;lt;/tbody&amp;gt;
      &amp;lt;/table&amp;gt;
      {/* Custom Footer or "Second Caption" */}
      &amp;lt;div className="mt-2 text-center text-gray-600"&amp;gt;{footer}&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;This approach guarantees your table is accessible and looks consistent in all browsers. You can pass any ReactNode as the footer, giving you full flexibility for content and styling.&lt;/p&gt;

&lt;p&gt;📚 References&lt;br&gt;
MDN Web Docs: &lt;/p&gt; element – Official documentation on correct usage and limitations of the  tag.

&lt;p&gt;Working With Tables in React: How to Render and Edit Fetched Data (dev.to) – A practical overview of rendering tables in React, including best practices for structure and accessibility.&lt;/p&gt;

&lt;p&gt;💡 Takeaway&lt;br&gt;
Always use only one &lt;/p&gt; as the first child of your table.

&lt;p&gt;For extra captions/footers, use a custom element outside the table.&lt;/p&gt;

&lt;p&gt;Don’t trust browser quirks-write code that’s consistent and accessible everywhere.&lt;/p&gt;

&lt;p&gt;Let me know if you’ve run into similar cross-browser issues, or if you have other table best practices to share!&lt;/p&gt;


&lt;/table&gt;
&lt;br&gt;
&lt;/tbody&gt;
&lt;br&gt;
&lt;/table&gt;
&lt;br&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>html</category>
      <category>a11y</category>
      <category>frontend</category>
      <category>react</category>
    </item>
  </channel>
</rss>
