@suyashjaiswal/chaitailwind
v1.0.4
Published
A lightweight, runtime CSS utility framework inspired by the warmth of chai. 200+ utilities, zero build step, pure vanilla JavaScript.
Maintainers
Readme
ChaiTailwind ☕
A lightweight, runtime CSS utility framework built with vanilla JavaScript. ChaiTailwind converts utility class names into inline styles dynamically in the browser - no build step required.
🚀 Live Demo | 📦 NPM Package | 📖 Documentation
What It Does
ChaiTailwind scans your HTML for classes starting with chai-, parses them, and applies corresponding inline styles. It's like Tailwind CSS, but works at runtime using JavaScript instead of build-time processing.
Example:
<div class="chai-p-20 chai-bg-indigo chai-color-white chai-rounded-lg">
Hello World
</div>Becomes:
<div class="chai-p-20 chai-bg-indigo chai-color-white chai-rounded-lg" style="padding: 20px; background-color: #6366f1; color: #ffffff; border-radius: 8px;">
Hello World
</div>Features
✅ Zero dependencies - Pure vanilla JavaScript ✅ No build step - Works directly in the browser ✅ 200+ utilities - Comprehensive set of utility classes ✅ Auto-caching - Computed styles are cached for performance ✅ Reactive - Watches DOM for new elements and class changes ✅ Small footprint - ~15KB unminified
Installation
NPM
npm install @suyashjaiswal/chaitailwindCDN
<script src="https://cdn.jsdelivr.net/npm/@suyashjaiswal/chaitailwind@1/dist/chaitailwind.min.js"></script>Manual Download
Download the files and include them in order:
<script src="path/to/styles.js"></script>
<script src="path/to/core.js"></script>
<script src="path/to/main.js"></script>Quick Start
Complete HTML Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ChaiTailwind Example</title>
</head>
<body>
<!-- Your content with chai- utility classes -->
<div class="chai-bg-blue chai-color-white chai-p-24 chai-rounded-xl">
<h2 class="chai-text-2xl chai-font-bold chai-mb-16">Card Title</h2>
<p class="chai-text-base">Card content goes here.</p>
</div>
<!-- Include ChaiTailwind at the end of body -->
<script src="https://cdn.jsdelivr.net/npm/@suyashjaiswal/chaitailwind@1/dist/chaitailwind.min.js"></script>
</body>
</html>Important: Place the script at the end of the <body> tag so that all HTML elements are loaded before ChaiTailwind initializes.
Installation Options
Via CDN (Recommended for quick start):
<script src="https://cdn.jsdelivr.net/npm/@suyashjaiswal/chaitailwind@1/dist/chaitailwind.min.js"></script>Via NPM:
npm install @suyashjaiswal/chaitailwind<script src="node_modules/@suyashjaiswal/chaitailwind/dist/chaitailwind.min.js"></script>That's it! The framework automatically applies styles to any element with chai- classes.
🎨 Live Demo
See ChaiTailwind in action with a beautiful, chai-themed landing page:
👉 https://chai-tailwind-eta.vercel.app/
The demo showcases:
- ☕ Warm parchment color palette inspired by chai
- 🎨 Glassmorphic navigation with blur effects
- ⚡ Animated fade-in effects on scroll
- 🎯 200+ utilities in use across the entire page
- 📱 Fully responsive design
- 🔥 Steam animation effects
- ✨ Hover interactions and card lift effects
The entire landing page is built using only ChaiTailwind utilities - no custom CSS! View the source code in index.html to see how it's done.
Complete Utility Reference
🎨 Colors
13 Built-in Colors:
red blue green yellow purple pink indigo gray black white orange teal cyan
- Text:
chai-color-{color}orchai-text-{color} - Background:
chai-bg-{color} - Border:
chai-border-{color}
<div class="chai-bg-indigo chai-color-white">Indigo background, white text</div>📏 Spacing
Padding:
chai-p-{value}- All sideschai-pt-{value}chai-pr-{value}chai-pb-{value}chai-pl-{value}- Individual sideschai-px-{value}- Horizontal (left + right)chai-py-{value}- Vertical (top + bottom)
Margin:
chai-m-{value}- All sides (useautofor centering)chai-mt-{value}chai-mr-{value}chai-mb-{value}chai-ml-{value}- Individual sideschai-mx-{value}- Horizontal (usechai-mx-autoto center)chai-my-{value}- Vertical
<div class="chai-p-20 chai-mb-16">Padded box with bottom margin</div>
<div class="chai-mx-auto chai-w-600">Centered box</div>✍️ Typography
Font Size:
chai-text-xs(12px) throughchai-text-5xl(48px)
Font Weight:
chai-font-thin(100) throughchai-font-black(900)
Text Alignment:
chai-text-leftchai-text-centerchai-text-rightchai-text-justify
Text Transform:
chai-text-uppercasechai-text-lowercasechai-text-capitalize
Text Decoration:
chai-text-underlinechai-text-line-throughchai-text-none
Line Height:
chai-leading-nonechai-leading-tightchai-leading-normalchai-leading-relaxedchai-leading-loose
Letter Spacing:
chai-tracking-tighterthroughchai-tracking-widest
<h1 class="chai-text-4xl chai-font-bold chai-text-center chai-text-uppercase">
Bold Centered Heading
</h1>📐 Borders
Border Width:
chai-border-{value}- All sides (e.g.,chai-border-2)chai-border-t-{value}chai-border-r-{value}chai-border-b-{value}chai-border-l-{value}
Border Style:
chai-border-solidchai-border-dashedchai-border-dottedchai-border-doublechai-border-none
Border Radius:
chai-rounded-nonechai-rounded-smchai-rounded-mdchai-rounded-lgchai-rounded-xlchai-rounded-2xlchai-rounded-3xlchai-rounded-full
<div class="chai-border-2 chai-border-solid chai-border-gray chai-rounded-lg">
Bordered box
</div>📦 Layout & Display
Display:
chai-flexchai-gridchai-blockchai-inlinechai-inline-blockchai-inline-flexchai-hidden
Flexbox Direction:
chai-flex-rowchai-flex-colchai-flex-row-reversechai-flex-col-reverse
Flexbox Wrap:
chai-flex-wrapchai-flex-nowrapchai-flex-wrap-reverse
Justify Content:
chai-justify-startchai-justify-centerchai-justify-endchai-justify-betweenchai-justify-aroundchai-justify-evenly
Align Items:
chai-items-startchai-items-centerchai-items-endchai-items-stretchchai-items-baseline
Flex Sizing:
chai-flex-1chai-flex-autochai-flex-initialchai-flex-nonechai-grow-{value}chai-shrink-{value}
Gap:
chai-gap-{value}chai-gap-x-{value}chai-gap-y-{value}
<div class="chai-flex chai-justify-between chai-items-center chai-gap-16">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>🎯 Grid
chai-grid-cols-{n}- Grid with n columnschai-grid-rows-{n}- Grid with n rowschai-col-span-{n}- Span n columnschai-row-span-{n}- Span n rows
<div class="chai-grid chai-grid-cols-3 chai-gap-16">
<div>1</div>
<div class="chai-col-span-2">2 (spans 2 columns)</div>
</div>📐 Sizing
Width:
chai-w-{value}- Width in pixelschai-w-fullchai-w-screenchai-w-autochai-w-minchai-w-maxchai-w-fit
Height:
chai-h-{value}- Height in pixelschai-h-fullchai-h-screenchai-h-autochai-h-minchai-h-maxchai-h-fit
Min/Max Width:
chai-min-w-{value}- Minimum widthchai-max-w-xsthroughchai-max-w-7xl- Responsive max widthschai-max-w-fullchai-max-w-minchai-max-w-maxchai-max-w-fit
Min/Max Height:
chai-min-h-{value}chai-max-h-{value}
<div class="chai-w-full chai-max-w-2xl chai-mx-auto">
Responsive centered container
</div>📍 Position
Position Type:
chai-relativechai-absolutechai-fixedchai-stickychai-static
Position Offsets:
chai-top-{value}chai-right-{value}chai-bottom-{value}chai-left-{value}chai-inset-{value}- All sides- Use
autofor auto positioning
Z-Index:
chai-z-{value}
<div class="chai-relative chai-h-200">
<div class="chai-absolute chai-top-10 chai-right-10 chai-z-10">
Positioned element
</div>
</div>✨ Effects
Opacity:
chai-opacity-{0-100}- e.g.,chai-opacity-50= 50% opacity
Shadow:
chai-shadow-smchai-shadow-mdchai-shadow-lgchai-shadow-xlchai-shadow-2xlchai-shadow-none
<div class="chai-shadow-lg chai-opacity-90">
Box with shadow and slight transparency
</div>📜 Overflow
chai-overflow-autochai-overflow-hiddenchai-overflow-visiblechai-overflow-scrollchai-overflow-x-autochai-overflow-x-hiddenchai-overflow-y-autochai-overflow-y-hidden
🖱️ Interactions
Cursor:
chai-cursor-pointerchai-cursor-defaultchai-cursor-not-allowedchai-cursor-waitchai-cursor-textchai-cursor-move
Pointer Events:
chai-pointer-events-nonechai-pointer-events-auto
User Select:
chai-select-nonechai-select-textchai-select-allchai-select-auto
🎬 Transitions & Transforms
Transitions:
chai-transition-nonechai-transition-allchai-transition-colorschai-transition-opacitychai-transition-shadowchai-transition-transformchai-duration-{ms}- Duration in milliseconds
Transforms:
chai-rotate-{deg}- Rotate in degreeschai-scale-{percent}- Scale (e.g.,chai-scale-110= 1.1x)chai-scale-x-{percent}chai-scale-y-{percent}chai-translate-x-{px}chai-translate-y-{px}
🖼️ Background
chai-bg-coverchai-bg-containchai-bg-centerchai-bg-topchai-bg-bottomchai-bg-leftchai-bg-rightchai-bg-no-repeatchai-bg-repeat
📝 Text Utilities
Whitespace:
chai-whitespace-normalchai-whitespace-nowrapchai-whitespace-prechai-whitespace-pre-wrap
Word Break:
chai-break-normalchai-break-wordschai-break-all
Vertical Align:
chai-align-baselinechai-align-topchai-align-middlechai-align-bottom
List Style:
chai-list-nonechai-list-discchai-list-decimal
🖼️ Object Fit
chai-object-coverchai-object-containchai-object-fillchai-object-none
Real-World Examples
Button
<button class="chai-bg-blue chai-color-white chai-px-24 chai-py-12 chai-rounded-md chai-font-semibold chai-cursor-pointer chai-transition-all" style="border: none;">
Click Me
</button>Card Component
<div class="chai-bg-white chai-p-24 chai-rounded-xl chai-shadow-lg">
<h3 class="chai-text-xl chai-font-bold chai-mb-12">Card Title</h3>
<p class="chai-text-base chai-color-gray chai-mb-16">Card description text.</p>
<button class="chai-bg-indigo chai-color-white chai-px-16 chai-py-8 chai-rounded-md">
Action
</button>
</div>Responsive Container
<div class="chai-max-w-4xl chai-mx-auto chai-px-32 chai-py-64">
<h1 class="chai-text-4xl chai-font-bold chai-mb-24">Page Title</h1>
<p class="chai-text-lg chai-color-gray">Content goes here...</p>
</div>Flex Layout
<div class="chai-flex chai-flex-col chai-gap-16">
<div class="chai-flex chai-justify-between chai-items-center">
<span>Label</span>
<span class="chai-font-bold">Value</span>
</div>
</div>Color Palette Reference
| Color | Hex | Color | Hex | |----------|---------|----------|---------| | red | #ef4444 | orange | #f97316 | | blue | #3b82f6 | teal | #14b8a6 | | green | #10b981 | cyan | #06b6d4 | | yellow | #f59e0b | gray | #6b7280 | | purple | #a855f7 | black | #000000 | | pink | #ec4899 | white | #ffffff | | indigo | #6366f1 | | |
How It Works Internally
- Initialization: On page load, scans DOM for elements with
chai-classes - Parsing: Extracts class names and maps them to CSS properties
- Caching: Stores computed styles in a Map for reuse
- Application: Applies styles as inline CSS
- Observation: Watches DOM for new elements or class changes using MutationObserver
Limitations
⚠️ This is a runtime framework, which means:
- Styles are applied as inline CSS (lower specificity than stylesheets)
- All styles are computed at runtime (slight performance cost)
- No PurgeCSS-like optimization (but caching helps)
- Not suitable for very large-scale applications
- No pseudo-classes or media queries support (use regular CSS for these)
Performance
- Caching: Computed styles are cached in a Map
- One-time processing: Elements are marked to prevent reprocessing
- Mutation Observer: Efficiently watches for DOM changes
- Fast selectors: Uses attribute selectors for quick element finding
For small to medium projects, performance is excellent. For large applications, consider a build-time solution like Tailwind CSS.
Use Cases
✅ Good for:
- Prototypes and MVPs
- Small to medium projects
- Projects without build tooling
- Learning utility-first CSS
- Quick demos and experiments
❌ Not ideal for:
- Very large production applications
- Projects requiring pseudo-classes/media queries in utility form
- Performance-critical applications with thousands of elements
Browser Support
Works in all modern browsers supporting:
- ES6+ JavaScript (Map, arrow functions, destructuring)
- MutationObserver API
- CSS inline styles
Project Structure
Chai-Tailwind/
├── styles.js # Style definitions and utilities (~15KB)
├── core.js # Core logic: parser, cache, observer (~3.7KB)
├── main.js # Entry point - initializes the framework
├── index.html # Professional demo landing page
└── README.md # This fileLoad Order: scripts must be loaded in order: styles.js → core.js → main.js
Contributing
This is a learning project and experiment in utility-first CSS. Feel free to:
- Open issues for bugs
- Suggest new utilities
- Submit pull requests
- Fork and modify for your needs
Publishing to NPM
If you want to publish updates:
# Build the distribution files
npm run build
# Update version in package.json (follows semver)
npm version patch # for bug fixes
npm version minor # for new features
npm version major # for breaking changes
# Login to npm (first time only)
npm login
# Publish to npm
npm publishLicense
MIT - Use freely in your projects!
Acknowledgments
This project was built as an assignment from Chai aur Code 🙏
Special Thanks to:
- Hitesh Choudhary & Piyush Garg - For the amazing teaching and mentorship at WebDev Cohort 2026
- Chai aur Code Community - For the inspiration and learning environment
- Tailwind CSS - For pioneering the utility-first CSS approach that inspired this project
Built as a learning project to explore runtime CSS frameworks and vanilla JavaScript development.
Built with ☕ and vanilla JavaScript
ChaiTailwind: Utility-first CSS that works in the browser, no build required.
