Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

A Tailwind border colour class has no visible effect

Your error

border-red-500 is on the element but no border appears2 more lines it can show

Fix it fast

Most common cause, 1 of 3

Only a colour class is set, with no border width

Add a width utility next to the colour. border gives 1px; border-2, border-4 and the side variants such as border-b work the same way.

Fix
<div className="rounded-lg border border-red-500 p-4">
  Payment failed
</div>
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

A Tailwind class such as border-red-500 sets only border-color, and Preflight resets every element's border to 0 width, so on its own it draws nothing; add border or border-2. A colour built with string interpolation is never generated. Since Tailwind v4 a bare border uses currentColor instead of v3's gray-200. Applies to Tailwind CSS 4.3.

  • Applies to Tailwind CSS 4.3, Next.js 16.4, React 19.3
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Print the element's computed border values in the browser console, with #card replaced by a selector for your element. A width of 0px means no width class applies; a set width with the text colour means the colour class never reached the stylesheet or was never written.

Run this first
const el = document.querySelector('#card');
const cs = getComputedStyle(el);
console.log(cs.borderTopWidth, cs.borderTopStyle, cs.borderTopColor, cs.color);

Then find the line you see in this list and open its fix:

  1. 1Only a colour class is set, with no border widthThe console prints 0px for borderTopWidth even though border-red-500 is on the element
  2. 2The colour class name is assembled at runtimeThe markup builds the class with a template string, such as border-${color}-500, and the width is fine but the colour falls back to currentColor
  3. 3v4 draws a bare border in currentColor, not v3's grayAfter the upgrade to v4, elements with only the border class show a dark border in the text colour

What does the error look like?

  • border-red-500 is on the element but no border appears
  • The border shows in the text colour instead of the colour set in the class
  • Borders turned dark after upgrading from Tailwind v3 to v4

Cause 1 of 3

Only a colour class is set, with no border width

You seeThe console prints 0px for borderTopWidth even though border-red-500 is on the element

Check

A Tailwind border colour class seems not to work when the element has no width class. border-red-500 writes border-color and nothing else, and Preflight starts every element at border: 0 solid, so the colour is applied to a border that is zero pixels wide.

Check
grep -rnE "border-[a-z]+-[0-9]{2,3}" app components src 2>/dev/null

Fix

Add a width utility next to the colour. border gives 1px; border-2, border-4 and the side variants such as border-b work the same way.

Fix
<div className="rounded-lg border border-red-500 p-4">
  Payment failed
</div>

Verify

The console now prints 1px solid and the red value for the element's top border.

Verify
console.log(getComputedStyle(document.querySelector('#card')).borderTopWidth)

Confirmed by tailwindcss.com

Did this fix it?

Cause 2 of 3

The colour class name is assembled at runtime

You seeThe markup builds the class with a template string, such as border-${color}-500, and the width is fine but the colour falls back to currentColor

Check

Tailwind generates a border colour only for class names that appear whole somewhere in your source files. It reads those files as plain text, so it cannot work out what border-${color}-500 turns into, and the finished class has no CSS behind it.

Check
grep -rnE "border-\$\{" app components src 2>/dev/null

Fix

Map each prop value to a complete class string, so every variant appears in the source as written. If a class truly cannot appear in source, force it with @source inline() in the CSS entry file.

Fix
const borderByStatus = {
  error: 'border-red-500',
  ok: 'border-green-600',
};

export function Card({ status, children }) {
  return <div className={`border ${borderByStatus[status]}`}>{children}</div>;
}

/* app/globals.css, only for classes that never appear in source */
@import "tailwindcss";
@source inline("border-amber-500");

Verify

Rebuild, reload the page and confirm the computed border colour matches the status.

Verify
npm run dev

Confirmed by tailwindcss.com

Did this fix it?

Cause 3 of 3

v4 draws a bare border in currentColor, not v3's gray

You seeAfter the upgrade to v4, elements with only the border class show a dark border in the text colour

Check

A border colour that changed after moving to Tailwind v4 comes from a changed default: v3 coloured border and divide utilities gray-200 when no colour class was given, while v4 uses currentColor to match the browser. A tailwind.config.js is also no longer read unless the CSS loads it with @config, so a default colour set there stops applying.

Check
grep -rn "@config\|@import \"tailwindcss\"" app src --include="*.css" 2>/dev/null

Fix

Name a colour wherever border or divide is used, or restore the v3 default once in the base layer, as the upgrade guide shows.

Fix
/* app/globals.css */
@import "tailwindcss";

@layer base {
  *,
  ::after,
  ::before,
  ::backdrop,
  ::file-selector-button {
    border-color: var(--color-gray-200, currentColor);
  }
}

Verify

Elements with only the border class show the light gray border again.

Verify
console.log(getComputedStyle(document.querySelector('#card')).borderTopColor)

Confirmed by tailwindcss.com

Did this fix it?

How do I stop it coming back?

  • Write border and its colour as a pair (border border-gray-200) in shared components, so neither depends on a default.
  • Keep status-to-class maps in one file with every class spelled out in full, instead of building names from variables.
  • Read the v4 upgrade guide's list of changed defaults before upgrading and grep for bare border and divide classes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.