Changing the Default Ajax Loading Icon on Magento 2 Checkout Page
The checkout process is a critical part of any e-commerce store’s user experience. In Magento 2, when an ajax request is loading (like during address selection or payment method choice), it displays a default spinner icon. However, you might want to customize this loading indicator to better match your site’s branding.
Understanding the Default Behavior
By default, Magento uses Font Awesome for its icons. The ajax loader is represented by the fa-spinner class with the fa-pulse animation applied.
.fa-spinner:before {
content: "\f01e";
}
This icon is shown via the loader div in the checkout page’s layout:
Changing to a Static Image
If you prefer an image or a custom SVG over an animated icon, you can replace it easily. First, create your desired loading graphic and save it as ajax_loader.gif (or any other supported format).
Next, upload this file to the pub/static/frontend/<Vendor>/<Theme>/images folder of your Magento installation.
Then, update the CSS in your theme’s stylesheet:
.loader span {
background-image: url('path/to/ajax_loader.gif');
}
Replace 'path/to/ajax_loader.gif' with the actual path to the file you’ve uploaded. Ensure the path is correct relative to the pub/static folder.
Replacing with a Custom SVG Icon
For more advanced customization, you can use an SVG icon instead of a gif or png image.
- Create your desired loading icon in an SVG format.
- Save it as
ajax_loader.svg. - Upload this file to the same
pub/static/frontend/<Vendor>/<Theme>/imagesfolder mentioned earlier. - Update the CSS:
.loader svg {
display: block;
}
- Now you can style your custom SVG loading icon using CSS.
Customizing the Spinner Color
If you want to change the color of the default spinner, you can target it directly in your theme’s stylesheet:
.loader .fa-spinner {
color: #your-color-code;
}
Conclusion and Further Reading
Changing the loading icon on the Magento 2 checkout page is a straightforward process that doesn’t require much code modification. By uploading a custom image or SVG file and updating your theme’s stylesheet, you can create a seamless user experience that aligns with your brand.
Remember to flush your cache after making these changes for them to take effect:
php bin/magento cache:flush
For more advanced Magento development tasks like this, I highly recommend checking out the developer resources at Laravel Company. They provide in-depth guides and tips to help you master Magento 2.