PHPackages                             ksfraser/html - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ksfraser/html

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ksfraser/html
=============

HTML project for Ksfraser

2.0.7(1mo ago)05↓100%PHPPHP &gt;=7.3

Since Oct 31Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/ksfraser/html)[ Packagist](https://packagist.org/packages/ksfraser/html)[ RSS](/packages/ksfraser-html/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (1)Versions (10)Used By (0)

Ksfraser HTML Library
=====================

[](#ksfraser-html-library)

A powerful, trait-based PHP HTML generation library using SOLID principles, comprehensive trait composition, and test-first development (TDD).

Overview
--------

[](#overview)

The Ksfraser HTML Library provides a fluent, type-safe interface for programmatically building HTML documents. It emphasizes:

- **Trait Composition**: Models feature responsibility through composable traits rather than class hierarchies
- **SOLID Principles**: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion
- **Fluent Interface**: Method chaining for intuitive element construction
- **Type Safety**: Strong typing with HtmlElementInterface and attribute validation
- **Accessibility**: Built-in ARIA support and semantic HTML5 elements
- **Extensibility**: Factory patterns for Bootstrap components and responsive utilities

Quick Start
-----------

[](#quick-start)

```
use Ksfraser\HTML\HtmlElement;

// Create a button
$button = HtmlElement::buttonPrimary('Click Me');

// Build a card with header and body
$card = HtmlElement::card()
    ->addNested(HtmlElement::cardHeader('Title'))
    ->addNested(HtmlElement::cardBody('Content'));

// Responsive section with semantic elements
$article = HtmlElement::article()
    ->displayFlex()
    ->alignItemsCenter()
    ->addNested(HtmlElement::heading('Main Title', 1))
    ->addNested(HtmlElement::paragraph('Introduction text'));

// Render to HTML
echo $article;
```

Features
--------

[](#features)

### Phase 1: Core Infrastructure (FR-001 to FR-010)

[](#phase-1-core-infrastructure-fr-001-to-fr-010)

- ✅ HTML element creation and rendering
- ✅ Attribute management with validation
- ✅ Fluent interface for method chaining
- ✅ Nested content composition
- ✅ Empty/void element support
- ✅ CSS class management (FR-006)
- ✅ Event handler attributes (FR-007)
- ✅ Data attributes for JavaScript integration (FR-008)
- ✅ ARIA accessibility attributes (FR-009)
- ✅ Element introspection and querying (FR-010)

### Phase 2: Enhanced Features (FR-011 to FR-014)

[](#phase-2-enhanced-features-fr-011-to-fr-014)

- ✅ **Form Elements &amp; Validation UI** (FR-011): Form building with labels, inputs, textareas, selects, validation feedback
- ✅ **Component Factory Pattern** (FR-012): 100+ factory methods for Bootstrap components (buttons, cards, alerts, badges, modals, navbars, pagination)
- ✅ **Responsive Layout Utilities** (FR-013): 50+ utility methods for responsive design (display, sizing, spacing, flexbox, grid, borders)
- ✅ **HTML5 Semantic Elements** (FR-014): 60+ factory methods for semantic HTML5 structure (article, nav, header, footer, etc.)

Integrated Traits
-----------------

[](#integrated-traits)

The HtmlElement class integrates 9 specialized traits providing focused responsibility:

1. **CSSManagementTrait** (FR-006)

    - 68+ tests | ~280 lines
    - CSS class management, conditional classes, bulk operations
2. **EventHandlerTrait** (FR-007)

    - 60+ tests | ~380 lines
    - JavaScript event handlers (onClick, onChange, onSubmit, etc.)
3. **DataAttributeTrait** (FR-008)

    - 50+ tests | ~220 lines
    - HTML5 data-\* attributes for JavaScript integration
4. **AriaAttributeTrait** (FR-009)

    - 80+ tests | ~350 lines
    - WCAG accessibility attributes and validation
5. **ElementIntrospectionTrait** (FR-010)

    - 70+ tests | ~360 lines
    - Query nested elements, attributes, methods introspection
6. **FormElementsTrait** (FR-011)

    - 70+ tests | ~500 lines
    - Form building: form, input, textarea, select, label, button, fieldset
    - Validation states and feedback rendering
7. **ComponentFactoryTrait** (FR-012)

    - 60+ tests | ~400 lines
    - Bootstrap components: buttons, cards, alerts, badges, modals, navbars, pagination
8. **ResponsiveLayoutTrait** (FR-013)

    - 80+ tests | ~300 lines
    - Display, sizing, spacing, flexbox, grid, typography, borders
9. **SemanticElementsTrait** (FR-014)

    - 100+ tests | ~500 lines
    - HTML5 semantic elements: article, nav, header, footer, heading, paragraph, tables, etc.

Architecture
------------

[](#architecture)

All features are implemented as composable traits:

```
HtmlElement (Core)
├── CSSManagementTrait
├── EventHandlerTrait
├── DataAttributeTrait
├── AriaAttributeTrait
├── ElementIntrospectionTrait
├── FormElementsTrait
├── ComponentFactoryTrait
├── ResponsiveLayoutTrait
└── SemanticElementsTrait

```

Requirements &amp; Documentation
--------------------------------

[](#requirements--documentation)

For detailed specifications and traceability:

- See [Functional Requirements](Project%20Docs/Functional_Requirements.md)
- See [Requirements Traceability Matrix](Project%20Docs/RTM.md)
- See [Architecture Guide](Project%20Docs/SOFTWARE_ARCHITECTURE_GUIDE.md)
- See [TDD Implementation Guide](Project%20Docs/TDD_IMPLEMENTATION_GUIDE.md)

Testing
-------

[](#testing)

Run the comprehensive test suite with PHPUnit:

```
composer test
# or
php vendor/bin/phpunit
```

**Test Coverage:**

- 250+ unit and integration test methods
- Phase 1: ~350 tests across 5 traits
- Phase 2: ~250 tests across 4 traits
- 100% trait coverage for all composed features

Requirements
------------

[](#requirements)

- PHP &gt;= 7.3
- PHPUnit &gt;= 9.6 (dev)

Installation
------------

[](#installation)

```
composer require ksfraser/html
```

License
-------

[](#license)

See [LICENSE](LICENSE) file for details.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance93

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 97% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~65 days

Total

3

Last Release

35d ago

Major Versions

1.0.0 → 2.0.12026-04-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/c8870cc04b29a973eed9ad367a936ab274d744de37ff0c35fa0540a932905271?d=identicon)[ksfraser](/maintainers/ksfraser)

---

Top Contributors

[![ksfraser](https://avatars.githubusercontent.com/u/54461925?v=4)](https://github.com/ksfraser "ksfraser (65 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ksfraser-html/health.svg)

```
[![Health](https://phpackages.com/badges/ksfraser-html/health.svg)](https://phpackages.com/packages/ksfraser-html)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
