Like you see in inspector, you defined only border color but not border width. Because it is 0px, it is invisible ;)

You need to change it to

class="border border-gray-800"

"border" will by default mean border-width: 1px so if you need thicker use for example

class="border-2 border-gray-800"

or if you wanna it only on one side

class="border-right border-gray-800"

More in documentation.

Answer from chojnicki on Stack Overflow
🌐
Reddit
reddit.com › r/tailwindcss › border won't show up
r/tailwindcss on Reddit: Border won't show up
August 22, 2023 -

I'm a beginner to Tailwind, so it's likely something simple. I can see an <input type="text" class="border border-solid border-2 border-indigo-600">, but only a faint 1px border of #e5e7eb shows up. I can see that this is under the *, ::before, ::after rule at the top of the stylesheet. My config file is customized only for the content paths, and theme and extend are empty. I read quite a bit of the Tailwind documentation, but I'm having a lot of trouble wrapping my head around how basics like color intersect with border, background, and text seeing as the latter three all incorporate color.

🌐
Bitovi
bitovi.com › blog › why-tailwind-doesnt-work-for-me
Why Tailwind Doesn't Work For Me
January 4, 2024 - In the previous example of border, Tailwind broke it’s own convention and it did it just to save 2 keystrokes. Whether we are talking about JS variable names, CSS class names, or just code comments, character length does not matter to the final product. Your build system should be stripping out comments and minifying the rest.
🌐
Reddit
reddit.com › r/tailwindcss › anyone else get annoyed typing `border-[1px]` and stuff all the time in tailwind?
r/tailwindcss on Reddit: Anyone else get annoyed typing `border-[1px]` and stuff all the time in Tailwind?
October 30, 2024 -

Design systems are getting better and more standardized these days, but honestly… I still find myself typing a lot of custom values in Tailwind — like w-[2px], h-[234px], border-[1px], that kind of thing.

It’s not a huge deal, but when it happens often, it breaks your flow. So I ended up making a tiny VSCode extension that helps me speed that part up a bit.

  • w-[2px]

  • h-[200px]

  • mt-[10vh]

It’s not a big deal, but when you’re doing it constantly, it adds up.

So I made a tiny VSCode extension that lets you type shorthands like:

  • w2pw-[2px]

  • h200ph-[200px]

  • mt10vhmt-[10vh]

Just something I threw together to save a few keystrokes. Might be useful if you do a lot of custom utility work.

🔗 tw-auto-bracket on VSCode Marketplace

Would love to hear if anyone else has little tricks or extensions they use for Tailwind. Always looking to improve the workflow 🙌

🌐
Reddit
reddit.com › r/tailwindcss › can't change the border color
r/tailwindcss on Reddit: Can't change the border color
June 10, 2022 -

I'm using the tab component from tailwind elements on a project i'm working on but I'm really struggling to change the bottom border color on the active tab (i.e. the tab you click to view the contents of the tab).

https://tailwind-elements.com/docs/standard/navigation/tabs/#section-related-resources

Whatever I try, the bottom border remains blue!

Does anyone have any idea where I can change it?

🌐
Tailwind CSS
tailwindcss.com › docs › border-style
border-style - Borders - Tailwind CSS
Use utilities like divide-dashed and divide-dotted to control the border style between child elements:
🌐
GitHub
github.com › tailwindlabs › tailwindcss › discussions › 16002
Using @layer base { border-color } is not working for TailwindCSS ver 4 · tailwindlabs/tailwindcss · Discussion #16002
@RobinMalfait I think that because I am importing a legacy tailwindcss JS config file the --color-gray-200 was not defined by default when importing @import "tailwindcss";, so by doing this I could fix the issue with the default border color:
Author   tailwindlabs
Find elsewhere
🌐
GitHub
github.com › tailwindlabs › tailwindcss › issues › 435
Browser ignoring .border · Issue #435 · tailwindlabs/tailwindcss
March 26, 2018 - I've come across an issue where the browser is ignoring the .border class: This happens in both Chrome & Firefox.
Published   Mar 26, 2018
🌐
Reddit
reddit.com › r/reactjs › tailwind css v4 styles not applying in shadow dom but work in development
r/reactjs on Reddit: Tailwind CSS v4 styles not applying in Shadow DOM but work in development
June 21, 2025 -

I'm building an embeddable React component using Vite and Tailwind CSS v4. The component works perfectly when running npm run dev, but when I embed it as a web component using Shadow DOM, some Tailwind styles (specifically background colors, border radius, and borders) are not being applied to certain components.


Setup

Vite Config:

import path from "path"
import tailwindcss from "@tailwindcss/vite"
import react from "@vitejs/plugin-react-swc"
import { defineConfig } from "vite"

