A lightweight Tailwind CSS plugin that adds utilities for managing content visibility (content-visibility
) and intrinsic size hints (contain-intrinsic-size
). Optimize rendering performance with flexible size hints using custom theme values.
npm install tailwindcss-visibility
Add the plugin to your tailwind.config.js
:
module.exports = {
plugins: [require('tailwindcss-visibility')],
theme: {
sizeHint: {
// Optional: Customize default size hints
sm: '300px',
md: '500px',
lg: '800px',
},
},
};
Or add your own size hints in your tailwind.config.js
:
module.exports = {
content: ['./src/**/*.{html,js}'],
plugins: [require('tailwindcss-visibility')],
theme: {
extend: {
sizeHint: {
xs: '100px',
'2xl': '1000px',
custom: '250px',
},
},
},
};
content-auto
: Enables content-visibility optimizationcontent-hidden
: Hides content while preserving sizecontent-visible
: Forces content to remain visible<div class="content-auto">
<!-- Content here will be optimized -->
</div>
Predefined size hints:
size-hint-sm
: 300px (default)size-hint-md
: 500px (default)size-hint-lg
: 800px (default)Arbitrary values:
size-hint-[200px]
size-hint-[20rem]
size-hint-[50vh]
<div class="content-auto size-hint-md">
<!-- Content with medium size hint -->
</div>
Long Scrolling Pages
Optimize rendering performance for long pages with multiple sections:
<article class="content-auto size-hint-md">
<h2>Section Title</h2>
<p>Content...</p>
</article>
Image Galleries
Prevent layout shifts in image galleries:
<div class="grid grid-cols-3 gap-4">
<div class="content-auto size-hint-[200px]">
<img src="image1.jpg" alt="Gallery image" />
</div>
<!-- More gallery items -->
</div>
Accordion Sections
Optimize hidden content in accordions:
<div class="content-hidden">
<p>Collapsed accordion content...</p>
</div>
Using content-visibility: auto can significantly improve initial page load and rendering performance:
Custom Size Hints
// tailwind.config.js
module.exports = {
theme: {
sizeHint: {
xs: '100px',
'2xl': '1000px',
card: '250px',
},
},
};
git checkout -b feature/amazing-feature
)git commit -m 'Add amazing feature'
)git push origin feature/amazing-feature
)MIT License - see the LICENSE file for details
Peter Benoit - @peterbenoit