Structuring front-end guidance
I think the user's request is moderately complex, so it will benefit from some structure but doesn't need a huge essay. They probably want some guidance along with code snippets, likely in English, focused on front-end development.
I'll respond in markdown for better readability. First, I'll include a quick setup section covering installation and configuration. Then, I'll illustrate design tokens with theme colors, spacing, and fonts.
I should demonstrate creating utility classes using the @apply directive. Finally, I'll show responsive usage in components like buttons, inputs, cards, and navbars, possibly grouping them into functional components for clarity.Creating front-end guidance
I want to keep the response concise while summarizing key patterns effectively. It's important to mention using a "container" class for responsive widths and breakpoints. I should also note customizing the tailwind.config.js for component library prefixes and dark mode. While it's not necessary to set up a build system, I might mention it briefly.
To organize my response, I'll structure it with top-level headings:
- Setup
- Design tokens in
tailwind.config.js
- Component utility classes using
@layer components.
For responsiveness, I can demonstrate a .card-grid showing grid layouts like cols-1 md:cols-2 lg:cols-3.Drafting a responsive component library
I’m working on drafting CSS using the @layer directive. This will include the basic Tailwind directives followed by a set of component classes. I want to create a .container-app class for layout, along with button styles like .btn, and responsive forms with .field-label and .field-input.
The user asked for a responsive component library, so I should touch on using @apply to create reusable utility classes that combine multiple Tailwind classes. It’s a good idea to provide one or two example HTML structures to demonstrate how these classes can work responsively.Drafting responsive components with Tailwind CSS
I could propose a pattern, using .btn-primary as the default button style and adding responsive behaviors like md: breakpoints. However, I don’t want to overcomplicate things. Instead, I can showcase a .card-grid class that highlights responsive breakpoints, ensuring I validate all syntax carefully.
I'll briefly show how to customize breakpoints in tailwind.config.js, keeping everything tool-agnostic since I'm unsure what build tool the user uses. Given my knowledge cut-off in October 2024, I can reference Tailwind version 3.4 or 3.5. It’s important to keep the environment setup minimal, focusing on the core library and naming conventions, such as "components.css."
I'll format code snippets using triple backticks with appropriate language hints. Let's get started!Emphasizing reusability and responsiveness
I should mention the importance of reusability across frameworks by using consistent class names. In React, for example, I'd switch to className. I'll emphasize responsive classes, such as setting the navigation to use flex-col with a gap of 4 on mobile, and switching to md:flex-row and md:gap-6 for larger screens.
I can keep modals simple, needing minimal JavaScript to toggle the hidden attribute. It’s essential to include responsive aspects in elements like grids and navigation as we go. Let’s provide that answer now! Below is a small, opinionated Tailwind-based component library you can drop into most projects. It uses:
- Tailwind’s utilities
- A layer of reusable component classes via
@apply
- Responsive layouts baked into some helpers
You can adjust names and tokens to fit your design system.
1. Tailwind Setup (minimal)
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx,html}",
],
theme: {
extend: {
colors: {
brand: {
50: "#eff6ff",
100: "#dbeafe",
500: "#3b82f6",
600: "#2563eb",
700: "#1d4ed8",
},
},
boxShadow: {
card: "0 10px 15px -3px rgba(15,23,42,0.15), 0 4px 6px -4px rgba(15,23,42,0.12)",
},
borderRadius: {
xl: "0.9rem",
},
},
},
plugins: [],
};
2. Component & Utility Layer
Create a main CSS file, e.g. src/styles/components.css:
@tailwind base;
@tailwind components;
@tailwind utilities;
/* ----------------------------- */
/* Component & utility classes */
/* ----------------------------- */
@layer components {
/* Layout container */
.app-container {
@apply mx-auto w-full max-w-6xl px-4 sm:px-6 lg:px-8;
}
/* Vertical stacks for spacing children */
.stack-sm > * + * {
@apply mt-2;
}
.stack > * + * {
@apply mt-4;
}
.stack-lg > * + * {
@apply mt-6;
}
/* Responsive card grid */
.card-grid {
@apply grid gap-4 sm:gap-6 md:grid-cols-2 lg:grid-cols-3;
}
/* --------------------------------- */
/* Typography helpers */
/* --------------------------------- */
.heading-xl {
@apply text-3xl font-semibold tracking-tight text-slate-900 sm:text-4xl;
}
.heading-lg {
@apply text-2xl font-semibold tracking-tight text-slate-900 sm:text-3xl;
}
.heading-md {
@apply text-xl font-semibold tracking-tight text-slate-900;
}
.body-base {
@apply text-sm sm:text-base text-slate-700 leading-relaxed;
}
.body-muted {
@apply text-sm text-slate-500;
}
/* --------------------------------- */
/* Buttons */
/* --------------------------------- */
.btn {
@apply inline-flex items-center justify-center gap-2
rounded-md border border-transparent
px-3 py-2 text-sm font-medium
transition-colors duration-150
focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2
disabled:cursor-not-allowed disabled:opacity-60;
}
.btn-primary {
@apply btn
bg-brand-600 text-white
hover:bg-brand-700
focus-visible:ring-brand-600;
}
.btn-secondary {
@apply btn
bg-slate-100 text-slate-900
hover:bg-slate-200
focus-visible:ring-slate-400;
}
.btn-outline {
@apply btn
border-slate-300 bg-transparent text-slate-900
hover:bg-slate-50
focus-visible:ring-slate-400;
}
.btn-ghost {
@apply btn
border-transparent bg-transparent text-slate-700
hover:bg-slate-100
focus-visible:ring-slate-300;
}
.btn-destructive {
@apply btn
bg-red-600 text-white
hover:bg-red-700
focus-visible:ring-red-600;
}
.btn-sm {
@apply px-2.5 py-1.5 text-xs;
}
.btn-lg {
@apply px-4 py-2.5 text-base;
}
.btn-icon {
@apply inline-flex h-9 w-9 items-center justify-center rounded-full p-0;
}
/* --------------------------------- */
/* Form fields */
/* --------------------------------- */
.field-label {
@apply mb-1 block text-sm font-medium text-slate-700;
}
.field-input {
@apply block w-full rounded-md border border-slate-300 bg-white
px-3 py-2 text-sm text-slate-900
shadow-sm
placeholder:text-slate-400
focus:border-brand-500 focus:outline-none focus:ring-1 focus:ring-brand-500
disabled:cursor-not-allowed disabled:bg-slate-100;
}
.field-textarea {
@apply field-input min-h-[120px] resize-y;
}
.field-helper {
@apply mt-1 text-xs text-slate-500;
}
.field-error {
@apply mt-1 text-xs text-red-600;
}
.field-input-error {
@apply border-red-500 focus:border-red-500 focus:ring-red-500;
}
/* Input + label group */
.field-group {
@apply flex flex-col;
}
/* --------------------------------- */
/* Cards */
/* --------------------------------- */
.card {
@apply rounded-xl border border-slate-200 bg-white/80 backdrop-blur
shadow-card;
}
.card-header {
@apply flex items-start justify-between gap-2 border-b border-slate-100 px-4 py-3;
}
.card-title {
@apply text-base font-semibold text-slate-900;
}
.card-subtitle {
@apply text-sm text-slate-500;
}
.card-body {
@apply px-4 py-3 text-sm text-slate-700;
}
.card-footer {
@apply flex items-center justify-end gap-2 border-t border-slate-100 px-4 py-3;
}
/* --------------------------------- */
/* Badges / Pills */
/* --------------------------------- */
.badge {
@apply inline-flex items-center rounded-full border
px-2 py-0.5 text-xs font-medium;
}
.badge-neutral {
@apply badge border-slate-200 bg-slate-50 text-slate-700;
}
.badge-success {
@apply badge border-emerald-200 bg-emerald-50 text-emerald-700;
}
.badge-warning {
@apply badge border-amber-200 bg-amber-50 text-amber-800;
}
.badge-danger {
@apply badge border-red-200 bg-red-50 text-red-700;
}
/* --------------------------------- */
/* Alerts */
/* --------------------------------- */
.alert {
@apply flex w-full items-start gap-3 rounded-md border px-3 py-2 text-sm;
}
.alert-info {
@apply alert border-sky-200 bg-sky-50 text-sky-900;
}
.alert-success {
@apply alert border-emerald-200 bg-emerald-50 text-emerald-900;
}
.alert-warning {
@apply alert border-amber-200 bg-amber-50 text-amber-900;
}
.alert-danger {
@apply alert border-red-200 bg-red-50 text-red-900;
}
.alert-icon {
@apply mt-0.5 text-base;
}
.alert-content {
@apply flex-1 space-y-0.5;
}
.alert-title {
@apply font-medium;
}
.alert-description {
@apply text-sm;
}
/* --------------------------------- */
/* Navbar (responsive) */
/* --------------------------------- */
.navbar {
@apply flex w-full items-center justify-between border-b border-slate-200 bg-white/80 px-4 py-2 backdrop-blur sm:px-6;
}
.navbar-brand {
@apply flex items-center gap-2 text-sm font-semibold text-slate-900;
}
.navbar-links {
@apply hidden items-center gap-4 text-sm text-slate-700 sm:flex;
}
.navbar-link {
@apply inline-flex items-center rounded-md px-2 py-1 hover:bg-slate-100;
}
.navbar-cta {
@apply hidden sm:inline-flex;
}
.navbar-toggle {
@apply inline-flex items-center justify-center rounded-md p-2 text-slate-700 hover:bg-slate-100 sm:hidden;
}
/* Mobile menu panel */
.navbar-mobile-menu {
@apply sm:hidden border-b border-slate-200 bg-white px-4 py-2 space-y-1;
}
.navbar-mobile-link {
@apply block rounded-md px-2 py-1.5 text-sm text-slate-700 hover:bg-slate-100;
}
/* --------------------------------- */
/* Modal (basic structure) */
/* --------------------------------- */
.modal-backdrop {
@apply fixed inset-0 z-40 bg-slate-900/40 backdrop-blur-sm;
}
.modal {
@apply fixed inset-0 z-50 flex items-center justify-center px-4;
}
.modal-panel {
@apply w-full max-w-md rounded-xl bg-white shadow-card;
}
.modal-header {
@apply flex items-center justify-between border-b border-slate-100 px-4 py-3;
}
.modal-title {
@apply text-base font-semibold text-slate-900;
}
.modal-body {
@apply px-4 py-3 text-sm text-slate-700;
}
.modal-footer {
@apply flex items-center justify-end gap-2 border-t border-slate-100 px-4 py-3;
}
}
Import components.css into your app entry (e.g. index.css or directly in JS/TS depending on your build).
3. Example Usage (HTML)
Page layout + headings
<div class="app-container py-8 space-y-8">
<header class="space-y-2">
<h1 class="heading-xl">Dashboard</h1>
<p class="body-muted">Overview of your account and recent activity.</p>
</header>
<!-- Card grid (responsive) -->
<section class="card-grid">
<article class="card">
<div class="card-header">
<div>
<h2 class="card-title">Revenue</h2>
<p class="card-subtitle">Last 30 days</p>
</div>
<span class="badge-success">+18.2%</span>
</div>
<div class="card-body">
<p class="text-2xl font-semibold text-slate-900">$24,310</p>
</div>
</article>
<article class="card">
<div class="card-header">
<div>
<h2 class="card-title">Subscribers</h2>
<p class="card-subtitle">Active</p>
</div>
<span class="badge-neutral">2,134</span>
</div>
<div class="card-body body-base">
Growth is steady compared to last month.
</div>
<div class="card-footer">
<button class="btn-outline btn-sm">View list</button>
<button class="btn-primary btn-sm">Add user</button>
</div>
</article>
<!-- more cards... -->
</section>
</div>
Navbar (with basic mobile toggle)
<nav class="navbar">
<div class="navbar-brand">
<span class="h-7 w-7 rounded-md bg-brand-600 text-white flex items-center justify-center text-xs font-bold">
AC
</span>
<span>Acme UI</span>
</div>
<div class="navbar-links">
<a href="#" class="navbar-link">Dashboard</a>
<a href="#" class="navbar-link">Projects</a>
<a href="#" class="navbar-link">Team</a>
</div>
<div class="flex items-center gap-2">
<button class="btn-ghost btn-sm">Sign in</button>
<button class="btn-primary btn-sm navbar-cta">Sign up</button>
<button class="navbar-toggle" id="nav-toggle" aria-label="Toggle navigation">
<!-- simple icon -->
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
d="M4 6h16M4 12h16M4 18h16" />
</svg>
</button>
</div>
</nav>
<div id="nav-mobile" class="navbar-mobile-menu hidden">
<a href="#" class="navbar-mobile-link">Dashboard</a>
<a href="#" class="navbar-mobile-link">Projects</a>
<a href="#" class="navbar-mobile-link">Team</a>
</div>
<script>
const toggle = document.getElementById('nav-toggle');
const mobile = document.getElementById('nav-mobile');
toggle.addEventListener('click', () => {
mobile.classList.toggle('hidden');
});
</script>
Form fields
<form class="space-y-4 max-w-md">
<div class="field-group">
<label class="field-label" for="email">Email</label>
<input id="email" type="email" class="field-input" placeholder="you@example.com" />
<p class="field-helper">We’ll never share your email.</p>
</div>
<div class="field-group">
<label class="field-label" for="message">Message</label>
<textarea id="message" class="field-textarea" placeholder="Tell us how we can help"></textarea>
</div>
<button type="submit" class="btn-primary">Send message</button>
</form>
Alert
<div class="alert-info">
<div class="alert-icon">ℹ️</div>
<div class="alert-content">
<p class="alert-title">Heads up</p>
<p class="alert-description">
You have unsaved changes. Don’t forget to save before leaving.
</p>
</div>
</div>
Modal (structure; toggle with JS/React)
<!-- Backdrop -->
<div class="modal-backdrop" hidden id="dialog-backdrop"></div>
<!-- Modal container -->
<div class="modal" hidden id="dialog">
<div class="modal-panel">
<div class="modal-header">
<h2 class="modal-title">Confirm deletion</h2>
<button class="btn-ghost btn-icon" id="dialog-close">
✕
</button>
</div>
<div class="modal-body">
Are you sure you want to delete this project? This action cannot be undone.
</div>
<div class="modal-footer">
<button class="btn-secondary" id="dialog-cancel">Cancel</button>
<button class="btn-destructive">Delete</button>
</div>
</div>
</div>
4. How to extend this library
- Add new components via
@layer components { ... } and @apply.
- Encode responsive behavior in component classes when it’s consistent (e.g.,
.card-grid, .navbar).
- Keep low-level Tailwind utilities in templates only for one-off tweaks; push patterns back into this component layer as they repeat.
If you tell me which framework you use (plain HTML, React, Vue, Next.js, etc.), I can adapt this into framework-specific components or a small “design system” structure.