I have created a site using React with TailwindCSS v4.1.16.
When running the site in dev mode (npm run dev), the responsive design is working and I can see the changing formats when I resize my screen or use devtools. However, when in production the site is always showing in mobile view no matter the size of the screen. The build command being used in prod is npm run build .
Here is the scripts section of the package.json
"scripts": {
"start": "react-scripts start",
"build": "npm run tw:build && react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"tw:watch": "npx @tailwindcss/cli -i ./src/input.css -o ./src/output.css --watch",
"tw:build": "npx @tailwindcss/cli -i ./src/input.css -o ./src/output.css",
"dev": "concurrently \"npm run tw:watch\" \"npm start\""
}
src/input.css
@import url('https://fonts.googleapis.com/css2?family=Birthstone&display=swap');
@import "tailwindcss";
@layer utilities {
.font-logo {
font-family: 'Birthstone', cursive;
}
}
src/index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import './output.css';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
tailwind.config.cjs
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./index.html",
"./src/**/*.{js,jsx,ts,tsx,json}",
],
theme: {
extend: {
fontFamily: {
sans: ['Quicksand', 'sans-serif'], // default body text
logo: ['Birthstone', 'cursive'], // logo
},
},
},
safelist: [
'font-logo',
{
pattern: /(sm|md|lg|xl|2xl):/,
},
],
plugins: [],
};
One of my components
import React from "react";
import BusinessContent from "../content/BusinessContent";
import AboutContent from "../content/AboutContent.json";
const About = () => {
return (
<section id="about" className="w-full text-gray-900 py-16 px-4 sm:px-8" style={{ backgroundColor: BusinessContent.secondaryColour }}>
<div className="max-w-5xl mx-auto flex flex-col md:flex-row items-center md:space-x-12">
{/* Image */}
<img
src={AboutContent.photo}
alt="Person1"
className="w-full md:w-1/3 rounded-lg shadow-lg mb-6 md:mb-0"
/>
{/* Text */}
<div className="md:flex-1">
<h2 className="text-3xl sm:text-4xl font-logo mb-4">
{AboutContent.title}
</h2>
{AboutContent.paragraphs.map((p, i) => (
<p key={i} className="text-base sm:text-lg leading-relaxed mt-4">
{p}
</p>
))}
</div>
</div>
</section>
);
};
export default About;