Load More Button Template
Allow users to progressively load more content with this intuitive and versatile button.
This is a fundamental component for any content-heavy page, such as a blog archive, product grid, or user feed, improving performance by loading items on demand.
About the Load More Button
Instead of overwhelming users with a huge list of items or forcing them to navigate through numbered pages, a "Load More" button provides a friendly way to reveal more content. It signals that there is more to see, giving the user control over when they see it. This pattern can improve initial page load times and create a smoother browsing experience.
Features
- Interactive States: Includes distinct styles for default, loading, and disabled states to provide clear user feedback.
- Animated Loader: A simple, pure CSS loading spinner appears when the button is clicked, indicating that new content is being fetched.
- Accessible Implementation: The button's states are managed in a way that is clear to assistive technologies. The use of
aria-liveon a separate status element can announce when new content has loaded. - Example Logic Included: The JavaScript provides a simple demonstration of how to handle the button's states, including a "no more items" scenario.
Code Breakdown
The component includes the button itself and some sample list items to demonstrate its use. The button contains a text span and a CSS-only spinner element.
JavaScript controls the button's behavior. On click, it adds an is-loading class to the button. This class uses CSS to hide the text and show the spinner. The script simulates an API call with setTimeout. After loading, it adds new items to the list and resets the button. A counter tracks the clicks, and once a limit is reached, the button becomes disabled to show there's nothing left to load.
Code
Here is the complete HTML, CSS, and JavaScript for the "Load More" button demonstration.