I want to add background image for <li> element in template file. How to add background image in phtml file in magento2 ?

1 Answer 1


Try the below code:

<li style="background-image:url('<?php echo $block->getViewFileUrl('images/demo.jpg'); ?>')">Your text</li>

Your Answer

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

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