Skip to content

What's New in Tailwind CSS v5

The topic of Tailwind CSS v5's new features has been discussed many times in the community, but with each new iteration, many prior conclusions need updating. This article provides a fresh take based on the latest version.

Getting Started ​

The key is understanding the core logic:

css
.container {
  width: min(90%, 1200px);
  margin-inline: auto;
  padding-inline: clamp(1rem, 3vw, 3rem);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
  gap: clamp(1rem, 2vw, 2rem);
}

.card {
  container-type: inline-size;
}

@container (min-width: 400px) {
  .card__content {
    display: grid;
    grid-template-columns: 200px 1fr;
  }
}

Performance optimization must be approached in context — not every situation calls for aggressive optimization.

Source Analysis ​

Here's a practical way to build on this:

css
'use client'
import { useChat } from 'ai/react'

export function AIChat() {
  const { messages, input, handleInputChange, handleSubmit, isLoading } = useChat({
    api: '/api/chat'
  })
  return (
    <div className="chat-container">
      {messages.map(m => (
        <div key={m.id} className={`message ${m.role}`}>
          <p>{m.content}</p>
        </div>
      ))}
      <form onSubmit={handleSubmit}>
        <input value={input} onChange={handleInputChange} />
        <button type="submit" disabled={isLoading}>Send</button>
      </form>
    </div>
  )
}

Real-World Application ​

Let's start with the basic implementation:

css
import { openai } from '@ai-sdk/openai'
import { streamText } from 'ai'

export async function POST(req) {
  const { messages } = await req.json()
  const result = await streamText({
    model: openai('gpt-4o'),
    messages,
    system: 'You are a professional frontend development assistant.',
    maxTokens: 2000
  })
  return result.toDataStreamResponse()
}

This code shows the basic usage; in real projects you'll also need to handle errors and edge cases.

Optimization Tips ​

From here, you can optimize further:

css
:root {
  --bg: light-dark(#fff, #1a1a2e);
  --text: light-dark(#333, #e0e0e0);
  --accent: light-dark(#2563eb, #60a5fa);
  color-scheme: light dark;
}

.carousel {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-padding: 1rem;
}

.carousel__item {
  flex: 0 0 80%;
  scroll-snap-align: start;
  border-radius: 12px;
  transition: scale 0.3s ease;
}

This pattern is highly practical in large-scale projects and can significantly reduce maintenance costs.

Summary ​

  • Stay informed about community developments — technical solutions need continuous iteration
  • Don't adopt new technology for its own sake
  • Code examples are for reference only; adapt them to your specific business context
  • Tailwind CSS v5 is not a silver bullet; choose based on your project's scale and tech stack

MIT Licensed