1) Let’s assume that you have created a custom theme.
Now, Create your custom less file at app/design/frontend/VendorName/ThemeName/web/css/source/_custom.less and add your less code inside that file.
2) After that you need to import this _custom.less file at app/design/frontend/VendorName/ThemeName/web/css/source/_sources.less@import ‘_custom.less’;
You need to import your _custom. less file using this above line. Just add that line inside _sources. less file. If this _sources. less file does not exist in your custom theme then, you need to copy a file from vendor/Magento/theme-frontend-blank/web/CSS/source/_sources.less file in your theme.
Now, just need to
deploy and clean cache
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f