Turtle Syntax

Reading and writing Turtle, the text format for RDF data.

Turtle is a text format for writing RDF triples. It's what .ttl files contain. This page covers the syntax.

Statements

A triple ends with a period:

people:alice vocab:name "Alice Chen" .

Semicolons: Same Subject

When multiple triples share the same subject, use semicolons to avoid repeating it:

people:alice
    a vocab:Person ;
    vocab:name "Alice Chen" ;
    vocab:email "alice@example.com" ;
    vocab:department departments:engineering .

This is four triples, all about people:alice. The last one ends with a period.

Commas: Same Subject and Predicate

When triples share both subject and predicate, use commas:

people:alice vocab:skills "Python" , "RDF" , "SPARQL" .

Three triples: Alice has three skills. You can combine semicolons and commas:

people:alice
    a vocab:Person ;
    vocab:skills "Python" , "RDF" ;
    vocab:manages projects:q3 , projects:q4 .

Prefix Declarations

Prefixes appear at the top of the file:

@prefix people: <https://example.org/people/> .
@prefix vocab:  <https://example.org/vocab/> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .

The @prefix keyword, the short name, the full namespace in angle brackets, and a period.

Base URI

The @base declaration sets a default namespace:

@base <https://example.org/vocab/> .

Blank Nodes

A blank node is an anonymous resource with no URI. Use square brackets:

people:alice vocab:address [
    vocab:street "123 Main St" ;
    vocab:city "Portland" ;
    vocab:state "OR"
] .

The [ ... ] is a blank node. It's a resource that exists only as part of this structure. Blank nodes can be nested.

Multi-Line Strings

Triple-quoted strings span multiple lines:

vocab:greeting vocab:message """
Hello,
this is a multi-line
string value.
""" .

Useful for embedding longer text content.

RDF Lists

Parentheses create ordered lists:

vocab:primaryColors vocab:items (
    vocab:Red
    vocab:Blue
    vocab:Yellow
) .

This is an rdf:List with three elements. The order is preserved.

The a Keyword

a is shorthand for rdf:type:

people:alice a vocab:Person .
# same as:
people:alice rdf:type vocab:Person .

Comments

Lines starting with # are comments:

# Organization vocabulary
vocab:Person a rdfs:Class ;
    rdfs:label "person" .  # Display name

Putting It Together

A complete .ttl file describing people and projects:

@prefix vocab:   <https://example.org/vocab/> .
@prefix people:  <https://example.org/people/> .
@prefix projects:<https://example.org/projects/> .
@prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd:     <http://www.w3.org/2001/XMLSchema#> .

# Classes (like class definitions in OOP)
vocab:Person a rdfs:Class ;
    rdfs:label "person" .

vocab:Employee a rdfs:Class ;
    rdfs:subClassOf vocab:Person ;
    rdfs:label "employee" .

vocab:Project a rdfs:Class ;
    rdfs:label "project" .

# Properties (like fields on a class)
vocab:name a rdf:Property ;
    rdfs:domain vocab:Person ;
    rdfs:range xsd:string ;
    rdfs:label "name" .

vocab:email a rdf:Property ;
    rdfs:domain vocab:Person ;
    rdfs:range xsd:string ;
    rdfs:label "email" .

vocab:manages a rdf:Property ;
    rdfs:domain vocab:Person ;
    rdfs:range vocab:Project ;
    rdfs:label "manages" .

# Data (like instances/objects)
people:alice a vocab:Employee ;
    vocab:name "Alice Chen" ;
    vocab:email "alice@example.com" ;
    vocab:manages projects:q3 .

projects:q3 a vocab:Project ;
    vocab:name "Q3 Planning" .

Prefixes at the top, then definitions using semicolons to group properties on each resource.

See Also

On this page