Are there some magic lines to be placed in the preamble that would, like in CSS, specify how each generic section or subsection in the whole document should be formatted?
You can use the
A short example would be
or questions tagged with titlesec.
there are a lot of packages which support customizing titles and headers: