# a-h/templ

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/a-h-templ).**

10,358 stars · 360 forks · Go · MIT

## Links

- GitHub: https://github.com/a-h/templ
- Homepage: https://templ.guide/
- awesome-repositories: https://awesome-repositories.com/repository/a-h-templ.md

## Topics

`go` `html-elements` `htmx` `ide-support` `language-server` `lsp` `server-side-rendering` `templating-languages`

## Description

Templ is a type-safe HTML templating engine and UI framework for Go. It provides a system for building reusable HTML components that compile into Go code for server-side rendering, ensuring type safety and compile-time validation of data and logic.

The project features a dedicated language server that provides autocomplete and syntax validation for template files within supported code editors. It employs compile-time code generation to transform a custom template language into Go source code, enabling the creation of modular HTML fragments and logic blocks.

The framework includes automated security mechanisms to prevent cross-site scripting through HTML escaping, CSS class and value sanitization, and resource URL validation. It supports various output targets, including streaming content to response writers for web interfaces or producing standalone files for static site generation.

A command line interface is provided to handle the generation of Go source code and the formatting of markup and template files.

## Tags

### Software Engineering & Architecture

- [Compile-Time Code Generation](https://awesome-repositories.com/f/software-engineering-architecture/compile-time-code-generation.md) — Transforms a custom template language into type-safe Go source code during the build process.
- [Template Syntax Validators](https://awesome-repositories.com/f/software-engineering-architecture/template-integrity-validators/template-syntax-validators.md) — Parses template files during the build process to ensure type safety and structural correctness.

### Web Development

- [HTML Templating Engines](https://awesome-repositories.com/f/web-development/html-templating-engines.md) — Implements a type-safe HTML templating engine that compiles templates into Go code for server-side rendering.
- [HTML Response Renderers](https://awesome-repositories.com/f/web-development/html-rendering/html-response-renderers.md) — Provides capabilities to write type-safe templates directly to a response writer for delivering web content. ([source](https://templ.guide/server-side-rendering/creating-an-http-server-with-templ))
- [Markup Compilers](https://awesome-repositories.com/f/web-development/markup-compilers.md) — Transforms declarative HTML-like syntax into optimized, type-safe component structures at build time. ([source](https://templ.guide/syntax-and-usage/basic-syntax))
- [Server-Side Rendering](https://awesome-repositories.com/f/web-development/server-side-rendering.md) — Generates HTML dynamically on the server to serve content to clients. ([source](https://templ.guide/))
- [Type-Safe UI Frameworks](https://awesome-repositories.com/f/web-development/type-safe-ui-frameworks.md) — Offers a UI framework that ensures type safety and compile-time validation for HTML components.
- [Web Components](https://awesome-repositories.com/f/web-development/web-components.md) — Provides a system for creating a library of modular HTML fragments and logic blocks to compose web pages.
- [Web Framework Integrations](https://awesome-repositories.com/f/web-development/web-framework-integrations.md) — Enables rendering dynamic HTML templates within various HTTP routing systems to serve content to web clients. ([source](https://templ.guide/integrations/web-frameworks))
- [Static HTML Generators](https://awesome-repositories.com/f/web-development/rendering-templating/server-side-rendering-utilities/static-html-generators.md) — Outputs rendered component content as standalone static HTML files using standard writer interfaces. ([source](https://templ.guide/static-rendering/generating-static-html-files-with-templ))
- [Custom Rendering Logic](https://awesome-repositories.com/f/web-development/server-side-rendering/custom-rendering-logic.md) — Allows implementing a component interface using raw code to manually control HTML output generation. ([source](https://templ.guide/core-concepts/components))
- [Static Site Generation](https://awesome-repositories.com/f/web-development/static-site-generation.md) — Renders Go components into standalone HTML files for deployment on static hosting environments.

### Development Tools & Productivity

- [Template Compilation Tools](https://awesome-repositories.com/f/development-tools-productivity/build-tooling/template-compilation-tools/template-compilation-tools.md) — Transforms custom template files into type-safe functions that return renderable HTML components during the build phase. ([source](https://templ.guide/static-rendering/generating-static-html-files-with-templ))
- [Language Server Protocol Implementations](https://awesome-repositories.com/f/development-tools-productivity/language-server-protocol-implementations.md) — Implements the Language Server Protocol to provide real-time syntax highlighting and autocomplete within code editors.
- [Language Servers](https://awesome-repositories.com/f/development-tools-productivity/language-servers.md) — Implements the Language Server Protocol to enable autocomplete and syntax validation within supported code editors. ([source](https://templ.guide/developer-tools/cli))

### Programming Languages & Runtimes

- [HTML Compilation](https://awesome-repositories.com/f/programming-languages-runtimes/compile-time-safe-templates/html-compilation.md) — Compiles a custom templating language into Go source code to produce type-safe user interfaces. ([source](https://cdn.jsdelivr.net/gh/a-h/templ@main/README.md))
- [Go Code Generators](https://awesome-repositories.com/f/programming-languages-runtimes/go-code-generators.md) — Transforms template files into idiomatic and type-safe Go source code. ([source](https://templ.guide/developer-tools/cli))
- [Component Compilers](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-compilers/multi-target-compilers/component-compilers.md) — Compiles markup and logic into Go functions that render HTML using loops and conditionals. ([source](https://templ.guide/core-concepts/components))

### Security & Cryptography

- [Cross-Site Scripting Prevention](https://awesome-repositories.com/f/security-cryptography/cross-site-scripting-prevention.md) — Automatically escapes user-provided data in HTML attributes and tags to block script injection. ([source](https://templ.guide/security/injection-attacks))
- [XSS Protections](https://awesome-repositories.com/f/security-cryptography/xss-protections.md) — Provides built-in sanitization and encoding to prevent cross-site scripting attacks during HTML rendering.
- [URL Protocol Sanitizers](https://awesome-repositories.com/f/security-cryptography/security/application-and-web/web-application/security-sanitization/url-protocol-sanitizers.md) — Validates URL attributes to remove JavaScript-based links and ensure only safe protocols are used. ([source](https://templ.guide/security/injection-attacks))

### User Interface & Experience

- [Component Composition](https://awesome-repositories.com/f/user-interface-experience/component-architectures/component-composition.md) — Organizes user interfaces into reusable functions and types that can be nested to build complex pages.
- [Reusable UI Components](https://awesome-repositories.com/f/user-interface-experience/reusable-ui-components.md) — Enables the construction of reusable HTML fragments and modular interface elements. ([source](https://templ.guide/))
- [Escaping Utilities](https://awesome-repositories.com/f/user-interface-experience/html-content-processing/html-content-processing/escaping-utilities.md) — Automatically encodes dynamic text content to prevent cross-site scripting and malicious script injection.
- [UI Component Libraries](https://awesome-repositories.com/f/user-interface-experience/ui-component-libraries.md) — Templurn supports integrating collections of pre-made HTML elements like buttons and cards into a project. ([source](https://templ.guide/component-libraries/))
- [Type-to-Component Mappings](https://awesome-repositories.com/f/user-interface-experience/view-to-data-mappings/type-to-component-mappings.md) — Ties the user interface directly to data structures by returning components from methods attached to types. ([source](https://templ.guide/core-concepts/components))

### Content Management & Publishing

- [Static Page Rendering](https://awesome-repositories.com/f/content-management-publishing/static-page-rendering.md) — Produces standalone HTML files optimized for deployment on static hosting environments. ([source](https://templ.guide/))
