You didn't share your v4 configuration, so your border-x-xs and border-border declarations aren't really clear. Starting with TailwindCSS v4, the JavaScript-based configuration has been removed by default, and instead, you configure these kinds of custom values using namespaces in a CSS-first configuration.
It's important to note that for utilities like border-width, width, height, margin, padding, etc., the values are controlled by a central --spacing variable. As a result, you can't define new values for these by default. So valid widths would be something like border-1 or border-2, but border-xs is not valid.
You can customize these settings using the @theme directive, but as mentioned, since widths, heights, and other sizing values are governed by the central --spacing, it's not possible (and would be inconsistent) to define special border-width values. This somewhat explains why tailwind-merge might not properly interpret your input. Two different results in two similar-looking cases could be due to internal logic differences, so I'd suggest opening an issue in the repository.
The extendTailwindMerge function in tailwind-merge also adapts to the namespaces used in the CSS-first configuration. As a result, extend.theme.borderColor, extend.theme.borderWidth, and extend.theme.borderRadius are no longer available.
In v4, the new namespace for borderRadius is rounded-*, which you can configure using extend.theme.rounded when using extendTailwindMerge.
As I mentioned earlier, according to the v4 documentation, it's not possible to customize border-color or border-width directly, so naturally, this isn't supported in twMerge either.
Example for a custom color name
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<style type="text/tailwindcss">
@theme {
--color-border: #da373d; /* not reusable, I don't recommend border as a name */
}
</style>
<div class="w-32 h-32 border-2 border-border text-border">Hello World</div>
Example for a custom color name usable only for borders
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<style type="text/tailwindcss">
@theme {
/* undocumented, expected to be deprecated in the future */
--border-color-border: #da373d; /* not reusable, I don't recommend border as a name */
}
</style>
<div class="w-32 h-32 border-2 border-border text-border">Hello World</div>
Example of introducing a custom border-width (using a custom utility)
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
<style type="text/tailwindcss">
@theme {
/* undocumented, expected to be deprecated in the future */
--border-color-border: #da373d; /* not reusable, I don't recommend border as a name */
/* new custom namespace by --value(--border-width-*) */
--border-width-xs: 10px;
--border-width-sm: 20px;
--border-width-md: 40px;
}
/* new custom utility for border-width */
@utility border-* {
border-width: --value(--border-width-*);
}
/* new custom utility for border-y-width */
@utility border-y-* {
border-top-width: --value(--border-width-*);
border-bottom-width: --value(--border-width-*);
}
/* new custom utility for border-x-width */
@utility border-x-* {
border-left-width: --value(--border-width-*);
border-right-width: --value(--border-width-*);
}
/* new custom utility for border-t-width */
@utility border-t-* {
border-top-width: --value(--border-width-*);
}
/* new custom utility for border-b-width */
@utility border-b-* {
border-bottom-width: --value(--border-width-*);
}
/* new custom utility for border-l-width */
@utility border-l-* {
border-left-width: --value(--border-width-*);
}
/* new custom utility for border-r-width */
@utility border-r-* {
border-right-width: --value(--border-width-*);
}
</style>
<div class="w-32 h-32 border-x-xs border-y-md border-border text-border">Hello World</div>
<div class="w-32 h-32 border-x-sm border-y-sm border-red-400 text-border">Hello World</div>
<div class="w-32 h-32 border-x-md border-y-xs border-red-200 text-border">Hello World</div>
In this case, it is the responsibility of Tailwind Merge to ensure the correct order, but your TailwindCSS v4 configuration is at least perfect for the desired result.
tailwindlabs/tailwindcssdiscussion #19020 - Which TailwindCSS v4 namespace matches a given TailwindCSS v3's theme keys?