Header size scaling with header levels in the note

Things I have tried

Searching through forums and documentation

What I’m trying to do

Have size of a header dependent on how many header levels there are in a note. For example when I add first header (H1) into a note, the size will be set at 10, then when I add a sub header (H2) the H1 is scaled up to 12 and H2 is set at font size 10. When H3 is added, it becomes font size 10 and all the rest grows by a set amount.

Is this possible to do with css? Thank you for your help.

The logic involved in such a scheme would, if even possible, make the CSS look horrendous.

You would need to set some flag depending on headers present, and then have rules depending on that flag on multiple levels. I don’t think that’s possible with pure CSS, but I’ve been mistaken before.

Within Obsidian I would rather prepare multiple CSS files with various header sizes, and add the appropriate one using cssClass in the frontmatter.