Performance: Text color utilities
Text color utilities affect paint performance by changing text color styles efficiently.
Jump into concepts and practice - no test required
<p class="text-red-400">Hello</p> <p class="text-red-400">World</p>
<style> .red-text { color: #f87171; } </style>
<p class="red-text">Hello</p>
<p class="red-text">World</p>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Tailwind text color utilities | No extra DOM nodes | 0 | Single paint per color change | [OK] Good |
| Custom CSS classes for text color | No extra DOM nodes | 0 | Single paint per color change | [OK] OK |
| Inline styles for text color | No extra DOM nodes | 0 | Single paint per color change | [OK] OK |
| JavaScript style changes on many elements | Multiple DOM style updates | 0 | Multiple paints | [X] Bad |
text-red-500 do to the text?text-red-500 uses the format text-{color}-{shade} to set text color.red is the color and 500 is a medium shade, so it changes text color to medium red.text-blue-100 is the correct format for light blue text color.<p class="text-green-700">Hello</p>
text-green-700 sets the text color to green with shade 700, which is a darker shade.<span class="text-purple-">Sample</span>
text-purple- ends with a dash but no shade number, which is invalid.text-gray-100 is a very light gray, suitable for dark backgrounds. text-gray-900 and text-black are dark colors, hard to read on dark backgrounds. text-white-500 is invalid because white doesn't have shades.