# Phlex

> Object-oriented views in Ruby

Source: https://talira.ai/catalog/phlex-xh5ps07b
Every listing: https://talira.ai/catalog.md

- Kind: Open source
- Types: Library, Framework
- Categories: [frameworks / rails / view components](https://talira.ai/categories/frameworks/rails/view-components), [languages / ruby / rails](https://talira.ai/categories/languages/ruby/rails), [languages / ruby](https://talira.ai/categories/languages/ruby)
- Licence: MIT[^1][^3]
- Pricing: Free and open source[^3]
- Pricing notes: Free and open source under MIT.
- Free tier: yes[^3]
- Self-hostable: yes[^4]
- Creator: Joel Drapper, who maintains it (GitHub Sponsors), with Will Cosgrove

Phlex is an MIT-licensed Ruby gem for building HTML, SVG and CSV views as plain Ruby classes: a component builds its markup with Ruby methods, keyword arguments and blocks instead of an ERB template, which makes unclosed tags hard to write and is designed to structurally prevent cross-site scripting. Because views are Ruby, tools like [RuboCop](https://talira.ai/catalog/rubocop-rxzhjmy8.md), Ruby LSP and [SimpleCov](https://talira.ai/catalog/simplecov-sp7ythxb.md) work on them, and the docs cover kits, caching, fragments, streaming and testing. `phlex-rails` integrates it with [Rails](https://talira.ai/catalog/ruby-on-rails-xkdcpj5k.md): it supports Rails helpers and works alongside ERB, [ViewComponent](https://talira.ai/catalog/viewcomponent-v7yr5dbn.md), [Stimulus](https://talira.ai/catalog/stimulus-p6z2qebs.md), Turbo and [Tailwind CSS](https://talira.ai/catalog/tailwind-css-wfchsr5n.md). It was made by Joel Drapper and Will Cosgrove.

## Links

- Website: https://www.phlex.fun/
- GitHub: https://github.com/yippee-fun/phlex
- Docs: https://www.phlex.fun/introduction/

## Problems it solves

- our Rails partials have grown into a mess of locals and conditionals that nobody can test
- write Rails views as Ruby classes instead of ERB templates so I can refactor them like normal code
- build a component library for a server-rendered Rails app without adopting a JavaScript framework
- lint, type-check and measure test coverage of my HTML views with the same Ruby tools as the rest of the app
- ERB makes it too easy to forget to escape user input in our Rails views
- rendering many small extracted view components in Rails gets slow
- generate SVG icons and CSV exports from the same Ruby view layer as my HTML
- a lighter alternative to Rails' ActionView for a Ruby web app that isn't Rails
- share UI components between several Ruby web apps as plain gems
- cache and stream fragments of server-rendered pages from Ruby view components

## Features

- HTML, SVG and CSV views written as Ruby classes
- structural templating that is designed to prevent cross-site scripting
- kits, caching, fragments, streaming, snippets and testing for components
- phlex-rails: Rails helpers, views and layouts, adoption guide for existing apps
- works alongside ERB, ViewComponent, Stimulus, Turbo and Tailwind CSS
- renders about 1.4 Gbps of HTML per core on an M3 Max MacBook Pro, by the project's own figure
- follows BreakVer, with security patches for recent minor versions

## Limitations

- Doesn't run on Ruby older than 3.2: phlex 2.x requires Ruby 3.2 or newer[^1]
- Doesn't support Rails before 7.1: phlex-rails 2.x requires railties 7.1 or newer (and below 9)[^2]

## Trust

Overall: 0.23 out of 1.
Signals: backing 0.20, extensibility 0.00.

- created by Joel Drapper, who maintains it (GitHub Sponsors), with Will Cosgrove

Warnings:

- GitHub activity not fetched yet

## Related

- Works with [Ruby on Rails](https://talira.ai/catalog/ruby-on-rails-xkdcpj5k.md)

## Alternatives

- [ViewComponent](https://talira.ai/catalog/viewcomponent-v7yr5dbn.md): A framework for building reusable, testable & encapsulated view components in Ruby on Rails

## Sources

[^1]: https://rubygems.org/gems/phlex (checked 20 Nov 2026)
[^2]: https://rubygems.org/gems/phlex-rails (checked 20 Nov 2026)
[^3]: https://github.com/yippee-fun/phlex/blob/main/LICENSE.txt (checked 20 Nov 2026)
[^4]: https://www.phlex.fun/ (checked 20 Nov 2026)