// https://vite.dev/config/
export default defineConfig({
  plugins: [react(), tailwindcss()],
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  define: {
    'process.env.NODE_ENV': JSON.stringify('production'),
    'process.env': '{}',
  },
  build: {
    lib: {
      entry: "./src/index.tsx",
      name: "myWidget",
      fileName: (format) => `mywidget.${format}.js`,
      formats: ["es", "umd"]
    },
    target: "esnext",
    rollupOptions: {
      external: [],
      output: {
        inlineDynamicImports: true,
        assetFileNames: (assetInfo) => {
          if (assetInfo.name?.endsWith('.css')) {
            return 'style.css';
          }
          return assetInfo.name || 'asset';
        },
        globals: {
          'react': 'React',
          'react-dom': 'ReactDOM'
        }
      },
    },
    cssCodeSplit: false,
  },
})

Tailwind Config:

// /** @type {import('tailwindcss').Config} */
export default {
  content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
  theme: {
    extend: {},
  },
  plugins: [
    require('@tailwindcss/typography'),
  ],
}

Web Component Implementation:

import ReactDOM from "react-dom/client";
import ChatSupport from "./components/ui/chatSupport";
import type { ChatbotCustomizationProps } from "./types/chatbotCustomizationProps";
// Import CSS as string for shadow DOM injection
import cssContent from "./index.css?inline";

export const normalizeAttribute = (attribute: string) => {
  return attribute.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
};

class MyWidget extends HTMLElement {
  private root: ReactDOM.Root | null = null;

  constructor() {
    super();
    this.attachShadow({ mode: "open" });
  }

  connectedCallback() {
    // Inject CSS into shadow DOM
    this.injectStyles();
    
    const props = this.getPropsFromAttributes<ChatbotCustomizationProps>();
    this.root = ReactDOM.createRoot(this.shadowRoot as ShadowRoot);
    this.root.render(<ChatSupport {...props} />);
  }

  disconnectedCallback() {
    if (this.root) {
      this.root.unmount();
      this.root = null;
    }
  }

  private injectStyles() {
    if (this.shadowRoot) {
      const styleElement = document.createElement('style');
      styleElement.textContent = cssContent;
      this.shadowRoot.appendChild(styleElement);
    }
  }

  private getPropsFromAttributes<T>(): T {
    const props: Record<string, string> = {};

    for (let index = 0; index < this.attributes.length; index++) {
      const attribute = this.attributes[index];
      props[normalizeAttribute(attribute.name)] = attribute.value;
    }

    return props as T;
  }
}

export default MyWidget

Problem

When the component runs in development mode (npm run dev), all Tailwind classes work correctly. However, when built and embedded as a web component with Shadow DOM, some styles are missing:

  • Background colors (bg-blue-500, bg-gray-100, etc.) – only affecting specific components

  • Border radius (rounded-lg, rounded-md)

  • Borders (border, border-gray-300)

I know that the Tailwind styles are being injected since most of the component is how I styled it, with just some things missing. This is the first time I'm using web components so I have no idea and nowhere to look for answers.

I tried adding a safelist in the Tailwind config but that didn't seem to affect the web-component version. I then added a bunch of styles in the injectStyles function in the same file where I define the component. That worked for the rounded border styles but didn't work for the background color and border styles which weren’t being displayed.

If the rest of the styles are working, why aren't these ones doing the same? Anyone got any solutions? Is it just Shadow DOM not working the same as the regular?

