Auditando sua saída CSS
Use ferramentas como relatórios do PurgeCSS e analisadores de pacotes para inspecionar quais classes do Tailwind chegaram à sua compilação de produção e por quê.
Auditando sua saída CSS é uma aula grátis de Tailwind CSS Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Tailwind CSS Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Tailwind CSS Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Why Audit Your CSS Output
Even with Tailwind's JIT engine removing unused styles, your production CSS bundle can grow unexpectedly. Auditing your CSS output means inspecting the final compiled file to understand what made it in, how large it is, and whether anything unnecessary slipped through. A lean stylesheet loads faster, parses faster, and improves Core Web Vitals scores.
Measuring Your Bundle Size
The simplest audit starts with measuring file size. After building your project, check the size of the generated CSS file. Gzip size is the number that matters for real-world performance because browsers decompress on the fly. A well-tuned Tailwind output is typically 5–15 KB gzipped for most projects.
# Build and check output size
npx tailwindcss -i ./src/input.css -o ./dist/output.css --minify
ls -lh ./dist/output.css
gzip -k ./dist/output.css && ls -lh ./dist/output.css.gzUsing the Tailwind CLI Watch Mode
During development, run Tailwind in watch mode to rebuild the stylesheet on every file change. This gives you real-time feedback on how your class additions affect output size. Use the --minify flag when measuring size to get production-accurate numbers rather than the development build.
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch
# In another terminal, measure:
npx tailwindcss -i ./src/input.css -o ./dist/output.css --minifyInspecting the Output File
Open the compiled CSS file and search for class names you suspect might be unnecessary. If you see hundreds of animation keyframes you never use, or an entire color palette for a color you only reference once, those are candidates for pruning. Text search for your content globs to verify they match the right files.
/* Example: search compiled output for unexpected classes */
/* grep 'animate-bounce' ./dist/output.css */
/* grep 'rose-' ./dist/output.css | wc -l */Checking Content Paths Are Correct
The most common source of bloat is misconfigured content paths. If your content array is too broad, Tailwind scans files it should not, picking up class-like strings from build artifacts, test fixtures, or third-party libraries. If it is too narrow, real classes get purged from production. Audit the content array first.
// tailwind.config.js
module.exports = {
content: [
'./src/**/*.{html,js,jsx,ts,tsx}',
'./pages/**/*.{js,ts,jsx,tsx}',
// AVOID: './node_modules/**/*' — scans too much
],
};Visualizing With PurgeCSS Stats
PurgeCSS can run as a standalone tool to analyze which selectors in your stylesheet are matched by your HTML files and which are not. While Tailwind has its own purging built in, running PurgeCSS separately gives you a detailed rejection report that highlights exactly which classes survived and which were removed.
# Install PurgeCSS globally for analysis
npm install -g purgecss
# Run analysis against your build output and HTML files
purgecss --css dist/output.css --content 'src/**/*.html' --output /tmp/purged.css
ls -lh /tmp/purged.cssUsing Bundle Analyzers for CSS
Tools like Statoscope, webpack-bundle-analyzer, or Next.js's built-in ANALYZE=true mode visualize your entire bundle including CSS files. They show a treemap of what takes up space, which makes it easy to spot unexpected Tailwind class groups consuming a disproportionate share of bytes.
# Next.js bundle analysis
npm install @next/bundle-analyzer
# next.config.js
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
module.exports = withBundleAnalyzer({});Identifying Dynamically Constructed Classes
A subtle source of bloat is dynamically constructed class names that JIT detects as strings and includes even though they are never used at runtime. For example, building a class from a variable like 'text-' + color forces you to safelist many permutations. Prefer full class names in your markup instead.
<!-- BAD: JIT cannot detect dynamic construction reliably -->
<!-- class="text-" + color + "-500" -->
<!-- GOOD: Write complete class names -->
<div class="text-red-500">Red</div>
<div class="text-blue-500">Blue</div>
<div class="text-green-500">Green</div>Auditing Safelist Entries
If you have added a safelist in your config, periodically audit those entries. Safelist items are always included regardless of whether they appear in scanned content. Over time, safe-listed classes from old features accumulate, adding bytes to every production build even after the feature is removed.
// tailwind.config.js
module.exports = {
safelist: [
// Audit these regularly — remove anything no longer needed
'bg-red-500',
'bg-green-500',
{
pattern: /bg-(red|green|blue)-(100|500|900)/,
},
],
};Comparing Builds Over Time
Treat CSS output size as a tracked metric in your CI pipeline. After each build, log the gzip size to a file or a dashboard. When the size spikes unexpectedly between commits, bisect the recent changes to find the culprit. Many teams set a size budget and fail the build when it is exceeded.
# Simple CI size budget check (shell script)
SIZE=$(wc -c < dist/output.css)
BUDGET=20000 # 20 KB uncompressed
if [ "$SIZE" -gt "$BUDGET" ]; then
echo "CSS budget exceeded: $SIZE bytes (limit: $BUDGET)"
exit 1
fi
echo "CSS size OK: $SIZE bytes"Removing Unused Official Plugins
Official Tailwind plugins like @tailwindcss/typography and @tailwindcss/forms add hundreds of rules when enabled. If you are not using Prose content or styled form elements, remove the plugin from your config. Every plugin you remove is a meaningful chunk of bytes saved from the final bundle.
// BEFORE: both plugins always included
plugins: [
require('@tailwindcss/typography'),
require('@tailwindcss/forms'),
],
// AFTER: only include what you actually use
plugins: [
// require('@tailwindcss/typography'), // removed — not using prose
require('@tailwindcss/forms'),
],Quick Check
Test your understanding of Tailwind CSS Mastery concepts from this lesson.
Lesson Recap
In this lesson you learned: measuring gzip size as the key production metric, auditing content paths to prevent over-scanning or under-scanning files, and removing unused plugins and safelist entries to keep the bundle lean. Next up we explore class sorting with the Prettier plugin.
Perguntas Frequentes
A aula “Auditando sua saída CSS” é grátis?
Sim — o texto completo de “Auditando sua saída CSS” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Tailwind CSS Academy, atualize para CoddyKit PRO. O curso de Tailwind CSS Academy inclui 4 aulas no total.
O que vou aprender em “Auditando sua saída CSS”?
Use ferramentas como relatórios do PurgeCSS e analisadores de pacotes para inspecionar quais classes do Tailwind chegaram à sua compilação de produção e por quê. Você pratica Tailwind CSS Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar Tailwind CSS Academy?
Nenhuma experiência prévia é necessária. Tailwind CSS Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.
Quanto tempo leva a aula “Auditando sua saída CSS”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de Tailwind CSS Academy?
Sim. Cada aula de Tailwind CSS Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Auditando sua saída CSS
- Ordenação de classes e plugin do Prettier
- Analisando o Tailwind com o ESLint
- Convenções da equipe e guia de estilo