Skip to content

Styling Generator Tables That Have No thead

Adityo Guni Waluyo

Report tables emitted as bare tr>th rows never match a thead th selector. The diagnosis runs on computed style, and one dual-form rule fixes it.

TL;DR

Table headers across 30 KotaPortal tables rendered as plain text because the generator emitted rows without a thead wrapper, so the header selector never matched anything. The fix added dual selectors covering both canonical and bare markup shapes, keeping the generator untouched. Lesson learned: inspect the emitted DOM first, since a non-matching selector fails silently regardless of the cascade.

Opening a document door in the KotaPortal admin manual, the report table headers rendered like plain text. Padding of roughly one pixel, no background separating them from the body rows, no zebra striping. The exact same symptoms appeared across all 30 tables in the 4 tabular document doors, in both the light and the dark theme.

Yet the CSS rule for the header was already sitting in the stylesheet.

First suspect: specificity or the cascade

The initial guess pointed at cascade order. It seemed plausible that the header rule lost to a more specific rule, or lived in a file that never loaded. An inspection of the stylesheet found no such override. The rule was there, its values were correct, and its position was reasonable.

Reading the stylesheet over and over fixed nothing, because the problem was never the cascade.

The markup shape actually emitted

Diagnosis moved forward once the emitted DOM was inspected directly. In the report markup, the table element carried rows and header cells as direct children; there was no thead wrapper, and no tbody wrapper either. The thead element is defined as the wrapper for a group of table rows marking the head of a table, usually holding the column headers [1]. Because the generator never emitted that wrapper, the selector targeting it had nothing to match.

The rule was not losing the cascade. The rule never matched at all.

This markup shape is valid per the specification. The HTML parser processes table content through dedicated insertion modes, and a tr row received directly inside a table is still processed into a complete table [2]. There is no error and no console warning. The only missing piece was the selector match, and this kind of failure is silent.

The rule of thumb is firm: when markup comes out of a generator, the stylesheet is written against the DOM that is actually emitted, not against the canonical shape you wish for. A selector validated only by reading code, without checking computed style, is not validated yet.

One rule for both shapes

The fix covers both shapes with a single selector set, so the generator markup stayed untouched. The canonical form with a thead and the bare form directly under the table are treated the same:

/* header: canonical form and bare form */
.doc thead th,
.doc tr > th {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .7rem .9rem;
  border-bottom: 2px solid color-mix(in srgb, var(--accent), var(--surface));
  white-space: nowrap;
}

/* zebra: both forms */
.doc tbody tr:nth-child(even) td,
.doc tr:nth-child(even) > td {
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

The color-mix() notation blends colors in a chosen colorspace with a chosen proportion [4], so the header tint follows the theme variables directly. Both themes share the same rules; only the values behind --accent and --surface change.

Zebra striping keeps working without a thead, because the nth-child pseudo-class matches elements by their index in the parent's child list [3]. In both shapes the rows remain children of the table or the tbody, so even rows are still detected.

For body cells, comfortable padding plus overflow-wrap: anywhere keeps long tokens such as column names or document identifiers from forcing the table wider [5]. Cells carrying a rowspan attribute get a surface background and a heavier font weight so they read as row labels rather than empty cells. Small chips for inline code keep technical terms legible in both themes.

Verification through computed style

Verification ran against the DOM, not against the CSS files. On every table, the computed header padding measured .7rem .9rem, the header background carried the blended color, and even rows showed the zebra background. A visual check in both themes confirmed the same result. All 30 tables across the 4 doors were covered by one rule change, and the generator markup was left as it was.

Leaving the generator alone was a deliberate decision. Its output is already consumed by other paths, and the stylesheet contract was repairable with dual selectors. The risk is known: the generator may emit a thead someday, and the canonical shape is covered from day one.

The lasting lesson is not a CSS trick but an ordering of diagnosis. Inspect the emitted DOM first, match the selector against that shape, and only then talk about specificity. A selector that never matches always loses silently, and no cascade can be blamed for that.

Sources

[1] MDN, the thead element, accessed 2026-11-09.

[2] WHATWG HTML Standard, parsing section, accessed 2026-11-09.

[3] MDN, the :nth-child() pseudo-class, accessed 2026-11-09.

[4] MDN, the color-mix() function, accessed 2026-11-09.

[5] MDN, the overflow-wrap property, accessed 2026-11-09.

Related articles