What is the fundamental difference between using margin/padding and using the position: relative property? In what cases is it more correct to apply this or that method? Please provide examples

2 Answers 2

Margin/padding is used to set the offset of an element, while position is used to position it.
  • but indentation can also be set using position? – Hungry Herring Nov 7 '19 at 14:01
  • this causes complexity – Hungry Herring Nov 7 '19 at 14:01
  • [[qwedcgt]], indentation cannot be set using position! who told you such nonsense? With it, you can only shift the element. – Spirit96 Nov 7 '19 at 15:18
margin/padding- give indents, on the basis of which other elements in the stream will shift
position: relative - will shift the current element, but other elements in the stream will not shift

In what cases is it more correct to apply this or that method?

margin- when you need an indentation
padding - when you need an indentation
position: relative - in such cases, almost never
  • thank you for your reply
    let's say if I work with a heading in a block that has a certain width, what is better to use?
    – Hungry Herring Nov 7 '19 at 14:06
  • [[qwedcgt]], but how does width affect padding? What’s the width here?
    margin, always use margin for outer padding, as I described in the answer.
    – Peaceful43 Nov 7 '19 at 14:56