Overview

Master XML syntax rules, naming conventions, and property types used in LVGL Pro Editor for defining UI components.

LVGL Pro Editor uses standard XML syntax with special conventions for property names, values, and type definitions that follow LVGL API patterns.

Naming Conventions

  • Attribute names use lowercase letters with _ separation (e.g., bg_color, font_size)
  • Tag names must start with a letter or _ and can contain letters, _, and digits
  • Compound names use - as separator (e.g., lv_chart-series)
  • Color values are written in hex as 0x112233 or in a short form: 0x123, but not as #112233 (a value that starts with # is read as a legacy constant reference (see below), so the color is not set)
  • LVGL API alignment: Follow LVGL naming conventions (e.g., align="center", bg_color="0xff0000")
  • References: Use { } to reference anything by name: a <prop>, a constant, a subject, or a variant (e.g. width="{card_width}"). Inside the braces the name is written plain, and it can be part of a larger expression
  • Bindings: the same expression, reading a subject or a variant. It is re-evaluated whenever one of them changes; an expression without one is evaluated once, when the element is created
  • Legacy references: $param_name for a <prop> and #const_name for a constant. Each takes a single name, so it can't be part of an expression

Names and Scopes

Styles, constants, subjects, and animation timelines are all referenced by name. Every Component, Widget, and Screen has its own local scope, and globals.xml holds the global scope.

A name is looked up in the local scope first, and in the global scope only after that. Two consequences:

  • Two Components can use the same local name freely. Their scopes never see each other.
  • A local name hides a global one. If a Component defines style_card and globals.xml defines style_card too, that Component always gets its own.

Keeping names unique within one scope is your responsibility. Nothing reports a collision, so give every style, constant, subject, timeline, and widget name="..." a distinct name. Two cases make a collision easy to miss:

  • In an expression a bare name is resolved in a fixed order: per-instance names (a variant, a bindable property, a local subject), then property, constant, subject. The first match wins, so a constant named temperature hides a subject of the same name.
  • A name="..." is found by searching the widget tree and the first match is used, so two widgets with the same name make animation targets and lv_obj_find_by_name() ambiguous.

A prefix per kind keeps them apart: style_card, subject_temperature, timeline_load.

Component, Widget, and Screen names come from their file names and are kept separately, so h3.xml never collides with a style, constant, or subject named h3.

Property Names

Most XML properties use standard syntax without special formatting:

xml
<some_tag prop="value" other_prop="other value"/>

Style selectors can be added to property names for advanced styling:

xml
<lv_checkbox style_bg_color-indicator-checked-disabled="0xff0000"/>

Types

All types can be used as API property types. Some types are also supported for constants and observer subjects.

Simple Types

TypeDescriptionExample
boolBoolean valuetrue or false
intInteger (-2B to 2B, equivalent to int32_t)42, -100
pxPixel units (unit can be omitted)10, 10px
%Percentage (must include % unit)50%, 100%
contentAuto-sizing constant (LV_SIZE_CONTENT)content
stringNull-terminated string"hello", "'a' 'b'" (multiple)
color24-bit RGB color value0xff0000, 0xf00
opaOpacity (0-255 or 0-100%)128, 50%
lv_objWidget object pointerReference to widget
screenScreen object pointerReference to screen
time_msTime in milliseconds500, 1000
deg_0.1Degrees with 0.1 resolution45.5, 180
scale_1/256Scale/Zoom (256=100%, 128=50%)256, 512
style_propStyle property namebg_opa, text_color

LVGL's XML parser follows the HTML standard where there are reserved characters in property values. For example ", ', <, >, and new line.

So this is invalid: value="I'm here". The ' needs to be escaped as "I&apos;m here".

The Editor show a little popup when you click on a string property, where you can write text in the normal way, and the editor will handle the escaping.

Text editor popup in the Editor to automatically escape reserved XML characters

Name-Based Types

In XML files, fonts, images, styles, and other assets are referenced by name, not by pointer:

xml
<style name="red" bg_color="0xff0000"/>

The same names can also be used as <prop> types so a Component can accept an asset as a parameter. The values are resolved against items registered in globals.xml:

TypeLooks upExample
imageAn image registered under <images><prop name="src" type="image" default="img_power"/>
fontA font registered under <fonts><prop name="title_font" type="font" default="montserrat_22"/>
subjectA subject registered under <subjects><prop name="subject" type="subject" default="subject_dimmer1"/>
styleA style defined in <styles> or globals.xml<prop name="extra_style" type="style"/>

These props are typically forwarded into a child element by name, e.g. <lv_image src="{src}"/> or <lv_slider bind_value="{subject}"/>.

A style prop names a style of the Component that passes it, and it is resolved there:

xml
<!-- card.xml -->
<component>
    <api>
        <prop name="outline" type="style"/>
    </api>
    <view extends="lv_obj">
        <style name="{outline}"/>
    </view>
</component>

<!-- The style belongs to the file that uses the card -->
<card outline="style_focus_ring"/>

A name is a literal or a { } expression of properties and constants. The Editor has to resolve the name to check that the style, font, image, and so on exists, so it can't wait for a subject.

Automatic binding occurs for:

  • Styles, fonts, images, animations
  • Gradients and other visual components
  • Components and globals registered in globals.xml

Manual binding is required for:

  • Event callbacks (only available in code)
  • Custom fonts or images stored in memory

To register name-data pairs, see the Editor Integration guide.

Arrays

Arrays can be defined in three ways:

SyntaxDescription
int[5]Array with a fixed set of elements.
string[NULL]Array terminated with a NULL element. NULL can be any other string too, for example grid_dsc[LV_GRID_TEMPLATE_LAST].
int[count]The number of elements is passed to the C API as a separate parameter. Used by lv_chart's values, lv_animimg's src, and lv_line's points.
string[]No termination or count parameter

The termination of the array is important only to

  1. Validate the correctness of the XML files
  2. Generate correct code

The items in the array are separated by spaces and the termination is not included. For example

If there is an <api> property like <prop name="values" type="int[3]"/> it can be used as <my_widget values="10 33 55"/>

String items need to be wrapped in ' because an item can be composed of multiple words, so a space alone can't be used as a separator. For example <prop name="list" type="string[NULL]"/> it can be used as: <my_widget values="'This is the first' 'The second' '3rd'"/>

Enums

Custom enums for Widgets can be created using enumdef (not supported for Components):

xml
<api>
  <enumdef name="my_widget_mode" help="Possible modes">
    <enum name="normal" value="0x10" help="Normal mode"/>
    <enum name="inverted" help="Inverted mode"/>
  </enumdef>

  <prop name="mode" type="enum:my_widget_mode" help="Select mode"/>
</api>

Multiple enum values with + suffix allow OR'ing values:

xml
type="axis+"  <!-- Allows selecting multiple axis values -->
axis="primary_x|secondary_y"  <!-- Separate with | -->

Compound Types

Types can be combined to allow multiple options. For example:

xml
type="px|%|content"  <!-- Accepts pixels, percentage, or auto-size -->

Limiting Accepted Values

This feature is planned but not yet supported. The examples below show the intended syntax.

You can restrict possible values for enums, colors, and strings:

xml
<!-- Enum with limited options -->
type="dir(top bottom)"

<!-- Color with color palette -->
type="color(0xff0000 0x00ff00 0x0000ff)"

<!-- String with fixed options -->
type="string('Ok' 'Cancel')"

Last updated on

On this page