I want to set path for background image in less file app\design\frontend\vendor\theme\web\<lessfile> in magento2.

  • 1
    This is not an off-topic question. This was very useful for me with Magento 2.
    – Webninja
    Oct 14, 2020 at 10:50
  • 2
    Yes it is, Thanks :) @Webninja Oct 15, 2020 at 7:02

1 Answer 1


First add image in app\design\frontend\vendor\theme\web\images folder and write css as below:

background: url('@{baseDir}images/icon_sprite.png');

after add new image run command as below:

- php bin/magento cache:clean
- php bin/magento setup:static-content:deploy
  • This is not working for me in Magento 2.1.4. Does this only apply to production mode or should this work in developer mode as well? Mar 14, 2017 at 12:27
  • 1
    This will work in both mode, just you have to run php bin/magento setup:static-content:deploy command after add image in app\design\frontend\vendor\theme\web\images folder. if still not working remove var/view_preprocessed folder. Mar 14, 2017 at 13:34
  • 1
    Thanks for the feedback. Turned out that my problem was elsewhere. Something to do with corrupt PNG files. Yeah I know, long story... your answer is still correct though. However, you could add that it in some cases it might be necessary to define @baseDir in your themes' theme.less. By default the variable is set to ../. Mar 14, 2017 at 15:11
  • Thank you ! How about using it this style in _email-extend.less ? and what is the difference with using background: url("@{baseUrl}images/icn.png');
    – medmek
    Oct 21, 2018 at 18:02

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