Skip to content

UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.

fix: fix build

Dillion Verma23d129e88262
diff --git a/apps/www/content/blog/color-theory-for-web-design.mdx b/apps/www/content/blog/color-theory-for-web-design.mdx
index 73737413..79ff8d1d 100644
--- a/apps/www/content/blog/color-theory-for-web-design.mdx
+++ b/apps/www/content/blog/color-theory-for-web-design.mdx
@@ -158,10 +158,10 @@ The table below breaks down the most common contrast requirements you'll encount
### WCAG 2.1 Contrast Ratio Requirements
-| Conformance Level | Normal Text (<18pt) | Large Text (≥18pt or 14pt bold) | UI Components & Graphics |
-| :----------------- | :------------------ | :------------------------------ | :----------------------- |
-| **AA (Minimum)** | **4.5:1** | **3:1** | **3:1** |
-| **AAA (Enhanced)** | **7:1** | **4.5:1** | **4.5:1** |
+| Conformance Level | Normal Text (\<18pt) | Large Text (≥18pt or 14pt bold) | UI Components & Graphics |
+| :----------------- | :------------------- | :------------------------------ | :----------------------- |
+| **AA (Minimum)** | **4.5:1** | **3:1** | **3:1** |
+| **AAA (Enhanced)** | **7:1** | **4.5:1** | **4.5:1** |
As you can see, the requirements are more lenient for larger text and essential graphics, but aiming for the higher AA standard for your body copy is a solid starting point for any project.
diff --git a/apps/www/content/blog/create-next-js-app.mdx b/apps/www/content/blog/create-next-js-app.mdx
index 414823df..d33bc66d 100644
--- a/apps/www/content/blog/create-next-js-app.mdx
+++ b/apps/www/content/blog/create-next-js-app.mdx
@@ -102,32 +102,34 @@ Tailwind's default theme is fantastic, but let's be real—you need to make it y
Let's say you're building a sleek, modern dashboard. You can easily extend the default theme to include your specific brand colors.
+```ts
// tailwind.config.ts
-import type { Config } from 'tailwindcss';
+import type { Config } from "tailwindcss"
const config: Config = {
-content: [
-'./pages/**/*.{js,ts,jsx,tsx,mdx}',
-'./components/**/*.{js,ts,jsx,tsx,mdx}',
-'./app/**/*.{js,ts,jsx,tsx,mdx}',
-],
-theme: {
-extend: {
-colors: {
-brand: {
-primary: '#0A72E4',
-secondary: '#F5A623',
-},
-dark: {
-900: '#1a1a1a',
-800: '#2b2b2b',
-},
-},
-},
-},
-plugins: [],
-};
-export default config;
+ content: [
+ "./pages/**/*.{js,ts,jsx,tsx,mdx}",
+ "./components/**/*.{js,ts,jsx,tsx,mdx}",
+ "./app/**/*.{js,ts,jsx,tsx,mdx}",
+ ],
+ theme: {
+ extend: {
+ colors: {
+ brand: {
+ primary: "#0A72E4",
+ secondary: "#F5A623",
+ },
+ dark: {
+ 900: "#1a1a1a",
+ 800: "#2b2b2b",
+ },
+ },
+ },
+ },
+ plugins: [],
+}
+export default config
+```
By nesting your custom colors inside `theme.extend`, you’ve just created new utility classes like `bg-brand-primary` and `text-dark-900` that you can use anywhere. It’s a simple change that enforces brand consistency and makes your markup much more descriptive.
@@ -139,21 +141,27 @@ Now, let's put this into practice and build a simple, responsive card component.
You'll see just how fast and intuitive this is.
+```tsx
// components/InfoCard.tsx
-import React from 'react';
-
-export const InfoCard = ({ title, children }: { title: string; children: React.ReactNode }) => {
+import React from "react"
+
+export const InfoCard = ({
+ title,
+ children,
+}: {
+ title: string
+ children: React.ReactNode
+}) => {
return (
- <div className="max-w-sm rounded-lg border border-neutral-200 bg-white p-6 shadow-md transition-shadow hover:shadow-lg dark:border-neutral-700 dark:bg-dark-800">
+ <div className="dark:bg-dark-800 max-w-sm rounded-lg border border-neutral-200 bg-white p-6 shadow-md transition-shadow hover:shadow-lg dark:border-neutral-700">
<h3 className="mb-2 text-xl font-bold text-gray-900 dark:text-white">
{title}
</h3>
- <p className="font-normal text-gray-700 dark:text-gray-400">
- {children}
- </p>
+ <p className="font-normal text-gray-700 dark:text-gray-400">{children}</p>
</div>
- );
-};
+ )
+}
+```
> The beauty of this method is its immediacy. You build, style, and see the results without ever leaving your component file. This tight feedback loop is what makes developing with Tailwind and Next.js feel so productive.
@@ -200,6 +208,7 @@ First, you need to bring the component's code into your project. This is the rec
Now, you can import and use it in your `app/page.tsx` file (or anywhere else) just like any other React component.
+```tsx
import ShimmerButton from "@/components/magicui/shimmer-button"
export default function HomePage() {
@@ -207,7 +216,7 @@ export default function HomePage() {
<main className="flex min-h-screen flex-col items-center justify-center p-24">
<div className="z-10 w-full max-w-5xl items-center justify-center font-mono text-sm lg:flex">
<ShimmerButton className="shadow-2xl">
- <span className="text-center text-sm leading-none font-medium tracking-tight whitespace-pre-wrap text-white lg:text-lg dark:from-white dark:to-slate-900/10">
+ <span className="whitespace-pre-wrap text-center text-sm font-medium leading-none tracking-tight text-white lg:text-lg dark:from-white dark:to-slate-900/10">
Get Started Now
</span>
</ShimmerButton>
@@ -215,6 +224,7 @@ export default function HomePage() {
</main>
)
}
+```
> Just like that, you've added a layer of interactivity that makes your UI feel more dynamic and satisfying. This is the core value of Magic UI—achieving maximum visual impact with minimal code.
@@ -258,17 +268,19 @@ The culprit is usually your `tailwind.config.ts` file. Tailwind's magic works by
The fix is easy. Just make sure your `content` path in the config file is broad enough to catch everything:
+```ts
// tailwind.config.ts
const config = {
-content: [
-'./pages/**/*.{js,ts,jsx,tsx,mdx}',
-'./components/**/*.{js,ts,jsx,tsx,mdx}',
-'./app/**/*.{js,ts,jsx,tsx,mdx}',
-// Make sure to add any other directories you're using!
-'./src/**/*.{js,ts,jsx,tsx,mdx}',
-],
-// ... rest of your config
-};
+ content: [
+ "./pages/**/*.{js,ts,jsx,tsx,mdx}",
+ "./components/**/*.{js,ts,jsx,tsx,mdx}",
+ "./app/**/*.{js,ts,jsx,tsx,mdx}",
+ // Make sure to add any other directories you're using!
+ "./src/**/*.{js,ts,jsx,tsx,mdx}",
+ ],
+ // ... rest of your config
+}
+```
One crucial detail: after updating the config, you **must** restart your dev server (`npm run dev`). A simple browser refresh won't cut it. Restarting forces Tailwind to re-scan your entire project and build the correct stylesheet.
@@ -284,24 +296,32 @@ For instance, if you try to render `new Date().toLocaleTimeString()` directly in
A reliable pattern for this is to use the `useState` and `useEffect` hooks. This effectively delays the rendering of your client-specific code until _after_ the initial server render has been "hydrated" on the client.
-'use client';
-import { useState, useEffect } from 'react';
+```tsx
+"use client"
+
+import { useEffect, useState } from "react"
const ClientOnlyComponent = () => {
-const [isClient, setIsClient] = useState(false);
+ const [isClient, setIsClient] = useState(false)
-useEffect(() => {
-// This runs only on the client, after the initial render
-setIsClient(true);
-}, []);
+ useEffect(() => {
+ // This runs only on the client, after the initial render
+ setIsClient(true)
+ }, [])
-if (!isClient) {
-return null; // Or you could return a loading skeleton here
-}
+ if (!isClient) {
+ return null // Or you could return a loading skeleton here
+ }
-// Now you're safely on the client and can use browser APIs
-return <div>Your current timezone is: {Intl.DateTimeFormat().resolvedOptions().timeZone}</div>;
-};
+ // Now you're safely on the client and can use browser APIs
+ return (
+ <div>
+ Your current timezone is:{" "}
+ {Intl.DateTimeFormat().resolvedOptions().timeZone}
+ </div>
+ )
+}
+```
This little trick ensures your component handles the server-to-client transition smoothly, getting rid of those frustrating errors and keeping your console nice and clean.
diff --git a/apps/www/content/blog/creating-next-js-app.mdx b/apps/www/content/blog/creating-next-js-app.mdx
index 97666740..f1d8fa23 100644
--- a/apps/www/content/blog/creating-next-js-app.mdx
+++ b/apps/www/content/blog/creating-next-js-app.mdx
@@ -94,21 +94,23 @@ Now, we need to tell Tailwind which files to watch. This is how its Just-in-Time
Open up `tailwind.config.ts` and paste these paths into the `content` array.
+```ts
// tailwind.config.ts
-import type { Config } from "tailwindcss";
+import type { Config } from "tailwindcss"
const config: Config = {
-content: [
-"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
-"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
-"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
-],
-theme: {
-extend: {},
-},
-plugins: [],
-};
-export default config;
+ content: [
+ "./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
+ "./src/components/**/*.{js,ts,jsx,tsx,mdx}",
+ "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
+ ],
+ theme: {
+ extend: {},
+ },
+ plugins: [],
+}
+export default config
+```
This glob pattern tells Tailwind to scan every relevant file inside your `app`, `components`, and `pages` directories. It's a critical step, so don't skip it!
@@ -167,6 +169,7 @@ The CLI works its magic, automatically adding the necessary files right into you
Here's how you'd drop it into a page:
+```tsx
import { Dock, DockIcon } from "@/components/magicui/dock"
export default function HomePage() {
@@ -179,6 +182,7 @@ export default function HomePage() {
</div>
)
}
+```
Just like that, you've added a genuinely sophisticated and interactive element to your app. This kind of rapid enhancement is a huge reason why Next.js has become so popular. With a **52.9% usage rate** among rendering frameworks as of 2025 and over **132,000 stars** on GitHub, its robust ecosystem is one of its greatest strengths. You can find more details on [Next.js framework advantages on aalpha.net](https://www.aalpha.net/articles/nextjs-advantages-and-disadvantages/).
diff --git a/apps/www/content/blog/dropdown-in-react-js.mdx b/apps/www/content/blog/dropdown-in-react-js.mdx
index 95838592..9ba4c276 100644
--- a/apps/www/content/blog/dropdown-in-react-js.mdx
+++ b/apps/www/content/blog/dropdown-in-react-js.mdx
@@ -40,7 +40,7 @@ The demand for this kind of custom work is fueled by React's incredible adoption
Of course, starting from a blank slate isn't always necessary. For larger projects, looking into the **[best react component library](https://magicui.design/blog/best-react-component-library)** can save a ton of development time by providing pre-built, accessible components ready for customization. This guide, however, is all about giving you the foundational knowledge to build one yourself.
-### Native <select> vs Custom React Dropdown
+### Native `<select>` vs Custom React Dropdown
Here's a quick look at the pros and cons of using the browser's default select element compared to a custom React component for your dropdowns.
diff --git a/apps/www/content/blog/framer-motion-react.mdx b/apps/www/content/blog/framer-motion-react.mdx
index 17ca79a8..61183297 100644
--- a/apps/www/content/blog/framer-motion-react.mdx
+++ b/apps/www/content/blog/framer-motion-react.mdx
@@ -148,7 +148,7 @@ Sometimes, seeing the difference laid out helps clarify why one approach is bett
### Animation Props vs Variants
-| Feature | Direct Props (e.g., animate={{...}}) | Variants (e.g., variants={...}) |
+| Feature | Direct Props (e.g., animate=\{\{...\}\}}) | Variants (e.g., variants=\{\{...\}\}) |
| :---------------- | :-------------------------------------------- | :------------------------------------------ |
| **Readability** | Poor for complex states. JSX gets cluttered. | Excellent. Separates logic from markup. |
| **Reusability** | Low. Logic is tied directly to the component. | High. Can be imported and used anywhere. |
diff --git a/apps/www/content/blog/install-tailwind-css.mdx b/apps/www/content/blog/install-tailwind-css.mdx
index 86870f27..f33ec456 100644
--- a/apps/www/content/blog/install-tailwind-css.mdx
+++ b/apps/www/content/blog/install-tailwind-css.mdx
@@ -87,12 +87,14 @@ Next, you need to tell PostCSS which plugins to use. Create a `postcss.config.js
Inside that file, add this small snippet:
+```ts
module.exports = {
-plugins: {
-tailwindcss: {},
-autoprefixer: {},
-},
-};
+ plugins: {
+ tailwindcss: {},
+ autoprefixer: {},
+ },
+}
+```
This is pretty straightforward. You're just telling PostCSS to run your CSS through both Tailwind and Autoprefixer during the build step.
@@ -138,17 +140,19 @@ That `-p` flag is a great little timesaver. It automatically creates both your `
Next, you have to tell Tailwind where your template files live. Pop open `tailwind.config.js` and update the `content` array to point to all your source files. This is how Tailwind knows where to scan for utility classes.
+```ts
/** @type {import('tailwindcss').Config} \*/
export default {
-content: [
-"./index.html",
-"./src/**/\*.{js,ts,jsx,tsx,vue}", // Don't forget .vue for Vue projects!
-],
-theme: {
-extend: {},
-},
-plugins: [],
+ content: [
+ "./index.html",
+ "./src/**/\*.{js,ts,jsx,tsx,vue}", // Don't forget .vue for Vue projects!
+ ],
+ theme: {
+ extend: {},
+ },
+ plugins: [],
}
+```
Last step: create your main CSS file (I usually put it at `src/index.css`) and drop in the three main Tailwind directives. Import that CSS file into your main entry point—like `main.jsx` or `main.js`—and you're good to go. For a more detailed walkthrough, our guide on how to [install Tailwind CSS in a React project](https://magicui.design/blog/install-tailwind-react) covers this from top to bottom.
@@ -173,17 +177,18 @@ After you've created your project with `npx create-react-app my-app`, run the st
The most important part for CRA is getting the `content` array in `tailwind.config.js` to match its file structure. It should look like this:
+```ts
/** @type {import('tailwindcss').Config} \*/
module.exports = {
-content: [
-"./src/**/*.{js,jsx,ts,tsx}",
-],
-theme: {
-extend: {},
-},
-plugins: [],
+ content: ["./src/**/*.{js,jsx,ts,tsx}"],
+ theme: {
+ extend: {},
+ },
+ plugins: [],
}
-This kind of seamless integration is exactly why Tailwind's popularity has exploded. By **2025**, it has become the go-to choice over Bootstrap for countless developers who value its customization and performance. Because its build process only includes the classes you *actually\* use, the result is a much smaller CSS file and a faster website—a massive win in today's performance-focused world.
+```
+
+This kind of seamless integration is exactly why Tailwind's popularity has exploded. By **2025**, it has become the go-to choice over Bootstrap for countless developers who value its customization and performance. Because its build process only includes the classes you \*actually\* use, the result is a much smaller CSS file and a faster website—a massive win in today's performance-focused world.
## Customizing Your Tailwind Design System
@@ -208,21 +213,23 @@ Honestly, for most projects, sticking with `extend` is the way to go. It offers
Let's make this practical. Say your brand uses a specific shade of purple and the "Poppins" font. Here’s how you’d wire that up in your config file:
+```ts
// tailwind.config.js
module.exports = {
-theme: {
-extend: {
-colors: {
-'brand-purple': '#5D3BEE',
-'brand-dark': '#1a202c',
-},
-fontFamily: {
-sans: ['Poppins', 'sans-serif'],
-},
-},
-},
-plugins: [],
+ theme: {
+ extend: {
+ colors: {
+ "brand-purple": "#5D3BEE",
+ "brand-dark": "#1a202c",
+ },
+ fontFamily: {
+ sans: ["Poppins", "sans-serif"],
+ },
+ },
+ },
+ plugins: [],
}
+```
Once you save that file and your build process refreshes, you can immediately start using classes like `bg-brand-purple` and `font-sans` in your HTML. It's that seamless.
@@ -253,18 +260,21 @@ Nailing down your `content` paths is absolutely non-negotiable for a successful
A classic mistake is forgetting to include a specific folder or file extension. For instance, if you’ve neatly organized your UI components into a `src/components` directory, you have to tell Tailwind to look there.
+```ts
// tailwind.config.js
module.exports = {
-content: [
-'./src/pages/**/*.{js,ts,jsx,tsx}',
-'./src/components/**/*.{js,ts,jsx,tsx}',
-// Add any other directories that contain Tailwind classes
-],
-theme: {
-extend: {},
-},
-plugins: [],
-};
+ content: [
+ "./src/pages/**/*.{js,ts,jsx,tsx}",
+ "./src/components/**/*.{js,ts,jsx,tsx}",
+ // Add any other directories that contain Tailwind classes
+ ],
+ theme: {
+ extend: {},
+ },
+ plugins: [],
+}
+```
+
This setup instructs Tailwind to scan for any JavaScript or TypeScript files inside both the `pages` and `components` folders. My advice? Always double-check these paths before you deploy.
### Solving Common Build Issues
@@ -320,16 +330,18 @@ First things first, you need to import the font into your main CSS file. Using `
With the font imported, pop open your `tailwind.config.js` and extend the `theme.fontFamily` object. This step registers your new font with Tailwind and gives it a name you can reference with a utility class.
+```ts
// tailwind.config.js
module.exports = {
-theme: {
-extend: {
-fontFamily: {
-sans: ['Inter', 'sans-serif'],
-},
-},
-},
+ theme: {
+ extend: {
+ fontFamily: {
+ sans: ["Inter", "sans-serif"],
+ },
+ },
+ },
}
+```
And that's it! Now you can apply your beautiful new font anywhere in your project just by using the `font-sans` class.
diff --git a/apps/www/content/blog/installing-tailwind-css.mdx b/apps/www/content/blog/installing-tailwind-css.mdx
index 672307e5..ef61143c 100644
--- a/apps/www/content/blog/installing-tailwind-css.mdx
+++ b/apps/www/content/blog/installing-tailwind-css.mdx
@@ -97,17 +97,16 @@ Alright, this next part is the most critical step of the entire process. Serious
Open up your `tailwind.config.js` file and find the `content` array. You need to add paths to every single file that might contain a Tailwind class—HTML files, JavaScript components, you name it.
+```ts
/** @type {import('tailwindcss').Config} \*/
export default {
-content: [
-'./public/**/_.html',
-'./src/\*\*/_.{js,jsx,ts,tsx,vue}',
-],
-theme: {
-extend: {},
-},
-plugins: [],
+ content: ["./public/**/_.html", "./src/\*\*/_.{js,jsx,ts,tsx,vue}"],
+ theme: {
+ extend: {},
+ },
+ plugins: [],
}
+```
This example uses "glob patterns" to find any `.html` files in the `public` folder and a variety of component files inside `src`. Make sure you adjust these paths to match your project's actual folder structure.
@@ -174,18 +173,17 @@ npx tailwindcss init -p
The real key is modifying your `tailwind.config.js`. You need to point the `content` array to your **JSX** and **TSX** files so Tailwind’s JIT compiler knows where to look for utility classes.
+```ts
// tailwind.config.js
/** @type {import('tailwindcss').Config} \*/
export default {
-content: [
-"./index.html",
-"./src/**/\*.{js,ts,jsx,tsx}",
-],
-theme: {
-extend: {},
-},
-plugins: [],
+ content: ["./index.html", "./src/**/\*.{js,ts,jsx,tsx}"],
+ theme: {
+ extend: {},
+ },
+ plugins: [],
}
+```
Lastly, create a main CSS file (something like `src/index.css`) and drop in the three core Tailwind directives. Just make sure to import this CSS file at the very top of your main entry point, which is usually `src/main.jsx`.
@@ -199,19 +197,21 @@ But if you're adding Tailwind to an _existing_ Next.js project, the process is n
The only significant difference is the `content` path in `tailwind.config.js`. You’ll want to configure it to scan the `pages`, `components`, and `app` directories commonly found in Next.js apps.
+```ts
// tailwind.config.js
/** @type {import('tailwindcss').Config} \*/
module.exports = {
-content: [
-'./pages/**/_.{js,ts,jsx,tsx,mdx}',
-'./components/\*\*/_.{js,ts,jsx,tsx,mdx}',
-'./app/\*_/_.{js,ts,jsx,tsx,mdx}',
-],
-theme: {
-extend: {},
-},
-plugins: [],
+ content: [
+ "./pages/**/_.{js,ts,jsx,tsx,mdx}",
+ "./components/\*\*/_.{js,ts,jsx,tsx,mdx}",
+ "./app/\*_/_.{js,ts,jsx,tsx,mdx}",
+ ],
+ theme: {
+ extend: {},
+ },
+ plugins: [],
}
+```
Once that's configured, just add the `@tailwind` directives to your `globals.css` file and make sure it’s imported in your `_app.js` or `layout.js` file.
@@ -251,22 +251,25 @@ You don't have to throw the baby out with the bathwater. The `theme.extend` obje
For instance, here’s how you might add a couple of custom brand colors and a new display font:
+```ts
// tailwind.config.js
module.exports = {
-theme: {
-extend: {
-colors: {
-'brand-primary': '#0A74DA',
-'brand-secondary': '#F6C90E',
-},
-fontFamily: {
-'sans': ['Inter', 'sans-serif'],
-'display': ['Poppins', 'sans-serif'],
-},
-},
-},
-plugins: [],
+ theme: {
+ extend: {
+ colors: {
+ "brand-primary": "#0A74DA",
+ "brand-secondary": "#F6C90E",
+ },
+ fontFamily: {
+ sans: ["Inter", "sans-serif"],
+ display: ["Poppins", "sans-serif"],
+ },
+ },
+ },
+ plugins: [],
}
+```
+
Just like that, you can start using classes like `bg-brand-primary` or `font-display` right in your markup. This is how you enforce consistency and stick to your design specs, which is a huge step up from a basic installation.
> The ability to extend the theme is what makes Tailwind so scalable. You can start with the defaults for rapid prototyping and then gradually introduce custom tokens as your design system matures, all without breaking your existing work.
@@ -283,13 +286,13 @@ First, you'll need to install the package:
Then, just require it inside the `plugins` array in your config file.
+```ts
// tailwind.config.js
module.exports = {
-// ...
-plugins: [
-require('@tailwindcss/typography'),
-],
+ // ...
+ plugins: [require("@tailwindcss/typography")],
}
+```
Now, just by adding a single `prose` className to any container of raw HTML, it will be beautifully styled from top to bottom. This modular approach is great because it keeps your main configuration file clean and makes it simple to add or remove features as your project's needs change.
diff --git a/apps/www/content/blog/next-js-create-app.mdx b/apps/www/content/blog/next-js-create-app.mdx
index 0e9e2022..dfdead6e 100644
--- a/apps/www/content/blog/next-js-create-app.mdx
+++ b/apps/www/content/blog/next-js-create-app.mdx
@@ -146,12 +146,13 @@ npx eslint --init
Then add a `lint-staged` block in `package.json`:
-"lint-staged": {
- "\*.js": [
-"eslint --fix",
-"prettier --write"
-]
+```json
+{
+ "lint-staged": {
+ "\*.js": ["eslint --fix", "prettier --write"]
+ }
}
+```
With Husky enabled, every commit triggers automatic fixes. Trust me, this saves hours in code review feedback.
diff --git a/apps/www/content/blog/next-js-getting-started.mdx b/apps/www/content/blog/next-js-getting-started.mdx
index 47435a77..a3ee91c4 100644
--- a/apps/www/content/blog/next-js-getting-started.mdx
+++ b/apps/www/content/blog/next-js-getting-started.mdx
@@ -140,15 +140,17 @@ Let's get our hands dirty and build out two pages every website needs: a homepag
And that's literally all it takes. You've just created the `/about` route. Now, let's drop some basic React code into `app/about/page.tsx` so it actually displays something.
+```tsx
// app/about/page.tsx
export default function AboutPage() {
-return (
-
-<main className="p-24">
- <h1 className="text-4xl font-bold">About Us</h1>
- <p className="mt-4">This is the about page for our first Next.js app!</p>
-</main>
-); }
+ return (
+ <main className="p-24">
+ <h1 className="text-4xl font-bold">About Us</h1>
+ <p className="mt-4">This is the about page for our first Next.js app!</p>
+ </main>
+ )
+}
+```
With that code in place, Next.js handles the rest. Fire up your browser and navigate to `localhost:3000/about`, and you'll see your new component rendered on the screen.
@@ -162,8 +164,9 @@ To connect your homepage to the about page, you'll import `Link` from `next/link
Here’s a quick example of how you could add a link to your `app/page.tsx`:
+```tsx
// app/page.tsx
-import Link from 'next/link';
+import Link from "next/link"
export default function HomePage() {
return (
@@ -177,6 +180,7 @@ export default function HomePage() {
</main>
)
}
+```
The `href` prop tells the `<Link>` component where to go. When a user clicks it, Next.js fetches what it needs in the background and swaps out the view without that classic white flash of a page refresh.
@@ -211,33 +215,35 @@ One of the coolest things about Server Components is the ability to just drop `a
Let's look at a practical example. Say you want to pull in a list of products from a public REST API and display them on a page. Here’s how you could fetch and render that data right inside a page component.
+```tsx
// app/products/page.tsx
async function getProducts() {
-const res = await fetch('https://dummyjson.com/products');
-if (!res.ok) {
-// This will activate the closest `error.js` Error Boundary
-throw new Error('Failed to fetch data');
-}
-return res.json();
+ const res = await fetch("https://dummyjson.com/products")
+ if (!res.ok) {
+ // This will activate the closest `error.js` Error Boundary
+ throw new Error("Failed to fetch data")
+ }
+ return res.json()
}
export default async function ProductsPage() {
- const data = await getProducts();
+ const data = await getProducts()
-return (
-
-<main className="p-24">
- <h1 className="mb-8 text-4xl font-bold">Our Products</h1>
- <div className="grid grid-cols-1 gap-6 md:grid-cols-3">
- {data.products.map((product) => (
- <div key={product.id} className="rounded-lg border p-4">
- <h2 className="text-xl font-semibold">{product.title}</h2>
- <p className="mt-2 text-gray-600">{product.description}</p>
+ return (
+ <main className="p-24">
+ <h1 className="mb-8 text-4xl font-bold">Our Products</h1>
+ <div className="grid grid-cols-1 gap-6 md:grid-cols-3">
+ {data.products.map((product) => (
+ <div key={product.id} className="rounded-lg border p-4">
+ <h2 className="text-xl font-semibold">{product.title}</h2>
+ <p className="mt-2 text-gray-600">{product.description}</p>
+ </div>
+ ))}
</div>
- ))}
- </div>
-</main>
-); }
+ </main>
+ )
+}
+```
Did you catch it? `ProductsPage` is an `async` function. That one keyword lets you `await` the `getProducts()` call right before returning your JSX. It’s an incredibly clean and direct way to handle what used to be a much more complicated task.
diff --git a/apps/www/content/blog/next-js-project-structure.mdx b/apps/www/content/blog/next-js-project-structure.mdx
index 2cadc782..a6e5e06f 100644
--- a/apps/www/content/blog/next-js-project-structure.mdx
+++ b/apps/www/content/blog/next-js-project-structure.mdx
@@ -219,17 +219,19 @@ By making a small tweak to your `tsconfig.json` file, you can set up absolute im
Here’s the setup I use in almost every project:
+```json
{
-"compilerOptions": {
-"baseUrl": ".",
-"paths": {
-"@/components/_": ["components/_"],
-"@/lib/_": ["lib/_"],
-"@/hooks/_": ["hooks/_"],
-"@/styles/_": ["styles/_"]
-}
-}
+ "compilerOptions": {
+ "baseUrl": ".",
+ "paths": {
+ "@/components/_": ["components/_"],
+ "@/lib/_": ["lib/_"],
+ "@/hooks/_": ["hooks/_"],
+ "@/styles/_": ["styles/_"]
+ }
+ }
}
+```
With that in place, our horrible import from before transforms into this beauty: `import Button from '@/components/ui/Button'`. Suddenly, it doesn't matter how deeply nested your component is. The path is always the same, making refactoring a breeze instead of a nightmare.
diff --git a/apps/www/content/blog/next-js-tailwind.mdx b/apps/www/content/blog/next-js-tailwind.mdx
index 027353c6..39e6376d 100644
--- a/apps/www/content/blog/next-js-tailwind.mdx
+++ b/apps/www/content/blog/next-js-tailwind.mdx
@@ -70,15 +70,17 @@ If you ever need a more detailed refresher on the setup, we've got a full guide
Once the script finishes, `cd` into your new project directory (`my-next-tailwind-app`). The first file you'll want to get familiar with is `tailwind.config.ts`. This is the heart of your Tailwind setup, and its `content` array is where the real magic happens.
+```ts
const config = {
-content: [
-'./src/pages/**/*.{js,ts,jsx,tsx,mdx}',
-'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
-'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
-],
-// ... other configurations
+ content: [
+ "./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
+ "./src/components/**/*.{js,ts,jsx,tsx,mdx}",
+ "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
+ ],
+ // ... other configurations
}
export default config
+```
This `content` array is crucial. It tells Tailwind's Just-In-Time (JIT) compiler exactly which files to scan for class names. This is how Tailwind performs its "tree-shaking," purging every single unused style from your final CSS bundle. The result? A tiny, production-ready stylesheet.
@@ -119,18 +121,20 @@ The `content` array tells Tailwind's Just-in-Time (JIT) engine exactly which fil
During the build process, Tailwind analyzes your code and ruthlessly purges every single style you haven't used. The result? Your final CSS bundle size shrinks dramatically, often to just a few kilobytes. It's a massive win for your site's loading speed.
+```ts
// tailwind.config.js
module.exports = {
-content: [
-'./src/pages/**/*.{js,ts,jsx,tsx,mdx}',
-'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
-'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
-],
-theme: {
-extend: {},
-},
-plugins: [],
+ content: [
+ "./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
+ "./src/components/**/*.{js,ts,jsx,tsx,mdx}",
+ "./src/app/**/*.{js,ts,jsx,tsx,mdx}",
+ ],
+ theme: {
+ extend: {},
+ },
+ plugins: [],
}
+```
### Extending the Default Theme
@@ -141,22 +145,24 @@ Want to add a primary brand color? It's simple:
- **Define a new color:** Just add it inside the `theme.extend.colors` object.
- **Use it everywhere:** You can now call it directly in your components, like `className="bg-brand-primary"`.
+```ts
// tailwind.config.js
module.exports = {
-// ...
-theme: {
-extend: {
-colors: {
-'brand-primary': '#4F46E5',
-'brand-secondary': '#10B981',
-},
-fontFamily: {
-sans: ['Inter', 'sans-serif'],
-},
-},
-},
-// ...
+ // ...
+ theme: {
+ extend: {
+ colors: {
+ "brand-primary": "#4F46E5",
+ "brand-secondary": "#10B981",
+ },
+ fontFamily: {
+ sans: ["Inter", "sans-serif"],
+ },
+ },
+ },
+ // ...
}
+```
> By using `extend`, you get the best of both worlds: you’re adding your custom design tokens on top of Tailwind's robust default set, not replacing them entirely.
@@ -176,26 +182,28 @@ The golden rule of modern web design is to start small. Building for mobile firs
Go ahead and create a new component file, `HeroSection.jsx`, and drop in this initial structure.
+```tsx
const HeroSection = () => {
-return (
-
-<section className="bg-gray-900 text-white">
- <div className="container mx-auto flex flex-col items-center px-6 py-16 text-center">
- <h1 className="text-4xl font-extrabold tracking-tight">
- Build Modern UIs with Next.js and Tailwind
- </h1>
- <p className="mt-4 max-w-2xl text-lg text-gray-300">
- Combine the power of React with the speed of utility-first CSS to create
- beautiful, high-performance web applications.
- </p>
- <button className="mt-8 rounded-md bg-indigo-600 px-8 py-3 font-semibold hover:bg-indigo-500 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none">
- Get Started
- </button>
- </div>
-</section>
-); };
+ return (
+ <section className="bg-gray-900 text-white">
+ <div className="container mx-auto flex flex-col items-center px-6 py-16 text-center">
+ <h1 className="text-4xl font-extrabold tracking-tight">
+ Build Modern UIs with Next.js and Tailwind
+ </h1>
+ <p className="mt-4 max-w-2xl text-lg text-gray-300">
+ Combine the power of React with the speed of utility-first CSS to
+ create beautiful, high-performance web applications.
+ </p>
+ <button className="mt-8 rounded-md bg-indigo-600 px-8 py-3 font-semibold hover:bg-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
+ Get Started
+ </button>
+ </div>
+ </section>
+ )
+}
export default HeroSection
+```
In that snippet, we've got a basic hero with a headline, some descriptive text, and a call-to-action button. Notice how we're already handling user interaction with classes like **`hover:bg-indigo-500`** and the `focus:` utilities for accessibility. These aren't afterthoughts in Tailwind; they're baked right in.
@@ -226,7 +234,7 @@ Here’s the updated code with those responsive classes added in:
Combine the power of React with the speed of utility-first CSS to create
beautiful, high-performance web applications.
</p>
- <button className="mt-8 rounded-md bg-indigo-600 px-8 py-3 font-semibold hover:bg-indigo-500 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none">
+ <button className="mt-8 rounded-md bg-indigo-600 px-8 py-3 font-semibold hover:bg-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
Get Started
</button>
</div>
@@ -253,31 +261,33 @@ For managing this exact kind of complexity, **`cva`** (Class Variance Authority)
Let's say you're building a standard `Button` component. With `cva`, you can define all its looks in one spot:
+```tsx
import { cva } from "class-variance-authority"
const buttonStyles = cva(
-'font-semibold rounded-lg transition-colors focus:outline-none focus:ring-2',
-{
-variants: {
-intent: {
-primary: 'bg-indigo-600 text-white hover:bg-indigo-500',
-secondary: 'bg-gray-200 text-gray-800 hover:bg-gray-300',
-},
-size: {
-small: 'text-sm px-3 py-1',
-medium: 'text-base px-5 py-2',
-},
-},
-defaultVariants: {
-intent: 'primary',
-size: 'medium',
-},
-}
-);
+ "font-semibold rounded-lg transition-colors focus:outline-none focus:ring-2",
+ {
+ variants: {
+ intent: {
+ primary: "bg-indigo-600 text-white hover:bg-indigo-500",
+ secondary: "bg-gray-200 text-gray-800 hover:bg-gray-300",
+ },
+ size: {
+ small: "text-sm px-3 py-1",
+ medium: "text-base px-5 py-2",
+ },
+ },
+ defaultVariants: {
+ intent: "primary",
+ size: "medium",
+ },
+ }
+)
export const Button = ({ intent, size, className, ...props }) => (
<button className={buttonStyles({ intent, size, className })} {...props} />
)
+```
By pulling all that style logic out, the component itself stays incredibly clean. You can just pass it props like `<Button intent="secondary" size="small">Click Me</Button>` instead of wrestling with a tangled mess of conditional class strings.
@@ -294,18 +304,20 @@ Finally, always keep performance in mind. This is especially true for large, hea
For instance, you can dynamically import a complex chart component that isn't needed right away:
+```tsx
import dynamic from "next/dynamic"
-const HeavyChartComponent = dynamic(() => import('../components/HeavyChart'));
+const HeavyChartComponent = dynamic(() => import("../components/HeavyChart"))
function MyPage() {
-return (
-
-<div>
- {/* Other content */}
- <HeavyChartComponent />
-</div>
-); }
+ return (
+ <div>
+ {/* Other content */}
+ <HeavyChartComponent />
+ </div>
+ )
+}
+```
This simple change ensures the code for `HeavyChartComponent` is only downloaded and run when it's actually needed. It's a small tweak that can make a huge difference in your initial page load time, keeping your application feeling snappy even as it grows in complexity.
diff --git a/apps/www/content/blog/search-input-with-icon.mdx b/apps/www/content/blog/search-input-with-icon.mdx
index 79da5066..4db66566 100644
--- a/apps/www/content/blog/search-input-with-icon.mdx
+++ b/apps/www/content/blog/search-input-with-icon.mdx
@@ -71,10 +71,9 @@ This lets us pin the icon exactly where we want it. We'll use `top`, `left`, and
Let's see how it all comes together in a complete example.
+```html
<div className="search-container">
- <label htmlFor="main-search" className="sr-only">
- Search
- </label>
+ <label htmlFor="main-search" className="sr-only"> Search </label>
<input
type="search"
id="main-search"
@@ -97,7 +96,9 @@ Let's see how it all comes together in a complete example.
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</div>
+```
+```css
.search-container {
position: relative;
width: 300px;
@@ -138,6 +139,7 @@ clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
+```
This code gives you a clean, accessible **search input with icon**, complete with intuitive focus states and a properly handled label. It's a reliable pattern that you can use anywhere.
@@ -169,37 +171,39 @@ Translating this into a React component is a piece of cake. We just need to swap
Here's how you can build a sleek search input with an icon using Tailwind CSS in a React environment.
+```tsx
function SearchInput() {
-return (
-
-<div className="relative w-full max-w-xs">
- <label htmlFor="tailwind-search" className="sr-only">
- Search
- </label>
- <div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
- <svg
- className="h-5 w-5 text-gray-400"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 20 20"
- fill="currentColor"
- aria-hidden="true"
- >
- <path
- fillRule="evenodd"
- d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z"
- clipRule="evenodd"
+ return (
+ <div className="relative w-full max-w-xs">
+ <label htmlFor="tailwind-search" className="sr-only">
+ Search
+ </label>
+ <div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
+ <svg
+ className="h-5 w-5 text-gray-400"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ fillRule="evenodd"
+ d="M9 3.5a5.5 5.5 0 100 11 5.5 5.5 0 000-11zM2 9a7 7 0 1112.452 4.391l3.328 3.329a.75.75 0 11-1.06 1.06l-3.329-3.328A7 7 0 012 9z"
+ clipRule="evenodd"
+ />
+ </svg>
+ </div>
+ <input
+ id="tailwind-search"
+ name="search"
+ type="search"
+ placeholder="Search..."
+ className="block w-full rounded-md border-0 bg-gray-100 py-2 pr-3 pl-10 text-gray-900 ring-1 ring-gray-300 ring-inset placeholder:text-gray-400 focus:ring-2 focus:ring-blue-500 focus:ring-inset sm:text-sm"
/>
- </svg>
- </div>
- <input
- id="tailwind-search"
- name="search"
- type="search"
- placeholder="Search..."
- className="block w-full rounded-md border-0 bg-gray-100 py-2 pr-3 pl-10 text-gray-900 ring-1 ring-gray-300 ring-inset placeholder:text-gray-400 focus:ring-2 focus:ring-blue-500 focus:ring-inset sm:text-sm"
- />
-</div>
-); }
+ </div>
+ )
+}
+```
This snippet is all you need. Notice how state variants like `focus:` are handled inline, making the styling logic immediately obvious. This kind of maintainability is a huge reason why so many developers gravitate toward utility-first frameworks for building robust component libraries.
@@ -245,41 +249,47 @@ Alright, let's put all the pieces together. We'll create a functional component
Here’s a practical, production-ready example that combines React, TypeScript, and [Tailwind CSS](https://tailwindcss.com/).
+```tsx
import React, { useState } from "react"
// Define the component's props with TypeScript
interface SearchInputProps {
-icon: React.ReactNode;
-placeholder?: string;
-onSearchChange: (value: string) => void;
+ icon: React.ReactNode
+ placeholder?: string
+ onSearchChange: (value: string) => void
}
-const SearchInput: React.FC<SearchInputProps> = ({ icon, placeholder = "Search...", onSearchChange }) => {
-const [query, setQuery] = useState('');
-
-const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
-const newValue = event.target.value;
-setQuery(newValue);
-onSearchChange(newValue);
-};
-
-return (
-
-<div className="relative w-full max-w-sm">
- <div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
- {icon}
- </div>
- <input
- type="search"
- value={query}
- onChange={handleChange}
- placeholder={placeholder}
- className="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 pl-10 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500"
- />
-</div>
-); };
+const SearchInput: React.FC<SearchInputProps> = ({
+ icon,
+ placeholder = "Search...",
+ onSearchChange,
+}) => {
+ const [query, setQuery] = useState("")
+
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
+ const newValue = event.target.value
+ setQuery(newValue)
+ onSearchChange(newValue)
+ }
+
+ return (
+ <div className="relative w-full max-w-sm">
+ <div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
+ {icon}
+ </div>
+ <input
+ type="search"
+ value={query}
+ onChange={handleChange}
+ placeholder={placeholder}
+ className="block w-full rounded-lg border border-gray-300 bg-gray-50 p-2.5 pl-10 text-sm text-gray-900 focus:border-blue-500 focus:ring-blue-500"
+ />
+ </div>
+ )
+}
export default SearchInput
+```
And just like that, we have a self-contained component ready to be dropped into any project. It provides a consistent and dynamic **search input with an icon** wherever it's needed, without any duplicated code.
diff --git a/apps/www/content/blog/sidebar-for-website.mdx b/apps/www/content/blog/sidebar-for-website.mdx
index 6986a4d3..30ad74d4 100644
--- a/apps/www/content/blog/sidebar-for-website.mdx
+++ b/apps/www/content/blog/sidebar-for-website.mdx
@@ -145,17 +145,18 @@ To bring the sidebar to life, we need to manage its state. While the `isOpen` pr
For example, a parent component would typically manage the open/closed state like this:
-const [isSidebarOpen, setSidebarOpen] = useState(false);
+```tsx
+const [isSidebarOpen, setSidebarOpen] = useState(false)
return (
-
-<div>
- <button onClick={() => setSidebarOpen(true)}>Open Menu</button>
- <Sidebar isOpen={isSidebarOpen} onClose={() => setSidebarOpen(false)}>
- {/* Navigation links go here */}
- </Sidebar>
-</div>
-);
+ <div>
+ <button onClick={() => setSidebarOpen(true)}>Open Menu</button>
+ <Sidebar isOpen={isSidebarOpen} onClose={() => setSidebarOpen(false)}>
+ {/* Navigation links go here */}
+ </Sidebar>
+ </div>
+)
+```
This pattern is called a **controlled component**. The parent has full authority over the sidebar's visibility, which makes state management crystal clear. Inside our sidebar, we can use the `useEffect` hook to handle side effects, like adding an event listener to close the sidebar when the "Escape" key is pressed. It's a small touch, but one that significantly improves keyboard accessibility.
diff --git a/apps/www/content/blog/tailwind-css-button.mdx b/apps/www/content/blog/tailwind-css-button.mdx
index 0dfbe9ce..89358721 100644
--- a/apps/www/content/blog/tailwind-css-button.mdx
+++ b/apps/www/content/blog/tailwind-css-button.mdx
@@ -173,18 +173,21 @@ By giving it precise paths to your template files, you make sure the compiler sc
A typical setup for a Next.js project, for example, might look like this:
+```ts
/** @type {import('tailwindcss').Config} \*/
module.exports = {
-content: [
-'./src/pages/**/_.{js,ts,jsx,tsx,mdx}',
-'./src/components/\*\*/_.{js,ts,jsx,tsx,mdx}',
-'./src/app/\*_/_.{js,ts,jsx,tsx,mdx}',
-],
-theme: {
-extend: {},
-},
-plugins: [],
-};
+ content: [
+ "./src/pages/**/_.{js,ts,jsx,tsx,mdx}",
+ "./src/components/\*\*/_.{js,ts,jsx,tsx,mdx}",
+ "./src/app/\*_/_.{js,ts,jsx,tsx,mdx}",
+ ],
+ theme: {
+ extend: {},
+ },
+ plugins: [],
+}
+```
+
Keeping these paths clean and accurate is a simple but incredibly powerful way to guarantee a lean, optimized build every time.
### The HTML vs. CSS Performance Question
@@ -215,6 +218,7 @@ We'll set up our component to accept props for `variant` (like `primary` or `sec
Here’s the basic skeleton:
+```tsx
// A basic structure for a reusable Button component
function Button({ children, variant = 'primary', size = 'md', ...props }) {
// We'll add class logic here
@@ -228,6 +232,7 @@ return (
</button>
);
}
+```
This is our starting point. We've got a set of base styles that apply to _every_ button. Now, we just need a clean way to manage the classes that change based on the `variant` and `size` props we pass in.
@@ -243,33 +248,44 @@ Let’s bring these tools together to flesh out our component's logic.
Here’s the finished `Button` component, fully equipped to handle variants and sizes gracefully. If you're looking for more real-world examples, exploring a high-quality **[Tailwind CSS component library](https://magicui.design/blog/tailwind-css-component-library)** can show you just how powerful this pattern is.
+```tsx
import { clsx } from "clsx"
import { twMerge } from "tailwind-merge"
-function Button({ children, variant = 'primary', size = 'md', className, ...props }) {
-const baseClasses = 'font-semibold rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors';
-
-const variantClasses = {
-primary: 'bg-indigo-600 text-white hover:bg-indigo-700 focus:ring-indigo-500',
-secondary: 'bg-gray-200 text-gray-800 hover:bg-gray-300 focus:ring-gray-500',
-};
-
-const sizeClasses = {
-sm: 'py-1 px-3 text-sm',
-md: 'py-2 px-4 text-base',
-lg: 'py-3 px-6 text-lg',
-};
-
-const finalClasses = twMerge(
-clsx(baseClasses, variantClasses[variant], sizeClasses[size], className)
-);
-
-return (
-
-<button className={finalClasses} {...props}>
- {children}
-</button>
-); }
+function Button({
+ children,
+ variant = "primary",
+ size = "md",
+ className,
+ ...props
+}) {
+ const baseClasses =
+ "font-semibold rounded-lg shadow-md focus:outline-none focus:ring-2 focus:ring-offset-2 transition-colors"
+
+ const variantClasses = {
+ primary:
+ "bg-indigo-600 text-white hover:bg-indigo-700 focus:ring-indigo-500",
+ secondary:
+ "bg-gray-200 text-gray-800 hover:bg-gray-300 focus:ring-gray-500",
+ }
+
+ const sizeClasses = {
+ sm: "py-1 px-3 text-sm",
+ md: "py-2 px-4 text-base",
+ lg: "py-3 px-6 text-lg",
+ }
+
+ const finalClasses = twMerge(
+ clsx(baseClasses, variantClasses[variant], sizeClasses[size], className)
+ )
+
+ return (
+ <button className={finalClasses} {...props}>
+ {children}
+ </button>
+ )
+}
+```
And there you have it. This reusable `Button` component is now the foundation for a scalable, maintainable UI system. You can call it anywhere in your app, pass a few props, and get a perfectly styled, consistent button every time.
diff --git a/apps/www/content/blog/tailwind-css-themes.mdx b/apps/www/content/blog/tailwind-css-themes.mdx
index d92b8478..44fa9083 100644
--- a/apps/www/content/blog/tailwind-css-themes.mdx
+++ b/apps/www/content/blog/tailwind-css-themes.mdx
@@ -81,17 +81,19 @@ So where does the real magic happen? It's when Tailwind takes these definitions
Let's say we want to add a custom primary color to our configuration:
+```tsx
// tailwind.config.js
module.exports = {
-theme: {
-extend: {
-colors: {
-primary: '#3490dc',
-},
-},
-},
-plugins: [],
+ theme: {
+ extend: {
+ colors: {
+ primary: "#3490dc",
+ },
+ },
+ },
+ plugins: [],
}
+```
With just that simple addition, you've unlocked a whole set of brand-new utilities. You can now jump into your HTML and use classes like `bg-primary`, `text-primary`, and `border-primary`. This direct link between your config and your code is what makes Tailwind so incredibly powerful for theming. It ensures you’re always pulling from approved brand colors, which means no more guesswork or random one-off hex codes.
@@ -125,29 +127,32 @@ A polished theme almost always needs custom typography and a sophisticated appro
To bring in custom fonts, you can drop a standard `@font-face` rule into your main CSS file and then give it a name in your `tailwind.config.js`.
-/_ In your main CSS file _/
-@font-face {
-font-family: 'Inter';
-src: url('/fonts/Inter-Regular.woff2') format('woff2');
-font-weight: 400;
-font-style: normal;
+```css
+/_ In your main CSS file _/ @font-face {
+ font-family: "Inter";
+ src: url("/fonts/Inter-Regular.woff2") format("woff2");
+ font-weight: 400;
+ font-style: normal;
}
+```
From there, you just wire it up in your theme configuration to make it available as a utility class, like `font-display`. This keeps your typography consistent and lets you apply it with the same utility-first workflow you use for everything else.
In the same way, you can define more specific responsive breakpoints for trickier layouts. While Tailwind's defaults are a great starting point, your design might need to target some non-standard screen sizes.
+```tsx
// tailwind.config.js
module.exports = {
-theme: {
-extend: {
-screens: {
-'xs': '480px',
-'3xl': '1920px',
-},
-},
-},
+ theme: {
+ extend: {
+ screens: {
+ xs: "480px",
+ "3xl": "1920px",
+ },
+ },
+ },
}
+```
Just like that, you’ve created new `xs:` and `3xl:` prefixes, giving you much finer control over how your layout snaps into place across a wider range of devices.
@@ -157,10 +162,12 @@ Sometimes you need a little escape hatch. Maybe you need to access your design t
The `theme()` function is your bridge between your config file and your custom CSS. It lets you pull any design token from `tailwind.config.js` right into a CSS rule. It's perfect for styling complex components that need a bit more than just utility classes.
+```css
.custom-component {
-background-color: theme('colors.primary');
-padding: theme('spacing.4');
+ background-color: theme("colors.primary");
+ padding: theme("spacing.4");
}
+```
This ensures that even your custom CSS stays perfectly in sync with your design system.
@@ -189,16 +196,15 @@ Two of the most indispensable official plugins are:
Getting them set up is a breeze. First, pull the package in with npm, then simply register it in the `plugins` array of your `tailwind.config.js` file.
+```tsx
// tailwind.config.js
module.exports = {
-theme: {
-// ...
-},
-plugins: [
-require('@tailwindcss/typography'),
-require('@tailwindcss/forms'),
-],
+ theme: {
+ // ...
+ },
+ plugins: [require("@tailwindcss/typography"), require("@tailwindcss/forms")],
}
+```
Just like that, you’ve unlocked powerful new features that feel like a natural part of your theme.
diff --git a/apps/www/content/blog/tailwind-landing-page-templates.mdx b/apps/www/content/blog/tailwind-landing-page-templates.mdx
index ae6566c8..fc58c95c 100644
--- a/apps/www/content/blog/tailwind-landing-page-templates.mdx
+++ b/apps/www/content/blog/tailwind-landing-page-templates.mdx
@@ -125,17 +125,16 @@ This command adds two critical files. The `postcss.config.js` file is usually go
Open up `tailwind.config.js` and update the `content` array to point to all your component files.
+```tsx
/** @type {import('tailwindcss').Config} \*/
export default {
-content: [
-"./index.html",
-"./src/**/\*.{js,ts,jsx,tsx}",
-],
-theme: {
-extend: {},
-},
-plugins: [],
+ content: ["./index.html", "./src/**/\*.{js,ts,jsx,tsx}"],
+ theme: {
+ extend: {},
+ },
+ plugins: [],
}
+```
The final piece of the puzzle is telling your app to actually use Tailwind's styles. Find your main CSS file (usually `src/index.css`), clear out whatever is in there, and add these three Tailwind directives.
diff --git a/apps/www/content/blog/text-loading-bar.mdx b/apps/www/content/blog/text-loading-bar.mdx
index 552e9b32..1f02bff4 100644
--- a/apps/www/content/blog/text-loading-bar.mdx
+++ b/apps/www/content/blog/text-loading-bar.mdx
@@ -85,20 +85,22 @@ This layering technique is a classic web design pattern that's been proven effec
A static bar doesn't do much, so we need a little JavaScript to simulate a loading process. This snippet will incrementally update the `width` of our fill element and change the text content to match, creating a fully functional text loading bar.
-const fill = document.querySelector('.progress-bar-fill');
-const text = document.querySelector('.progress-bar-text');
-let progress = 0;
+```js
+const fill = document.querySelector(".progress-bar-fill")
+const text = document.querySelector(".progress-bar-text")
+let progress = 0
const interval = setInterval(() => {
-progress += 10;
-if (progress <= 100) {
-fill.style.width = progress + '%';
-text.textContent = 'Loading... ' + progress + '%';
-} else {
-clearInterval(interval);
-text.textContent = 'Complete!';
-}
-}, 500);
+ progress += 10
+ if (progress <= 100) {
+ fill.style.width = progress + "%"
+ text.textContent = "Loading... " + progress + "%"
+ } else {
+ clearInterval(interval)
+ text.textContent = "Complete!"
+ }
+}, 500)
+```
This simple update loop gives you a complete, working example. You now have a solid, framework-agnostic component that’s easy to drop into any project and adapt as needed.