quarto-dev / quarto-dev/quarto-cli

Improve metadata and more generally HTML code for :empty selectors

Open
#13,537 4 comments 0 reactions 1 assignee View on GitHub

@cscheid is already working on this.

Since Oct 11, 2025.

enhancement html
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

TL;DR

  • The Pandoc/Quarto HTML template inserts empty lines inside <div class="quarto-title-meta"> when no metadata is present.
  • This causes the div to not be considered empty by CSS, so div:empty { display: none; } does not work.
  • As a result, unwanted empty divs are displayed and styling cannot be suppressed using the :empty selector.
  • This issue is unlikely limited to metadata block.

Description/Example

The HTML template for the title block metadata looks like this:

<div class="quarto-title-meta">
  $if(by-affiliation)$
  $elseif(by-author)$
  <div>
    <div class="quarto-title-meta-heading">$labels.authors$</div>
    <div class="quarto-title-meta-contents">
      $for(by-author)$
       <p>$_title-meta-author.html()$</p>
      $endfor$
    </div>
  </div>
  $endif$

  ...
</div>

When no metadata this leads to:

<div class="quarto-title-meta">

</div>

Because of the empty lines in between conditionals.

Problem

  • The div is not empty in CSS parlance due to whitespace/empty lines.
  • Thus, you cannot hide it with:
div:empty {
  display: none;
}
  • If you add styling to div.quarto-title-meta, it gets displayed every time, even with no metadata.
  • You also get empty lines added.

Proposed Fix

One way to fix this is to remove the empty lines in between metadata in the template.

Workarounds

For now, I’m doing the cleaning in JS:

<script>
  document.querySelectorAll('header#title-block-header div, header#title-block-header p').forEach(function(el) {
    if (!el.textContent.trim()) {
      el.style.display = "none";
      el.textContent = "";
    }
  });
</script>

References

Discussion

  • Some users have experienced “empty” divs being added regardless of template modifications.
  • Removing empty lines makes :empty work.
  • "We arguably should be doing this in our HTML postprocessor."

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.