Performance: Extending default theme values
Extending default theme values affects CSS bundle size and rendering performance by adding more styles to process.
const defaultTheme = require('tailwindcss/defaultTheme'); module.exports = { theme: { extend: { colors: { customRed: '#f00', customBlue: '#00f' } } } }
module.exports = {
theme: {
colors: {
red: '#f00',
blue: '#00f',
green: '#0f0',
yellow: '#ff0',
purple: '#800080',
orange: '#ffa500',
pink: '#ffc0cb',
teal: '#008080',
lime: '#00ff00',
cyan: '#00ffff',
// many more custom colors added here
}
}
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Override entire theme colors | No extra DOM nodes | No reflows triggered | High paint cost due to large CSS | [X] Bad |
| Extend theme colors selectively | No extra DOM nodes | No reflows triggered | Lower paint cost with smaller CSS | [OK] Good |
extend inside the theme in Tailwind CSS?extend in Tailwindextend key inside theme allows you to add new values while keeping the default ones intact.extend and directly define values, you replace the defaults, losing them.brandBlue with hex #1DA1F2 using extend in Tailwind config?extend key must be inside the theme object to add new values.colors nested under extend.{
theme: {
extend: {
colors: {
softGreen: '#a8d5ba'
}
}
}
}softGreen (camelCase) becomes bg-softGreen.bg- followed by the exact color key name.{
theme: {
extend: {
spacing: 72: '18rem'
}
}
}spacing key must have an object with key-value pairs inside curly braces.spacing: 72: '18rem' misses curly braces around { 72: '18rem' }.xxl with value 2.5rem but keep all default font sizes. Which config snippet correctly extends the fontSize theme without losing defaults?extend under theme.fontSize inside extend inside theme. Others replace or misplace keys.Pass the test and this pattern moves unknown