Hello,
Margin is an element’s personal space that how much distance the element wants to keep with other elements around it.
Padding is how much an element is away from itself that how much distance an element wants to keep with the elements inside it.
They both are used to create gaps around elements, but they differ in their method of creating that gap. Margin accommodates the gap by pushing adjacent elements away from it, while Padding accommodates the gap by either growing its own size or by shrinking the size of content inside it.
By default, padding will increase the size of the element to accommodate the gap.
Screenshot for better understanding: https://jmp.sh/M7MsjCS
Hope the above instructions helps you to figure out when to use padding and when to use margin while adding custom css code in your site
Best Regards.