# plain.elements **Build reusable HTML components using a tag-based syntax.** - [Overview](https://plainframework.com/docs/plain-elements/plain/elements/?llm#overview) - [Passing attributes](https://plainframework.com/docs/plain-elements/plain/elements/?llm#passing-attributes) - [Nested content with `children`](https://plainframework.com/docs/plain-elements/plain/elements/?llm#nested-content-with-children) - [Namespaced elements](https://plainframework.com/docs/plain-elements/plain/elements/?llm#namespaced-elements) - [FAQs](https://plainframework.com/docs/plain-elements/plain/elements/?llm#faqs) - [Installation](https://plainframework.com/docs/plain-elements/plain/elements/?llm#installation) ## Overview Elements give you a component-like syntax for HTML templates. Instead of using Jinja `{% include %}` or macros, you write components as `.html` files and use them with capitalized HTML tags like ` ``` To use elements in a template, add `{% use_elements %}` at the top. Then use your element with its capitalized tag name. ```html {% use_elements %}
``` The output will be: ```html
``` ## Passing attributes You can pass attributes to elements in two ways: as strings or as Python expressions. String attributes use standard HTML syntax: ```html {% use_elements %} ``` Python expressions use single braces `{}`: ```html {% use_elements %} ``` Inside the element template, attributes become template variables: ```html ``` By default, Plain raises an error for undefined variables. Use the `|default` filter or `is defined` test for optional attributes. ## Nested content with `children` Content between opening and closing tags is available as the `children` variable. ```html
{{ children }}
``` ```html {% use_elements %}

Welcome

This content appears inside the card body.

``` Self-closing elements don't have children: ```html {% use_elements %} ``` ## Namespaced elements You can organize elements into subdirectories. This is particularly useful for reusable packages or grouping related components. Put the element template in a subdirectory of `templates/elements/`: ```html ``` Use the dot-separated path as the tag name: ```html {% use_elements %} ``` ## FAQs #### Can I nest the same element inside itself? No. Elements cannot be nested inside themselves to prevent infinite recursion. If you need recursive structures, split them into separate element types. #### Why use capitalized tag names? Capitalized names like `