Tailwind Color is a website that shows all Tailwind CSS colors from version 0 to version 4. You can compare the colors, make gradients, do a contrast test, and copy the values.
Live site: https://tailwind.raflimalik.com
- Overview
- Requirements
- Get started
- Scripts
- Project structure
- Development
- Fix a bug
- Build and self-host
- Fork and customize
- License
- Built with
The site has these pages:
| Page | Path | What it does |
|---|---|---|
| Home | / |
Shows the full palette of one Tailwind CSS version in OKLCH, HEX, HSL, or RGB. |
| Compare | /compare |
Shows two shades side by side. The shades can come from different versions. |
| Gradient | /gradient |
Blends two shades. Shows the result of each interpolation mode. |
| Contrast | /contrast |
Calculates the contrast of text on a background with WCAG 2 and APCA. |
| Gallery | /gallery |
Shows all colors of one version in one grid. Click a swatch to copy its value. |
| License | /license |
Shows the projects that this site uses and their licenses. |
The site also supplies /sitemap.xml for search engines.
Each page keeps its settings in the localStorage of the browser. When you open the site again, the pages show your last settings.
- SvelteKit 2 and Svelte 5
- Tailwind CSS 4
- shadcn-svelte and Bits UI for UI components
- culori for color conversion
- apca-w3 for APCA contrast
- runed to keep settings after a page reload
- Vitest and CodSpeed for benchmarks
@sveltejs/adapter-cloudflarefor deployment
The color values come from the Tailwind CSS source code. The footer of the site has a link to the source file of each version.
- Version 4 uses OKLCH values.
- Version 0 to version 3 use HEX values.
The app changes each value to OKLCH, HEX, HSL, and RGB.
- Node.js 20.19 or a more recent version
- pnpm 12 (the version is in the
packageManagerfield ofpackage.json) - Git
Note
The app does not use environment variables.
-
Clone the repository:
git clone https://github.com/RMalik777/Tailwind-Color.git cd Tailwind-Color -
Enable Corepack. Corepack installs the pnpm version that the project uses.
corepack enable -
Install the dependencies:
pnpm install
-
Start the development server:
pnpm dev
-
Open http://localhost:5173 in your browser.
To open the browser automatically, run pnpm dev --open.
| Command | What it does |
|---|---|
pnpm dev |
Starts the development server with hot reload. |
pnpm build |
Makes a production build. |
pnpm preview |
Serves the production build on your computer. |
pnpm check |
Does a type check of the Svelte and TypeScript files. |
pnpm check:watch |
Does the type check again each time that a file changes. |
pnpm lint |
Does a check of the format (Prettier) and the code (ESLint). |
pnpm format |
Formats all files with Prettier. |
pnpm bench |
Runs the benchmarks in the benches folder. |
benches/ Benchmarks for the color and contrast functions
src/
app.css Tailwind CSS theme and global styles
app.html HTML template
lib/
components/ Navigation bar, footer, and toolbar
custom/ Color picker, shade picker, version select, copy button
ui/ Components from shadcn-svelte
const/ Navigation links and select options
data/
raw-tailwind-color.ts Color values from the Tailwind CSS source code
color.ts Palettes after conversion to all formats
functions/ Color conversion, contrast, gradient, and color history
types/ Shared TypeScript types
routes/ One folder for each page, plus sitemap.xml
static/ Favicon
- Add the color values to
src/lib/data/raw-tailwind-color.tsas a newRawTailwindColor[]export. - Add the version to the
Versiontype insrc/lib/types/color.ts. - Add the new palette to
colorsByVersioninsrc/lib/data/color.ts. - Add the version to
versionOptionsinsrc/lib/const/option.ts. - If the new version uses a different default interpolation for gradients, update
defaultInterpolationinsrc/lib/functions/gradient.ts.
Use processColorFromOklch for OKLCH values. Use processColorFromHex for HEX values.
- Make a folder in
src/routeswith a+page.sveltefile. - Add the page to the
linklist insrc/lib/const/nav.ts. - Add the path to the
pageslist insrc/routes/sitemap.xml/+server.ts.
All pages are prerendered, because src/routes/+layout.ts sets prerender = true.
The files in src/lib/components/ui come from shadcn-svelte. To add a component, run this command:
pnpm dlx shadcn-svelte@latest add <component>The settings for shadcn-svelte are in components.json.
- Prettier formats the code. The settings are in
.prettierrc. - ESLint finds problems in the code. The settings are in
eslint.config.js. - Commit messages use Conventional Commits (for example,
feat:,fix:,style:,ci:).
The benches folder has benchmarks for the color and contrast functions. Run them with this command:
pnpm benchThe CodSpeed workflow (.github/workflows/codspeed.yml) runs the benchmarks on each push to main and on each pull request.
-
Fork the repository on GitHub.
-
Clone your fork.
-
Make a new branch:
git checkout -b fix/short-name
-
Start the development server with
pnpm dev. -
Do the steps that cause the bug.
-
Change the code to remove the bug.
-
If you change a function in
src/lib/functions, add a test file in the same folder (for example,color.test.ts). -
Run the checks:
pnpm check pnpm lint pnpm build
-
If you change a function that has a benchmark, run
pnpm bench. -
Commit your changes.
-
Open a pull request.
Vitest finds the test files with the pattern src/**/*.{test,spec}.{js,ts}. To run the tests, use pnpm exec vitest run.
Tip
The pages keep their settings in localStorage. If a bug occurs only with some settings, clear the site data in your browser. Then do the steps again.
Note
All pages are prerendered to static HTML files. Only /sitemap.xml runs on the server when a request occurs.
The project uses @sveltejs/adapter-cloudflare. Thus, you can deploy it to Cloudflare Pages without a change to the code.
To deploy from Git:
- In the Cloudflare dashboard, make a new Pages project.
- Connect your repository to the project.
- Set the build command to
pnpm build. - Set the build output directory to
.svelte-kit/cloudflare. - Deploy the project.
To deploy from your computer:
pnpm build
pnpm dlx wrangler pages deploy .svelte-kit/cloudflare --project-name <your-project-name>For a different host, change the adapter to @sveltejs/adapter-static.
-
Replace the adapter:
pnpm remove @sveltejs/adapter-cloudflare pnpm add -D @sveltejs/adapter-static
-
In
svelte.config.js, change the import:import adapter from "@sveltejs/adapter-static";
-
In
src/routes/sitemap.xml/+server.ts, add this line. The static adapter can only use prerendered routes.export const prerender = true;
-
Build the site:
pnpm build
-
Upload the
buildfolder to your static host (for example, Netlify, Vercel, GitHub Pages, or an nginx server).
If the site is on a subpath (for example, https://example.com/tailwind-color), set kit.paths.base in svelte.config.js. For more information, refer to the SvelteKit adapter documentation.
Some values in the code are for the site of the author. Change these values in your fork:
| File | Value |
|---|---|
src/routes/sitemap.xml/+server.ts |
The site URL |
src/routes/+layout.svelte |
The page title, description, og:url, og:site_name, and theme-color |
src/routes/+layout.svelte |
The onedollarstats analytics configuration |
src/lib/components/footer.svelte |
The links to the author site, the source code, and "Other works" |
static/favicon.png |
The site icon |
src/app.css |
The theme colors and fonts |
The site sends page views to OneDollarStats. To remove the analytics, do these steps:
-
In
src/routes/+layout.svelte, remove theonedollarstatsimport, theonMountimport, and theonMountblock. -
Remove the package:
pnpm remove onedollarstats
This project uses the MIT License. Tailwind CSS and the other projects that this site uses have their own licenses. The /license page of the site shows them.