Top answer
1 of 3
3
It sounds frustrating! Since most of your styles are working but specific ones like bg-*, rounded-*, and border-* aren’t, this is likely a purge issue. Tailwind might be stripping those classes during the production build because it doesn’t detect them directly in your source files. This can especially happen if you’re applying those class names conditionally or building them dynamically. One solution is to explicitly add a safelist in your tailwind.config.js. This tells Tailwind not to purge those classes. For example, you can add: safelist: [ 'bg-blue-500', 'bg-gray-100', 'rounded-lg', 'rounded-md', 'border', 'border-gray-300', ] Make sure this is placed at the root level of the config object, not inside theme or plugins. Also, double-check that your CSS is being correctly injected into the Shadow DOM. After building, open your generated style.css file and verify that those class definitions (e.g. .bg-blue-500, .rounded-md) actually exist. If they're missing, the purge process is likely cutting them out. Keep in mind that CSS specificity works differently in the Shadow DOM. Styles won’t cascade in from outside, so if your dev environment seems fine but production doesn't render the same way, it may be due to these encapsulation differences.
2 of 3
1
This is peak Tailwind + Shadow DOM pain. Seen this combo trip up a lot of folks, especially when it works in dev and then falls apart in the build. A few things to try: When you’re developing (npm run dev), Vite shoves a fat global stylesheet into the page, and maybe your Shadow DOM is picking it up by accident. In production, you’re explicitly injecting compiled CSS into the shadow root (good), but Tailwind's JIT (Just-in-Time) engine will strip out any classes it doesn’t see during build. If you conditionally render classes (e.g. someFlag ? "bg-blue-500" : "bg-gray-100") or use string interpolation, Tailwind might not catch them. Same thing if you’re generating class names from props or config files. Two ways to debug: Search your compiled cssContent for the missing class names (bg-blue-500, etc). If they’re missing, it’s a Purge bug. Add a safelist to your tailwind.config.js that names exactly which classes you know you’re using. Restart the build. See if that flips the switch. Example: safelist: [ "bg-blue-500", "bg-gray-100", "rounded-lg", "border", "border-gray-300", ] If that fixes it, you’ve confirmed Tailwind is just being aggressive about stripping CSS. Leave those in the safelist or refactor how you generate the class names. Also, make sure your cssContent import really contains the built CSS and not just an empty or truncated file. Sometimes, misconfiguring @vitejs/plugin-react-swc or path aliasing can trip up the build output. This isn’t really a Shadow DOM issue. Shadow just forces you to do CSS right, so any missing styles are way more obvious. Last tip: if you’re dealing with lots of tokens and tired of the setup grind, Foundation is my Figma shortcut for getting variables and tokens out, but obviously doesn’t touch the CSS build side here. Chances are this is all Tailwind’s side. Safelist and check the CSS bundle, you’ll probably nail it.
🌐
Reddit
reddit.com › r/tailwindcss › border bottom on hover on mediyum screen isnt working
r/tailwindcss on Reddit: Border bottom on hover on mediyum screen isnt working
November 29, 2022 -
<button className="text-left w-fit border-b-2 border-app-yellow-50 
md:border-none md:hover:mb-[-2px] md:hover:border-b-2 md:hover:border-app-yellow-50
">
Don't yet have an account? Sign up 😄
</button>

Hi! I have a button with a border bottom on small screens and disabling it to only enable on wideer screens. But, it isn't working. Any ideas on how I can fix this?

here is a minimum replication https://play.tailwindcss.com/ki712K5lFA

🌐
Reddit
reddit.com › r/tailwindcss › hi im learning tailwindcss but border and scroll-mt- doesnt work, help!
r/tailwindcss on Reddit: Hi im Learning tailwindcss but border and scroll-mt- doesnt work, help!
April 17, 2024 -

Hello as titel says, they dont work.

Im following a guide and in the guide they work. But for example if i try to make a list with a border or add scroll margin with scroll-mt-20, Nothing happens .

Example:

<section id="rockets" class="p-6 my-12 scroll-mt-20">

-- This scroll-mt-20 does nothing.

<li class="w-2/3 sm:w-5/6 flex flex-col items-center border border-solid border-slate-900 dark:border-gray-100 bg-white py-6 px-2 rounded-3xl shadow-xl dark:bg-black"></li>

-- This does not get a border.

🌐
GeeksforGeeks
geeksforgeeks.org › css › border-style-not-working-on-hover-in-tailwind-css
Border Style Not Working on Hover in Tailwind CSS? - GeeksforGeeks
July 23, 2025 - </button> </body> </html> ... In Tailwind CSS, it is very important to apply the hover class with the correct structure. If we place the hover: class in the wrong place, it will not work.
🌐
GitHub
github.com › tailwindlabs › tailwindcss › discussions › 8006
border-l-1 is not working · tailwindlabs/tailwindcss · Discussion #8006
Just use: border-l for a 1px left border, as for any other odd or custom value you can use Arbitrary Values, for example: border-l-[3px] border-l-[5px] border-l-[3em] border-l-[3rem]
Author   tailwindlabs
🌐
GitHub
github.com › mui › material-ui › issues › 37371
Tailwind border styles don't apply · Issue #37371 · mui/material-ui
May 22, 2023 - Link to live example from official tailwind+mui example: https://codesandbox.io/s/react-tailwind-borders-issue-xmig8s?file=/src/App.tsx For some reason tailwind border styles don't work.
Published   May 22, 2023
🌐
Reddit
reddit.com › r/tailwindcss › how to stop a border hover state from moving button/div
r/tailwindcss on Reddit: How to stop a border hover state from moving button/div
November 19, 2022 -

Hi all, struggle town tourist here

I am trying to figure out how I can stop a div from moving when I've set a border as a hover state.With regular CSS, I usually just add a transparent border to the default state, but this is not working for me with tailwind.

It wont take both a default state border & hover state border

Heres my Tailwind Play:https://play.tailwindcss.com/gZOUB4Ynuo