Skip to the content.

Attributes

Attributes are key-value pairs that configure elements and provide metadata. They are defined within parentheses (...) as a section of standard-syntax elements, containers, meta-elements, and headers.

Table of Contents

Syntax

Attribute syntax uses key-value pairs separated by semicolons and/or newlines:

(
    key1: value1
    key2: value2
    key3: value3
)

(key1: value1; key2: value2)

(
    key1: value1;
    key2: value2;
    key3: value3
)

Data Types

Attributes can have different data types that define what values they can contain and how they are validated. .chalk supports both built-in primitive data types and custom data types defined in your library.

See the Primitives Reference for complete details on each type.

Examples

element(
    // String attribute
    title: My Title

    // Number attribute
    count: 42

    // Boolean attribute - explicit values
    enabled: true
    disabled: false
    
    // Boolean attribute - shorthand (identifier means true)
    interactive
    visible
    
    // Boolean attribute - negation (!identifier means false)
    !hidden
    !collapsed

    // String list attribute
    tags: javascript, react, frontend

    // Formatted string attribute
    description: This supports **bold** and *italic* text

    // Email attribute
    contact: user@example.com

    // Date attribute
    published: 2024-12-19

    // URL attribute
    link: https://example.com/page

    // RGB colour attribute
    colour: #ff5733
)

Attribute Validation