{"id":31585,"date":"2025-01-21T16:48:00","date_gmt":"2025-01-21T15:48:00","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=31585"},"modified":"2025-01-30T11:03:38","modified_gmt":"2025-01-30T10:03:38","slug":"building-agnostic-components-with-cva-and-tailwinddesign-ux","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/","title":{"rendered":"Building Agnostic Components with CVA and TailwindDesign\/UX"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p><strong>Is Tailwind great? Yes. But does it have any weak points?<\/strong><\/p>\n\n\n\n<p>Using Tailwind offers numerous advantages:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Speeds up development:<\/strong> It keeps content and presentation layers close, avoids the cognitive load of naming classes, and nearly eliminates style collisions.<\/li>\n\n\n\n<li><strong>Enhances consistency:<\/strong> Through the use of tokens.<\/li>\n\n\n\n<li><strong>Produces small CSS files:<\/strong> By extracting only the classes you use.<\/li>\n<\/ul>\n\n\n\n<p>However, it has a clear downside compared to traditional CSS approaches: code repetition. To mitigate this, Tailwind&#8217;s documentation suggests using components wherever possible.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p><strong>Another drawback: lost semantics<\/strong><br>For instance, applying the class <code>btn--lg<\/code> to an element implies using a &#8220;large&#8221; variant. However, using classes like <code>px-6 py-4 text-lg<\/code> loses this context.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p><strong>How to solve this with React?<\/strong><\/p>\n\n\n\n<p>One way to address this at the UI library level (e.g., in React) is to create a <code>Button<\/code> component that accepts variants as props and maps those props to Tailwind classes.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">&lt;code&gt;<span class=\"hljs-keyword\">import<\/span> type { ReactNode } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'react'<\/span>;\n\n<span class=\"hljs-keyword\">const<\/span> sizeStyles = {\n  <span class=\"hljs-attr\">sm<\/span>: <span class=\"hljs-string\">'px-3 py-1 text-sm'<\/span>,\n  <span class=\"hljs-attr\">md<\/span>: <span class=\"hljs-string\">'px-4 py-2 text-base'<\/span>,\n  <span class=\"hljs-attr\">lg<\/span>: <span class=\"hljs-string\">'px-6 py-4 text-lg'<\/span>,\n};\n\n<span class=\"hljs-keyword\">const<\/span> intentStyles = {\n  <span class=\"hljs-attr\">primary<\/span>: <span class=\"hljs-string\">'bg-blue-600 text-blue-50'<\/span>,\n  <span class=\"hljs-attr\">secondary<\/span>: <span class=\"hljs-string\">'bg-orange-600 text-orange-50'<\/span>,\n  <span class=\"hljs-attr\">default<\/span>: <span class=\"hljs-string\">'text-slate-600 text-slate-50'<\/span>,\n};\n\ninterface Props {\n  <span class=\"hljs-attr\">size<\/span>: keyof <span class=\"hljs-keyword\">typeof<\/span> sizeStyles;\n  intent: keyof <span class=\"hljs-keyword\">typeof<\/span> intentStyles;\n  children: ReactNode;\n}\n\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">const<\/span> Button = <span class=\"hljs-function\">(<span class=\"hljs-params\">{ size, intent, children }<\/span>) =&gt;<\/span> (\n  <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">button<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">{<\/span>`<span class=\"hljs-attr\">inline-block<\/span> <span class=\"hljs-attr\">border-0<\/span> ${<span class=\"hljs-attr\">sizeStyles<\/span>&#91;<span class=\"hljs-attr\">size<\/span>]} ${<span class=\"hljs-attr\">intentStyles<\/span>&#91;<span class=\"hljs-attr\">intent<\/span>]}`}&gt;<\/span>\n    {children}\n  <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">button<\/span>&gt;<\/span><\/span>\n);\n&lt;<span class=\"hljs-regexp\">\/code&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p><strong>Advantages of this approach:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Reduces repetitive Tailwind classes:<\/strong> No need to write the same classes repeatedly for buttons.<\/li>\n\n\n\n<li><strong>Improves clarity:<\/strong> You don&#8217;t have to remember that <code>primary<\/code> equals <code>bg-blue-600 text-blue-50<\/code>.<\/li>\n\n\n\n<li><strong>Centralizes styles:<\/strong> Updating styles is straightforward without needing to navigate multiple files.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<p><strong>But is this the final solution? Not quite.<\/strong><\/p>\n\n\n\n<p>This component has some limitations:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It doesn\u2019t allow passing an <code>onClick<\/code> event or other native props.<\/li>\n\n\n\n<li>It can\u2019t handle additional classes passed via <code>className<\/code> without overwriting its internal styles.<\/li>\n\n\n\n<li>It doesn\u2019t support working with refs (e.g., for focusing on the button imperatively).<\/li>\n\n\n\n<li>It\u2019s not polymorphic\u2014you can\u2019t render other elements (like <code>&lt;a&gt;<\/code> or <code>&lt;div&gt;<\/code>) with the same styles.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-optimizing-the-code\"><strong>Optimizing the Code<\/strong><\/h3>\n\n\n\n<p>The minimal code required to centralize button styles, keep semantic usage, and avoid duplication is:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">&lt;code&gt;<span class=\"hljs-keyword\">const<\/span> sizeStyles = {\n  <span class=\"hljs-attr\">sm<\/span>: <span class=\"hljs-string\">'px-3 py-1 text-sm'<\/span>,\n  <span class=\"hljs-attr\">md<\/span>: <span class=\"hljs-string\">'px-4 py-2 text-base'<\/span>,\n  <span class=\"hljs-attr\">lg<\/span>: <span class=\"hljs-string\">'px-6 py-4 text-lg'<\/span>,\n};\n\n<span class=\"hljs-keyword\">const<\/span> intentStyles = {\n  <span class=\"hljs-attr\">primary<\/span>: <span class=\"hljs-string\">'bg-blue-600 text-blue-50'<\/span>,\n  <span class=\"hljs-attr\">secondary<\/span>: <span class=\"hljs-string\">'bg-orange-600 text-orange-50'<\/span>,\n  <span class=\"hljs-attr\">default<\/span>: <span class=\"hljs-string\">'text-slate-600 text-slate-50'<\/span>,\n};\n\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">const<\/span> button = <span class=\"hljs-function\">(<span class=\"hljs-params\">{ size, intent }: { size: keyof <span class=\"hljs-keyword\">typeof<\/span> sizeStyles; intent: keyof <span class=\"hljs-keyword\">typeof<\/span> intentStyles }<\/span>) =&gt;<\/span>\n  <span class=\"hljs-string\">`inline-block border-0 <span class=\"hljs-subst\">${sizeStyles&#91;size]}<\/span> <span class=\"hljs-subst\">${intentStyles&#91;intent]}<\/span>`<\/span>;\n&lt;<span class=\"hljs-regexp\">\/code&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To use it:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">code<\/span>&gt;<\/span>className={button({ intent: 'primary', size: 'lg' })}\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">code<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>This approach avoids prop-drilling issues, is framework-agnostic, and can work in Vue, Svelte, or any framework.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-accelerating-development-with-cva\"><strong>Accelerating Development with CVA<\/strong><\/h3>\n\n\n\n<p>CVA (<em>class-variance-authority<\/em>) is a JavaScript library for building CSS components based on variants. Here\u2019s how you can use it to solve the button example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">&lt;code&gt;<span class=\"hljs-keyword\">import<\/span> { cva } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'class-variance-authority'<\/span>;\n\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">const<\/span> button = cva(<span class=\"hljs-string\">'inline-block border-0'<\/span>, {\n  <span class=\"hljs-attr\">variants<\/span>: {\n    <span class=\"hljs-attr\">size<\/span>: {\n      <span class=\"hljs-attr\">sm<\/span>: <span class=\"hljs-string\">'px-3 py-1 text-sm'<\/span>,\n      <span class=\"hljs-attr\">md<\/span>: <span class=\"hljs-string\">'px-4 py-2 text-base'<\/span>,\n      <span class=\"hljs-attr\">lg<\/span>: <span class=\"hljs-string\">'px-6 py-4 text-lg'<\/span>,\n    },\n    <span class=\"hljs-attr\">intent<\/span>: {\n      <span class=\"hljs-attr\">primary<\/span>: <span class=\"hljs-string\">'bg-blue-600 text-blue-50'<\/span>,\n      <span class=\"hljs-attr\">secondary<\/span>: <span class=\"hljs-string\">'bg-orange-600 text-orange-50'<\/span>,\n      <span class=\"hljs-attr\">default<\/span>: <span class=\"hljs-string\">'text-slate-600 text-slate-50'<\/span>,\n    },\n  },\n});\n&lt;<span class=\"hljs-regexp\">\/code&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To invoke:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">code<\/span>&gt;<\/span>className={button({ intent: 'primary', size: 'lg' })}\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">code<\/span>&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-extending-component-classes\"><strong>Extending Component Classes<\/strong><\/h3>\n\n\n\n<p>To add additional classes to the component, use the <code>class<\/code> property (or <code>className<\/code> for React):<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">&lt;code&gt;className={button({\n  <span class=\"hljs-attr\">intent<\/span>: <span class=\"hljs-string\">'primary'<\/span>,\n  <span class=\"hljs-attr\">size<\/span>: <span class=\"hljs-string\">'lg'<\/span>,\n  <span class=\"hljs-attr\">class<\/span>: <span class=\"hljs-string\">'text-blue-600'<\/span>,\n})}\n&lt;<span class=\"hljs-regexp\">\/code&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-extracting-types\"><strong>Extracting Types<\/strong><\/h3>\n\n\n\n<p>You can extract types for component variants using <code>VariantProps<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">&lt;code&gt;<span class=\"hljs-keyword\">import<\/span> type { VariantProps } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'class-variance-authority'<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { cva } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'class-variance-authority'<\/span>;\n\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">const<\/span> button = cva(<span class=\"hljs-comment\">\/* ... *\/<\/span>);\n\n<span class=\"hljs-keyword\">export<\/span> type ButtonProps = VariantProps&lt;<span class=\"hljs-keyword\">typeof<\/span> button&gt;;\n&lt;<span class=\"hljs-regexp\">\/code&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-default-variants\"><strong>Default Variants<\/strong><\/h3>\n\n\n\n<p>Set default variants with <code>defaultVariants<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">&lt;code&gt;<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">const<\/span> button = cva(<span class=\"hljs-string\">'inline-block border-0'<\/span>, {\n  <span class=\"hljs-attr\">variants<\/span>: {\n    <span class=\"hljs-attr\">size<\/span>: { <span class=\"hljs-attr\">sm<\/span>: <span class=\"hljs-string\">'px-3 py-1 text-sm'<\/span>, <span class=\"hljs-attr\">md<\/span>: <span class=\"hljs-string\">'px-4 py-2 text-base'<\/span>, <span class=\"hljs-attr\">lg<\/span>: <span class=\"hljs-string\">'px-6 py-4 text-lg'<\/span> },\n    <span class=\"hljs-attr\">intent<\/span>: { <span class=\"hljs-attr\">primary<\/span>: <span class=\"hljs-string\">'bg-blue-600 text-blue-50'<\/span>, <span class=\"hljs-attr\">secondary<\/span>: <span class=\"hljs-string\">'bg-orange-600 text-orange-50'<\/span>, <span class=\"hljs-attr\">default<\/span>: <span class=\"hljs-string\">'text-slate-600 text-slate-50'<\/span> },\n  },\n  <span class=\"hljs-attr\">defaultVariants<\/span>: { <span class=\"hljs-attr\">size<\/span>: <span class=\"hljs-string\">'md'<\/span>, <span class=\"hljs-attr\">intent<\/span>: <span class=\"hljs-string\">'default'<\/span> },\n});\n&lt;<span class=\"hljs-regexp\">\/code&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-compound-variants\"><strong>Compound Variants<\/strong><\/h3>\n\n\n\n<p>To define styles for multiple conditions:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">&lt;code&gt;<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">const<\/span> button = cva(<span class=\"hljs-string\">'inline-block border-0'<\/span>, {\n  <span class=\"hljs-attr\">variants<\/span>: {\n    <span class=\"hljs-attr\">size<\/span>: { <span class=\"hljs-attr\">sm<\/span>: <span class=\"hljs-string\">'px-3 py-1 text-sm border'<\/span>, <span class=\"hljs-attr\">md<\/span>: <span class=\"hljs-string\">'px-4 py-2 text-base border-2'<\/span>, <span class=\"hljs-attr\">lg<\/span>: <span class=\"hljs-string\">'px-6 py-4 text-lg border-4'<\/span> },\n    <span class=\"hljs-attr\">outline<\/span>: { <span class=\"hljs-attr\">false<\/span>: <span class=\"hljs-string\">'border-transparent'<\/span>, <span class=\"hljs-attr\">true<\/span>: <span class=\"hljs-literal\">null<\/span> },\n    <span class=\"hljs-attr\">intent<\/span>: { <span class=\"hljs-attr\">primary<\/span>: <span class=\"hljs-literal\">null<\/span>, <span class=\"hljs-attr\">secondary<\/span>: <span class=\"hljs-literal\">null<\/span>, <span class=\"hljs-attr\">default<\/span>: <span class=\"hljs-literal\">null<\/span> },\n  },\n  <span class=\"hljs-attr\">compoundVariants<\/span>: &#91;\n    { <span class=\"hljs-attr\">intent<\/span>: <span class=\"hljs-string\">'primary'<\/span>, <span class=\"hljs-attr\">outline<\/span>: <span class=\"hljs-literal\">false<\/span>, <span class=\"hljs-attr\">class<\/span>: <span class=\"hljs-string\">'bg-blue-600 text-blue-50'<\/span> },\n    { <span class=\"hljs-attr\">intent<\/span>: <span class=\"hljs-string\">'primary'<\/span>, <span class=\"hljs-attr\">outline<\/span>: <span class=\"hljs-literal\">true<\/span>, <span class=\"hljs-attr\">class<\/span>: <span class=\"hljs-string\">'bg-blue-50 text-blue-600 border-blue-600'<\/span> },\n  ],\n  <span class=\"hljs-attr\">defaultVariants<\/span>: { <span class=\"hljs-attr\">size<\/span>: <span class=\"hljs-string\">'md'<\/span>, <span class=\"hljs-attr\">intent<\/span>: <span class=\"hljs-string\">'default'<\/span>, <span class=\"hljs-attr\">outline<\/span>: <span class=\"hljs-literal\">false<\/span> },\n});\n&lt;<span class=\"hljs-regexp\">\/code&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-avoiding-class-collisions-with-tailwind-merge\"><strong>Avoiding Class Collisions with Tailwind Merge<\/strong><\/h3>\n\n\n\n<p>Use <code>tailwind-merge<\/code> to resolve class conflicts:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">&lt;code&gt;<span class=\"hljs-keyword\">import<\/span> { twMerge } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'tailwind-merge'<\/span>;\n\ntwMerge(<span class=\"hljs-string\">'p-3'<\/span>, <span class=\"hljs-string\">'p-4'<\/span>); <span class=\"hljs-comment\">\/\/ Output: p-4<\/span>\ntwMerge(<span class=\"hljs-string\">'block'<\/span>, <span class=\"hljs-string\">'flex'<\/span>); <span class=\"hljs-comment\">\/\/ Output: flex<\/span>\ntwMerge(<span class=\"hljs-string\">'p-3 hover:p-4'<\/span>, <span class=\"hljs-string\">'p-2'<\/span>); <span class=\"hljs-comment\">\/\/ Output: p-2 hover:p-4<\/span>\n&lt;<span class=\"hljs-regexp\">\/code&gt;<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\" \/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-conclusion\"><strong>Conclusion<\/strong><\/h3>\n\n\n\n<p>Building a UI component that meets functional requirements is not trivial, especially for purely presentational components. In such cases, <strong>CVA offers a practical and efficient alternative<\/strong>, with the added benefit of being framework-agnostic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Is Tailwind great? Yes. But does it have any weak points? Using Tailwind offers numerous advantages: However, it has a clear downside compared to traditional CSS approaches: code repetition. To mitigate this, Tailwind&#8217;s documentation suggests using components wherever possible. Another drawback: lost semanticsFor instance, applying the class btn&#8211;lg to an element implies using a &#8220;large&#8221;&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/\">Read more<\/a><\/p>\n","protected":false},"author":254,"featured_media":28361,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[76],"tags":[4209,66,12281],"collections":[],"class_list":{"0":"post-31585","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-design-ux","8":"tag-careers","9":"tag-css","10":"tag-tailwind","11":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Building Agnostic Components with CVA and TailwindDesign\/UX - Codemotion Magazine<\/title>\n<meta name=\"description\" content=\"Discover how to create reusable and efficient components using CVA and Tailwind CSS. Optimize your projects now!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building Agnostic Components with CVA and TailwindDesign\/UX\" \/>\n<meta property=\"og:description\" content=\"Discover how to create reusable and efficient components using CVA and Tailwind CSS. Optimize your projects now!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-01-21T15:48:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-01-30T10:03:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1792\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"jmlweb\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"jmlweb\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/\"},\"author\":{\"name\":\"jmlweb\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/b38417c0c79c66c436a78f8b207c514a\"},\"headline\":\"Building Agnostic Components with CVA and TailwindDesign\/UX\",\"datePublished\":\"2025-01-21T15:48:00+00:00\",\"dateModified\":\"2025-01-30T10:03:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/\"},\"wordCount\":408,\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp\",\"keywords\":[\"Careers\",\"CSS\",\"Tailwind\"],\"articleSection\":[\"Design\/UX\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/\",\"name\":\"Building Agnostic Components with CVA and TailwindDesign\/UX - Codemotion Magazine\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp\",\"datePublished\":\"2025-01-21T15:48:00+00:00\",\"dateModified\":\"2025-01-30T10:03:38+00:00\",\"description\":\"Discover how to create reusable and efficient components using CVA and Tailwind CSS. Optimize your projects now!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#primaryimage\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp\",\"width\":1792,\"height\":1024,\"caption\":\"css repos\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Frontend\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Design\/UX\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Building Agnostic Components with CVA and TailwindDesign\/UX\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Codemotion.Italy\/\",\"https:\/\/x.com\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/b38417c0c79c66c436a78f8b207c514a\",\"name\":\"jmlweb\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e9b818c4bcbc06b196d66cea92d9fe41bd5ccd255dd3943745cd801eff3f96db?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e9b818c4bcbc06b196d66cea92d9fe41bd5ccd255dd3943745cd801eff3f96db?s=96&d=mm&r=g\",\"caption\":\"jmlweb\"},\"description\":\"Frontend Solutions Architect @ Freepik\",\"sameAs\":[\"https:\/\/jmlweb.es\"],\"url\":\"https:\/\/www.codemotion.com\/magazine\/author\/jmlweb\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Building Agnostic Components with CVA and TailwindDesign\/UX - Codemotion Magazine","description":"Discover how to create reusable and efficient components using CVA and Tailwind CSS. Optimize your projects now!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/","og_locale":"en_US","og_type":"article","og_title":"Building Agnostic Components with CVA and TailwindDesign\/UX","og_description":"Discover how to create reusable and efficient components using CVA and Tailwind CSS. Optimize your projects now!","og_url":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2025-01-21T15:48:00+00:00","article_modified_time":"2025-01-30T10:03:38+00:00","og_image":[{"width":1792,"height":1024,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp","type":"image\/webp"}],"author":"jmlweb","twitter_card":"summary_large_image","twitter_creator":"@CodemotionIT","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"jmlweb","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/"},"author":{"name":"jmlweb","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/b38417c0c79c66c436a78f8b207c514a"},"headline":"Building Agnostic Components with CVA and TailwindDesign\/UX","datePublished":"2025-01-21T15:48:00+00:00","dateModified":"2025-01-30T10:03:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/"},"wordCount":408,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp","keywords":["Careers","CSS","Tailwind"],"articleSection":["Design\/UX"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/","url":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/","name":"Building Agnostic Components with CVA and TailwindDesign\/UX - Codemotion Magazine","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp","datePublished":"2025-01-21T15:48:00+00:00","dateModified":"2025-01-30T10:03:38+00:00","description":"Discover how to create reusable and efficient components using CVA and Tailwind CSS. Optimize your projects now!","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp","width":1792,"height":1024,"caption":"css repos"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/building-agnostic-components-with-cva-and-tailwinddesign-ux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"Frontend","item":"https:\/\/www.codemotion.com\/magazine\/frontend\/"},{"@type":"ListItem","position":3,"name":"Design\/UX","item":"https:\/\/www.codemotion.com\/magazine\/frontend\/design-ux\/"},{"@type":"ListItem","position":4,"name":"Building Agnostic Components with CVA and TailwindDesign\/UX"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/b38417c0c79c66c436a78f8b207c514a","name":"jmlweb","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e9b818c4bcbc06b196d66cea92d9fe41bd5ccd255dd3943745cd801eff3f96db?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e9b818c4bcbc06b196d66cea92d9fe41bd5ccd255dd3943745cd801eff3f96db?s=96&d=mm&r=g","caption":"jmlweb"},"description":"Frontend Solutions Architect @ Freepik","sameAs":["https:\/\/jmlweb.es"],"url":"https:\/\/www.codemotion.com\/magazine\/author\/jmlweb\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-600x400.webp","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-600x600.webp","author_info":{"display_name":"jmlweb","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/jmlweb\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp",1792,1024,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-150x150.webp",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-300x171.webp",300,171,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-768x439.webp",768,439,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-1024x585.webp",1024,585,true],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-1536x878.webp",1536,878,true],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co.webp",1792,1024,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-100x100.webp",100,100,true],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-180x128.webp",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-896x504.webp",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-400x225.webp",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-600x400.webp",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/06\/DALL\u00b7E-2024-06-24-17.23.54-A-super-widescreen-image-featuring-CSS-as-a-character.-CSS-is-portrayed-as-a-cool-trendy-and-swag-figure-with-a-stylish-outfit-sunglasses-and-a-co-600x600.webp",600,600,true]},"uagb_author_info":{"display_name":"jmlweb","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/jmlweb\/"},"uagb_comment_info":0,"uagb_excerpt":"Is Tailwind great? Yes. But does it have any weak points? Using Tailwind offers numerous advantages: However, it has a clear downside compared to traditional CSS approaches: code repetition. To mitigate this, Tailwind&#8217;s documentation suggests using components wherever possible. Another drawback: lost semanticsFor instance, applying the class btn--lg to an element implies using a &#8220;large&#8221;&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/31585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/254"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=31585"}],"version-history":[{"count":2,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/31585\/revisions"}],"predecessor-version":[{"id":31824,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/31585\/revisions\/31824"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/28361"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=31585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=31585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=31585"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=31585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}