---
name: html-structure-validate
description: Validate HTML5 structure and basic syntax. BLOCKING quality gate - stops pipeline if validation fails. Ensures deterministic output quality.
---
# HTML Structure Validate Skill
## Purpose
This skill is a **BLOCKING quality gate** that ensures generated HTML meets minimum structural requirements. It is the **first deterministic validation** of probabilistic AI-generated output.
The skill checks:
- **HTML5 compliance** - Proper DOCTYPE, tags
- **Tag closure** - All tags properly closed
- **Required elements** - Meta tags, stylesheet links
- **Well-formedness** - Valid structure
If validation fails, the pipeline **STOPS** and triggers a hook to notify the user.
This enforces the principle: **Python validates, ensuring deterministic quality**.
## What to Do
1. **Load HTML file to validate**
- Read `04_page_XX.html` generated by AI skill
- Verify file exists and is readable
- Confirm file is text (not binary)
2. **Run validation checks**
- Check HTML5 structure compliance
- Verify tag closure
- Validate head section
- Check required CSS link
- Validate page container structure
3. **Generate validation report**
- Document all checks performed
- List any errors found
- Note warnings (non-blocking)
- Record informational findings
4. **Save validation report** as JSON
- Save to: `output/chapter_XX/page_artifacts/page_YY/06_validation_structure.json`
- Include timestamp
- Include all check results
5. **Exit with appropriate code**
- Return 0 if VALID (continue pipeline)
- Return 1 if INVALID (STOP pipeline, trigger hook)
## Input Parameters
```
html_file: - Path to 04_page_XX.html
output_dir: - Directory for validation report
strict_mode: - If true, warnings also fail (default: false)
page_number: - Page number (for reporting)
chapter: - Chapter number (for reporting)
```
## Validation Checks
### Check 1: DOCTYPE Declaration
**Requirement**: File must start with proper DOCTYPE
```html
```
**Check**:
- [ ] File contains `` (case-insensitive)
- [ ] DOCTYPE appears before any tags
- [ ] DOCTYPE is on first line or near beginning
**Error if**: Missing or incorrect DOCTYPE
### Check 2: HTML Tags
**Requirement**: Proper `` opening and closing tags
```html
...
```
**Checks**:
- [ ] `` tag present
- [ ] `` closing tag present
- [ ] Tags are properly paired
- [ ] No unclosed `` tags
**Error if**: Missing either tag or improperly paired
### Check 3: Head Section
**Requirement**: Complete `` section with metadata
```html
...
```
**Checks**:
- [ ] `` and `` tags present
- [ ] `` present
- [ ] `` present (warning if missing)
- [ ] `` tag with content present
- [ ] CSS `` tag present with href attribute
**Error if**: Missing charset, title, or CSS link
**Warning if**: Missing viewport meta tag
### Check 4: Body Section
**Requirement**: Proper `` tags with content
```html
` present
- [ ] `` present inside container
- [ ] Body contains substantial content (> 100 bytes)
**Error if**: Missing tags or required container divs
### Check 5: Tag Closure Validation
**Requirement**: All tags must be properly closed
**Checks for**:
- Unmatched opening tags (e.g., `
` without `
`)
- Improper nesting (e.g., `
text
`)
- Self-closing tags used correctly (e.g., ` `, ``)
- Comment blocks properly formatted (``)
**Validation method**:
- Parse HTML into tree structure
- Verify all nodes properly matched
- Check nesting doesn't violate HTML5 rules
**Error if**: Any unmatched or improperly nested tags
### Check 6: Heading Tags (h1-h6)
**Requirement**: Valid heading hierarchy
```html
Chapter Title
Section Heading
Subsection
```
**Checks**:
- [ ] All heading tags properly closed
- [ ] First heading should be h1 (warning if not)
- [ ] Heading levels don't skip dramatically (h1 → h4 is suspicious)
- [ ] All headings have text content (not empty)
**Error if**: Heading tags improperly closed
**Warning if**: Suspicious hierarchy
### Check 7: Content Structure
**Requirement**: Meaningful content in page container
**Checks**:
- [ ] `` contains elements
- [ ] Content includes headings or paragraphs
- [ ] No completely empty content area
- [ ] Text nodes or elements present (> 100 words total)
**Error if**: No content or empty structure
### Check 8: List Integrity
**Requirement**: All lists properly structured
**Checks** for each `
` or ``:
- [ ] List opening and closing tags matched
- [ ] List contains `