Below is code of my default.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
        <css src="My_Slider::css/betterslider.css"/>

i want css to be loaded js before body end tag , how can this be done please help with same.

2 Answers 2


I don't have enough reputation yet to mark this question as a duplicate or to add this as a comment, but here's a cross-reference to an answer: Magento 2 add script before closing body tag

  1. app/design/frontend/{Vendor}/{theme}/Magento_Theme/layout/default.xml

    <referenceContainer name="before.body.end">
        <block class="Magento\Framework\View\Element\Template" name="beforebodyend.css.file" template="Magento_Theme::html/before_body_end_css.phtml" />
  2. app/design/frontend/{Vendor}/{theme}/Magento_Theme/templates/html/before_body_end_css.phtml

    <link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('css/betterslider.css')?>">
  3. app/design/frontend/{Vendor}/{theme}/web/css/betterslider.css

    .class {
Don't forget to flush the cache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.