Compatibility wrapper providing unified access to WHATWG HTML implementation with familiar API structure.
swift-html-standard is a lightweight wrapper around swift-whatwg-html that provides a simplified, unified API structure. It offers three main products for different use cases: complete HTML implementation, attributes-only, or elements-only.
This package serves as the recommended entry point for projects migrating from swift-html-types or seeking a simpler import structure than the modular swift-whatwg-html organization.
- Zero-cost abstraction: Direct re-exports with no wrapper types or runtime overhead
- Simplified imports: Three focused products instead of 26 individual modules
- Complete WHATWG compliance: Full backing by swift-whatwg-html implementation
- Flexible granularity: Import everything, just attributes, or just elements
- Type aliases: Convenient
HTMLElementandHTMLVoidElementaliases - Swift 6 concurrency: Full Sendable conformance with strict concurrency mode
- Migration path: Drop-in replacement for swift-html-types with minimal changes
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/swift-standards/swift-html-standard", from: "0.1.0")
]import HTML_Standard
// Access all HTML elements and attributes
let input = Input(
name: Name("email"),
disabled: nil,
form: nil,
type: .email(Input.Email(value: Value("")))
)import HTML_Standard_Attributes
// Access only HTML attribute types
let name = Name("username")
let placeholder = Placeholder("Enter username")
let required = Required()import HTML_Standard_Elements
// Access only HTML element types
let form = Form(
action: Action("/submit"),
method: Method.post,
enctype: EncType.multipart
)Complete implementation with all elements and attributes:
import HTML_Standard
// Everything is available
let video = Video(
src: Src("/video.mp4"),
controls: Controls(),
preload: Video.Preload.metadata
)All attribute modules (GlobalAttributes, FormAttributes, LinkAttributes, MediaAttributes, TableAttributes, ScriptAttributes, Metadata):
import HTML_Standard_Attributes
// Attribute types only
let href = Href("https://example.com")
let rel = Rel.stylesheet
let target = Target.blankAll element modules organized by WHATWG spec sections:
import HTML_Standard_Elements
// Element types with convenient aliases
typealias Element = HTMLElement // WHATWG_HTML.Element
typealias VoidElement = HTMLVoidElement // WHATWG_HTML.VoidElement
let section = Section()
let article = Article()The Elements product provides convenient aliases:
import HTML_Standard_Elements
// These are equivalent:
let element1: HTMLElement = ...
let element2: WHATWG_HTML.Element = ...
let void1: HTMLVoidElement = ...
let void2: WHATWG_HTML.VoidElement = ...Replace imports:
// Old
import HTMLTypes
import HTMLAttributeTypes
import HTMLElementTypes
// New
import HTML_Standard
import HTML_Standard_Attributes
import HTML_Standard_ElementsType names remain the same - only imports change.
- Swift 6.2+
- macOS 15.0+ / iOS 18.0+ / tvOS 18.0+ / watchOS 11.0+
- Swift 6 language mode with strict concurrency
swift-html-standard/
├── HTML Standard/ # Complete implementation
│ └── Re-exports WHATWG HTML
├── HTML Standard Attributes/ # Attributes only
│ ├── WHATWG HTML Shared
│ ├── WHATWG HTML GlobalAttributes
│ ├── WHATWG HTML FormAttributes
│ ├── WHATWG HTML LinkAttributes
│ ├── WHATWG HTML MediaAttributes
│ ├── WHATWG HTML TableAttributes
│ ├── WHATWG HTML ScriptAttributes
│ └── WHATWG HTML Metadata
└── HTML Standard Elements/ # Elements only
├── WHATWG HTML Shared
└── WHATWG HTML Elements
- Zero-cost wrapper: All types are re-exported directly, no intermediate layers
- Simplified organization: Three products instead of 26 modules
- Familiar structure: Matches expectations from swift-html-types
- Full compliance: Backed by complete WHATWG HTML Living Standard implementation
- Flexible imports: Choose the granularity you need
- swift-whatwg-html: Complete, modular WHATWG HTML Living Standard implementation
- swift-html-css-pointfree: Integration with pointfree-html for HTML generation
- swift-whatwg-html: WHATWG HTML implementation
- swift-rfc-2045: RFC 2045 MIME types
- swift-iso-8601: ISO 8601 date/time
- swift-standards: Shared utilities
Contributions are welcome! This package is a thin wrapper, so most contributions should go to swift-whatwg-html. For wrapper-specific issues:
- Ensure changes maintain zero-cost abstraction
- Tests pass with Swift 6.2
- Code follows existing style
This project is licensed under the Apache License 2.0. See LICENSE.md for details.