| Crates.io | bevy_flair |
| lib.rs | bevy_flair |
| version | 0.5.0-rc.1 |
| created_at | 2025-01-24 11:27:05.733322+00 |
| updated_at | 2025-09-22 10:24:30.716729+00 |
| description | Bevy UI styling using CSS |
| homepage | |
| repository | https://github.com/eckz/bevy_flair |
| max_upload_size | |
| id | 1529312 |
| size | 1,923,906 |
Bevy Flair brings CSS-like styling to Bevy UI, letting you define appearance and layout using familiar CSS syntax.
It enables you to style UI components, taking advantage of the power of CSS.
Apply CSS assets directly to Bevy UI elements.
Inherited stylesheets. Specify a NodeStyleSheet on a root node and all children inherit it automatically.
Property inheritance support (e.g. color, font-family).
Font loading with @font-face.
Animated property changes via transition.
Custom animations with @keyframes.
Hot-reloading: edit your .css file and see styles re-applied on the fly.
Broad support for existing Bevy UI components and properties:
Node properties are supported.BorderColor, BackgroundColor, BorderRadius, Outline, BoxShadow, UiTransform and ZIndex
are supported, and inserted automatically when the corresponding property is used (e.g. using background-color: red will automatically insert the BackgroundColor component )linear-gradient(), radial-gradient() or conic-gradient().Shorthand properties like border, grid, margin, etc.
margin becomes margin-left, margin-right, etc.Non-standard CSS extensions for ImageNode
background-image: url("panel-border-030.png"), -bevy-image-mode: sliced(20.0px).Color parsing. (e.g. red,#ff0000,rgb(255 0 0),hsl(0 100% 50% / 50%),oklch(40.1% 0.123 21.57))
Common CSS selectors and combinators (via selectors crate):
Attribute selectors (via AttributeList).
Nested selectors: e.g. &:hover { ... }.
Importing other stylesheets with @import.
Custom properties with var() (Fallback is currently not supported).
Basic calc() expressions (mainly useful with variables).
Val types. This wouldn't work: calc(100% - 20px).calc(var(--spacing) * 2).@media queries (prefers-color-scheme, width, height, resolution, aspect-ratio).
@layer support.
Inline CSS properties.
Pseudo-elements ::before and ::after (enabled with PseudoElementsSupport).
Different stylesheets per subtree. With the use of a different NodeStyleSheet per subtree. It's even possible to not apply any style for a given subtree.
Use of custom times for transitions and animations (See https://github.com/eckz/bevy_flair/blob/main/examples/animations.rs).
Supports for custom properties. (Example TBA).
Supports for custom parsing. (See https://github.com/eckz/bevy_flair/blob/main/examples/custom_parsing.rs)
Only one stylesheet per entity (workaround: by using @import).
No global stylesheets.
No real support for !important.
!important is detected but ignored with a warning.Limited font support: only single fonts via @font-face. No local or fallback fonts.
No advanced color functions like color-mix() or relative color syntax (e.g. lch(from blue calc(l + 20) c h)).
No individual animation or transition properties like animation-name, transition-duration, etc.
Example styled entirely with CSS:
https://github.com/user-attachments/assets/792b9cfa-42fb-4e50-a85f-8d21aafeb1e5
Add bevy_flair to your Cargo.toml.
Create your UI structure and attach NodeStyleSheet the root:
main.rs:
use bevy::prelude::*;
use bevy_flair::prelude::*;
fn main() {
App::new()
.add_plugins((DefaultPlugins, FlairPlugin))
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
commands.spawn(Camera2d);
commands.spawn((
Node::default(),
NodeStyleSheet::new(asset_server.load("my_stylesheet.css")),
children![(Button, children![Text::new("Button")])],
));
}
Save your css file under assets/my_stylesheet.css:
:root {
display: flex;
width: 100%;
height: 100%;
align-items: center;
justify-content: center;
/* font-size and color are inherited */
font-size: 35px;
color: rgb(30% 30% 30%);
}
button {
display: flex;
align-items: center;
justify-content: center;
width: 150px;
height: 65px;
background-color: rgb(15%, 15%, 15%);
border-radius: 10px;
transition: background-color 0.5s;
&:hover {
color: #ddd;
background-color: rgb(30%, 30%, 25%);
}
&:active {
color: #ddd;
background-color: rgb(35%, 65%, 35%);
}
text {
/* Color transitions need to happen in the text element */
transition: color 0.5s;
}
}
Another good place to start are the examples in the examples folder.
initial values, which uses the component's default value.animation or transition is quite possible not 100% consistent with the standard.em, or properties like text-decoration).| bevy | bevy_flair |
|---|---|
| 0.17 | 0.5 |
| 0.16 | 0.2, 0.3, 0.4 |
| 0.15 | 0.1 |
Contributions are welcome! Feel free to fork the repository and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.
The assets included in this repository (for our examples) fall under different open licenses.