First, specifically in this case there are not the slightest advantages of using the class instead of the inline-style (saving 2 characters is not considered):
<div class='margin_20'>отступили 20 px</div> <div style='margin:20px'>отступили 20 px</div>
There is an option that you need a bunch of values with prefixes, then the class really could give something. But it is better to limit yourself to a few predetermined values, and not to push anything. For example, make margin-xs , margin-s , ..., margin-xxl .
As for the question itself, theoretically css allows the imposition of part of the styles to other attributes , but at the moment no browser supports this:
p[data-ml] { margin-left: attr(data-ml px); }
<p data-ml="30">123</p> <p data-ml="50">123</p> <p data-ml="70">123</p>