Validator can't see certain headings wrapped in DIV elements

For technical support and bug reports for all editions of CSS HTML Validator, including htmlval for Linux and Mac.
TomHTML
Rank III - Intermediate
Posts: 75
Joined: Sun Feb 04, 2018 10:19 am

Validator can't see certain headings wrapped in DIV elements

Post by TomHTML »

In the new version of the Validator (perhaps present in previous versions, but I didn't notice it until I installed the new version), headings wrapped in DIVs that are a child element of a SECTION are not recognized by the validator. For example:

Code: Select all

<body>
    <header>
        <h1>My stuff</h1>
    </header>
    <main>
        <h1>Main title</h1>
        <section>
            <div class=my-style>
                <h2>hello</h2>
            </div>
        </section>
    </main>
</body>
The Validator issues this warning on the <section>:
No heading element was found as a child of this <section> element. Each section should typically be identified by including a child heading element (<h1>, <h2>, <h3>, etc.).
This warning seems wrong; the DIV seems to hide the <h2> from the validator.
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX

Re: Validator can't see certain headings wrapped in DIV elements

Post by Albert Wiersch »

Hello,

CSS HTML Validator is only looking for headings in the children, so it won't see a heading if it's in a child element and not the child element itself. This is because https://developer.mozilla.org/en-US/doc ... sage_notes says "each <section> should be identified, typically by including a heading (<h1> - <h6> element) as a child of the <section> element". Note that it says child and not descendant.

However, I ran this through the Nu Html Checker and it accepted (by not generating a warning) the heading element when it was a descendant.... so I will go ahead and have CSS HTML Validator look for heading elements as descendants and not just as children in <section> elements

You can try the new config file that should address this issue here:
https://www.htmlvalidator.com/2022/htmlvalV220cfg.zip

Please see the "readme" file in the above ZIP file for installation instructions.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
TomHTML
Rank III - Intermediate
Posts: 75
Joined: Sun Feb 04, 2018 10:19 am

Re: Validator can't see certain headings wrapped in DIV elements

Post by TomHTML »

Thanks for attending to this so quickly!

I believe the reasoning is that DIVs are only used for styling, so they're discounted over other elements, but if so, the documentation at Mozilla should be clearer.

Thanks again!
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX

Re: Validator can't see certain headings wrapped in DIV elements

Post by Albert Wiersch »

TomHTML wrote: Sat Jul 23, 2022 6:06 pm Thanks for attending to this so quickly!

I believe the reasoning is that DIVs are only used for styling, so they're discounted over other elements, but if so, the documentation at Mozilla should be clearer.

Thanks again!
You're welcome!

Yes, the documentation at Mozilla may need to be clearer and/or revised... but <div> elements are general sectional elements that can be used for styling but also for a general "related content section" when another sectioning element like <article>, <nav>, <section>, etc. isn't appropriate (or as Mozilla says, the <div> element is a generic container for flow content).
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial