Why does frontend development have to be so complicated?
A simple intention, such as placing three elements vertically in the centre of a page, requires developers to understand markup, styling, layout models, alignment axes and various implementation details.
This made me question something more fundamental:
Why can't we express our intentions directly and let the compiler handle the implementation?
That question led me to create Fgen — short for Frontend Generator.
Fgen is an experimental, open-source, declarative frontend language that compiles human-readable instructions directly into HTML and CSS.
What does Fgen look like?
Here is a complete Fgen program:
page Home: background whitesmoke padding 40 spacing 24 align center justify center heading "Hello World": size 40 color navy text "My own frontend language": size 20 button "Get started": background navy color white padding 16 rounded 8 Save this as hello.ui and compile it:
python3 compiler.py hello.ui Fgen generates a complete HTML document that can be opened directly in a browser.
No closing tags. No CSS selectors. No frontend framework required.
The philosophy behind Fgen
I am not simply trying to make HTML and CSS shorter.
I want to reduce the cognitive complexity of frontend development.
Fgen is built around several fundamental principles:
- Developers should express intentions rather than implementation details.
- Structure, styling and layout should coexist naturally.
- Anything that can be logically inferred should not need to be explicitly instructed.
- Anything that can be defined once should not need to be defined repeatedly.
- Generated output should remain compatible with existing web standards.
For example, creating a horizontal layout should simply mean writing:
row: spacing 20 button "Continue" button "Cancel" The compiler understands that a row implies a horizontal layout and generates the appropriate CSS automatically.
The developer does not need to configure Flexbox manually.
How the compiler works
Fgen is currently implemented in Python with zero third-party runtime dependencies.
The compiler consists of four fundamental stages:
Fgen source code (.ui) | v Lexer | v Parser | v Abstract Syntax Tree | v Code Generator | v HTML + CSS 1. Lexical analysis
The lexer converts raw source code into tokens.
For example:
heading "Hello World" Becomes:
("KEYWORD", "heading") ("STRING", "Hello World") ("NEWLINE", "\n") ("EOF", None) Because Fgen uses indentation to establish hierarchy, the lexer also generates INDENT and DEDENT tokens.
A stack tracks indentation levels and determines when nested blocks begin and end.
2. Parsing
A recursive descent parser consumes these tokens and validates the language's grammar.
It establishes relationships between elements, properties and nested blocks.
For example:
column: heading "Hello World": size 32 color navy Produces an internal representation similar to:
{ "type": "column", "value": null, "properties": {}, "children": [ { "type": "heading", "value": "Hello World", "properties": { "size": 32, "color": "navy" }, "children": [] } ] } This Abstract Syntax Tree separates the meaning of the program from its textual representation.
3. Code generation
The generator recursively traverses the syntax tree and translates its nodes into HTML and CSS.
Layout elements receive implicit styling, while explicitly declared properties are translated into their corresponding CSS representations.
For example:
column: align center spacing 20 Automatically generates the equivalent of:
display: flex; flex-direction: column; align-items: center; gap: 20px; The browser receives ordinary web technologies. It does not need to understand Fgen itself.
Building Fgen's website using Fgen
I wanted to test the language against a practical problem rather than rely entirely on small examples.
So I built Fgen's official website using Fgen itself.
You can visit it here:
https://mughees0.github.io/fgen/
Building the website exposed several limitations that were less apparent while developing the compiler in isolation.
One particularly important discovery was unnecessary repetition.
Repeated visual elements currently require repeated declarations. That contradicts the very philosophy behind Fgen.
This experience has made reusable components and higher-level abstractions a core development priority.
Where I want to take the language
Imagine being able to define a reusable component:
component Card(title): column: background white padding 24 rounded 12 heading title And then reuse it:
use Card("Overview") use Card("Analytics") use Card("Settings") Or describe an entire visual sequence naturally:
flow vertical: connector "↓" use Stage("Source code") use Stage("Lexer") use Stage("Parser") use Stage("Code generator") These examples represent proposed future syntax, not currently implemented features.
The objective is to develop abstractions that allow developers to express increasingly complex interfaces without proportionally increasing implementation complexity.
Current project status
Fgen v0.1.0 has been publicly released under the MIT License.
The current implementation includes:
- Custom lexer
- Recursive descent parser
- Abstract Syntax Tree
- HTML and CSS generation
- Indentation-based syntax
- Automatic horizontal and vertical layouts
- Declarative styling
- Command-line compiler
- Programmatic compilation interface
- 21 passing automated tests
- Zero third-party runtime dependencies
Fgen currently supports static interfaces. It is not yet a complete replacement for modern frontend frameworks.
Try it yourself
Clone the repository:
git clone https://github.com/Mughees0/fgen.git cd fgen Compile an example:
python3 compiler.py examples/hello.ui Open the generated index.html in your browser.
Run the automated tests:
python3 -m unittest discover -s tests -v Building Fgen in the open
I do not want Fgen to remain an individual project.
I want it to evolve through open-source collaboration, experimentation and constructive criticism.
There are already open contribution issues covering:
- Lexer improvements
- Hexadecimal color support
- Compiler diagnostics
- Images and hyperlinks
- Forms and inputs
- Responsive layout architecture
- Reusable components
I am particularly interested in hearing from developers with experience in programming language design, compiler engineering and frontend architecture.
A question for the developer community
If you could redesign frontend development from first principles, without being constrained by the conventions of HTML and CSS, what would you change?
What would a genuinely natural frontend language look like?
I would like Fgen to become a practical exploration of those questions.
GitHub: https://github.com/Mughees0/fgen
Official website: https://mughees0.github.io/fgen/
First release: https://github.com/Mughees0/fgen/releases/tag/v0.1.0
Contribute: https://github.com/Mughees0/fgen/issues
All contributions, ideas and constructive criticism are welcome.
