Skip to content

swift-css

Development Status

Typed CSS for Swift HTML rendering — inline style methods, dark-mode color pairs, and named themes that emit light and dark CSS custom properties.


Key Features

  • Grouped property methods.css.frame(...), .css.spacing(...), .css.text(...), and .css.flexContainer(...) set related CSS properties in a single call and render as HTML inline styles.
  • Dark-mode colorsDarkModeColor stores light and dark values as one normalized pair, auto-deriving the dark variant when only a light color is supplied.
  • Named themesDarkModeColor.Theme ships palettes mirroring familiar systems (.github, .apple, .vapor, .slate, and more), each exposing semantic text, background, border, and branding color roles.
  • Stylesheet generationtheme.stylesheet emits CSS custom properties for every role, paired with a @media (prefers-color-scheme: dark) override block and matching utility classes.
  • Scoped themingprepareDependencies sets process-wide theme and font defaults; withDependencies overrides them for a single synchronous or asynchronous operation.

Quick Start

A single named theme value expands into a complete stylesheet — every semantic color as a CSS custom property, plus a @media (prefers-color-scheme: dark) block carrying the dark variants:

import CSS_Theming

let stylesheet = DarkModeColor.Theme.github.stylesheet

print(stylesheet)
// /* Generated Theme Stylesheet */
// :root {
//     --color-blue: ...;
//     --text-primary: ...;
// }
// @media (prefers-color-scheme: dark) {
//     :root { --color-blue: ...; }
// }

DarkModeColor.Theme.StyleSheet conforms to CustomStringConvertible, so it interpolates into any output directly.


Installation

dependencies: [
    .package(url: "https://github.com/swift-foundations/swift-css.git", branch: "main")
]
.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "CSS", package: "swift-css")
    ]
)

Requires Swift 6.3.1 and macOS 26 / iOS 26 / tvOS 26 / watchOS 26 / visionOS 26.


Architecture

Three library products. CSS Theming and CSS Test Support re-export CSS.

Product Import When to import
CSS import CSS Inline CSS property methods and the dark-mode color types.
CSS Theming import CSS_Theming Named themes, stylesheet generation, and scoped theming defaults; re-exports CSS.
CSS Test Support import CSS_Test_Support Test targets that snapshot rendered CSS; re-exports both library targets.

Community

Discussion thread will be created at first public release.

License

Apache 2.0. See LICENSE.

About

Typed CSS styling with dark-mode color pairs and named themes that emit light and dark CSS custom properties for Swift.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

Sponsor this project

Packages

Contributors

Languages