5

Edit 3/18/22: I recently checked several Terms of Use and similar documents and found run-in headings are frequent in this type of document but always incorrectly formatted as <strong> rather than as headings, so this issue appears to be much broader than academia style guides.


I have been wrestling with the format of run-in headings for years. This is not a minor problem, because one of the top styles in academia and scholarly work, APA, requires (APA is strict, not flexible like some style guides) run-in headings for both level 4 and 5 headings (https://apastyle.apa.org/style-grammar-guidelines/paper-format/headings)

Many other academic styles also have run-in headings — for example, Chicago's five heading levels; and Harvard Extension's "C" level headings.

I used to just format run-in headings as bold, but that does not correctly interpret the document structure for assistive technologies. So I now use the CSS below, since display: run-in is not currently a CSS option. The results are glitchy.

For instance, a break appears after the heading when the heading wraps on the browser page. Any suggestions for better code?

H4.enpara {
  text-indent: 2em;
  display: inline-block;
  break-before: column;
  margin-bottom: -1em;
}

H4.enpara + P {
  display: inline;
  margin: 0 0 .7em 0;
}
iZann
  • 53
  • 7
  • 1
    side note: use lowercase in CSS – Raptor Feb 28 '22 at 01:31
  • 1
    @Raptor while I agree 100% I prefer lowercase (as do most), unless you are using XHTML it doesn't matter. Same as HTML, you can use upper and or lower case for tag names. I just thought it was really interesting when someone told me that , hopefully you think it is interesting too! https://www.w3.org/TR/selectors/#case-sensitive – GrahamTheDev Feb 28 '22 at 02:29
  • 1
    Yes, I agree. Nowadays less people work on XHTML now. I almost forgot this stuff. – Raptor Feb 28 '22 at 02:31
  • 1
    @raptor Haha, I feel you on the things I learned from the XHTML days, like `` and all of the self closing trailing slash stuff. I have to admit I still use so many of the things from back then still. I guess you can't teach an old dog **all** the new tricks in my case – GrahamTheDev Feb 28 '22 at 02:33

2 Answers2

3

Original Answer

Note: the concept was correct, but it had flaws, see the h2 heading "Edit, it was more complicated than I thought"

Original answer: Could we not just use inline on both and apply a left-margin to the heading?

Then for spacing we just add a 0.15em margin to the left of the run-in paragraph.

The only down side is that you can end up with a double space as an extra character is automatically added for an inline paragraph and heading in Chrome.

The only solution I have for that would be to add a spacer class to headings that take up more than one line manually (the margin-left).

It is minor though as with a bit of fine-tuning you can see it is barely noticeable. It is still more accessible than using bold as you pointed out and I don't think the spacing difference is large enough to cause any problems to people with dyslexia etc.

h4, h5 {
  margin-left: 2em;
  display: inline;
}

h4 + p, h5 + p {
  display: inline;
  margin-left: 0.15em;
}
<h4>a long heading that will wrap onto two lines to ensure that browser wrapping does not break our run-in system</h4><p>a paragraph</p>
<p>another paragraph that does not have a run-in</p>
<h4>Another heading</h4>
<p>another paragraph with a run-in.</p>
<p>a longer paragraph to ensure there isn't an issue with the run-in happening for the heading itself on a paragraph
<h5>a heading level 5 to test it works for that also</h5>
<p>a further paragraph that should have a run-in also</p>

Edit, it was more complicated than I thought

The above kind of works, but you can get run-in where it is not intended if you happen to only have a single paragraph after a h4 or h5 and then use another h4 or h5.

I may have made a mistake and this is not extensively tested, but this appears to be the correct formatting requirements for all heading levels.

I had to use a couple of tricks to account for run-in on a h4 followed by a h5 with only a single paragraph and to counter a spacing issue that introducing the ::after pseudo element caused.

I think the below behaves correctly, but you would need to test it extensively as I said.

The only thing it doesn't cover is correcting Title Case as that isn't possible without JS as far as I am aware.

Finally I have set all spacing in REM, then if someone increases their browser size it will scale appropriately. The only thing that you may have to look at there is whether a 2rem margin on the left works or whether that should be a fixed amount (if you quadrupled the font size for example the left margin would be too large probably).

The fix would be to set the left margin in a fixed unit such as px, I will leave that up to you to investigate / decide.

h1, h2, h3, h4, h5{
  font-size: 1rem;
  font-weight: bold;
}

h1{
   text-align: center;
}

h3, h5{
  font-style: italic;
}


h4, h5 {
  margin-left: 2rem;
  display: inline;
}

h4 + p::after, h5 + p::after{
  content: "";
  height: 1rem;
  display: block;
  clear: both;
}

h4 + p, h5 + p {
  display: inline;
  margin-left: 0.15rem;
}

h4 + p + p,
h4 + p + h1,
h4 + p + h2,
h4 + p + h3,
h4 + p + h4,
h4 + p + h5,
h5 + p + p,
h5 + p + h1,
h5 + p + h2,
h5 + p + h3,
h5 + p + h4,
h5 + p + h5{
   margin-top: 0rem;
}
<h1>H1 - Centered, Bold, Title Case Heading</h1>

<p>Text begins as a new paragraph.</p>

<h2>H2 - Flush Left, Bold, Title Case Heading</h2>

<p>Text begins as a new paragraph.</p>

<h3>H3 - Flush Left, Bold Italic, Title Case Heading</h3>

<p>Text begins as a new paragraph.</p>

<h4>H4 - Indented, Bold, Title Case Heading, Ending With a Period.</h4> 

<p>Text begins on the same line and continues as a regular paragraph.</p>

<h5>H5 - Indented, Bold Italic, Title Case Heading, Ending With a Period.</h5> 

<p>Text begins on the same line and continues as a regular paragraph.</p>

<h2>H2 - Flush Left, Bold, Title Case Heading</h2>
GrahamTheDev
  • 22,724
  • 2
  • 32
  • 64
  • This works. Using the ::after pseudo-element solves many problems. I'm impressed. And thanks for the lowercase recommendation on CSS. The uppercase is a carryover from many, many years ago I'm afraid. – iZann Feb 28 '22 at 01:46
  • lowercase or uppercase doesn't actually matter (the tip was someone else), in fact things like `
    ` and `
    ` can be useful for keeping track of nested items (just as long as you close with the same case it doesn't matter!). Please do let me know if you find a scenario where the above doesn't work. And thanks for the question, it was a really fun problem to solve as I wasn't aware of APA (as I am not academic ) and I was surprised it hadn't been solved elsewhere on the site (as far as I can tell) given how much it is used...perhaps as the guidelines only apply to "paper"...who knows?
    – GrahamTheDev Feb 28 '22 at 02:25
  • 1
    Yes, I think this is a significant contribution. I still would urge W3C to add a CSS style for "display: run-in" since that would allow specification of spacing above the heading. The only way I can figure to do that now is to specify spacing in the preceding block (usually a paragraph). Also, "display:run-in" would forestall any need for special instructions for the subsequent paragraph. Nevertheless, what you did with the available CSS is brilliant IMHO. – iZann Feb 28 '22 at 05:27
  • 1
    Oh, and thanks for the info about upper case in CSS. I was surprised by the comment, thinking some major change must have occurred that I somehow missed. Yes, I use selective upper case in the stylesheet to make it easier to find things. Just a personal preference. – iZann Feb 28 '22 at 05:30
  • What are the spacing requirements for above the heading? I might be able to sort that too if you let me know where this doesn't work. Explain it like I am 5 though lol! – GrahamTheDev Feb 28 '22 at 12:05
  • I need 1em/rem above the h4. – iZann Feb 28 '22 at 22:46
  • There is currently 1rem above the h4? Are you saying an additional 1rem? Also for clarity is that a spec thing or just a personal need (so I know which way to fix it!)? – GrahamTheDev Mar 01 '22 at 08:03
  • It's not a spec thing. It's just for the publication I work for, which isn't even APA (it's based on Turabian I think; APA was the style guide I'm most familiar with from my graduate classes). The 1em above doesn't appear on [my site](https://worldviewpublications.org/outlook/archive/article.php?EDITION=2102) , which by default has no space between paragraphs, *if* the block above is a paragraph. – iZann Mar 01 '22 at 13:33
1

@Graham Ritchie's answer seems to work well, but not a fan of the h4 + p + p, h4 + p + h1.... Hopefully this works well for you:

h1, h2, h3, h4, h5 {
  font-size: 1rem;
  font-weight: bold;
}

p {
  text-indent: 2rem;
}

h1 {
  text-align: center;
}

h3, h5 {
  font-style: italic;
}

h4, h5 {
  display: inline;
  margin-inline-start: 2rem;
}

h4 + p, h5 + p {
  display: inline;
  margin-inline-start: 0.5rem;
}

h4 + p::after, h5 + p::after {
  content: "";
  display: block;
  margin: 1rem;
}
<h1>H1 heading</h1>
<p>Text following h1</p>
<h2>H2 heading</h2>
<p>Text following h2</p>
<h3>H3 heading</h3>
<p>Text following h3</p>
<h4>H4 heading</h4>
<p>Text following h4</p>
<p>Text following h4 + p</p>
<h4>H5 heading</h4>
<p>Text following h5</p>
<h5>H5 heading following h5 + p</h5>
<p>Text following h5</p>
<h2>H2 heading following h5 + p</h2>
<p>Text following h2</p>
Ranoiaetep
  • 5,872
  • 1
  • 14
  • 39
  • I tweaked the @Graham Ritchie answer to work for the publication I work on, and it required top margin adjustments slightly different from his. Before I try this solution, I have a question. Is the "margin-inline-start" new? Does it work on all browsers? – iZann Mar 18 '22 at 22:24
  • @iZann All latest browsers since 2-3 years ago supports it according to [MDN](https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inline-start#browser_compatibility). However, changing them to `margin-left` should be fine if your contents are displayed left-to-right. – Ranoiaetep Mar 18 '22 at 22:38
  • Looks neater, great iteration! Just need to correct all paragraphs being indented though but certainly on the right track! I can't remember why I ended up falling back to loads of declarations now, but there was a weird edge case I had to get around. – GrahamTheDev Mar 29 '22 at 09:06
  • Sorry to take so long with this @Ranoiaetep; publishing editor of my website died quite suddenly, and it's taken awhile to get back to work and try out the code. So far, so good. I will check all the articles where I used H4s, but I don't expect any problems. The "margin-inline-start: 0.5rem" is a bit too much space for me. I'm using 0.15rem there, but that's not an error, just a style difference. – iZann May 22 '22 at 23:31
  • 1
    I have now checked all the articles on my website that have run-in H4 headings, and the formatting is correct on all of them, so I've changed to the simplified code. Thanks! – iZann May 23 '22 at 00:41