INI files consist of sections and properties (key-value pairs).
Browse / INI File Cheatsheet
INI File Cheatsheet
A practical reference covering the syntax, structure, and common conventions for working with INI configuration files.
INI Basics & Syntax
File Structure
|
Sections group properties logically. |
There is typically a global section before the first named section (though not always explicitly used). |
Order of sections and keys within sections is generally not guaranteed unless the parser explicitly supports it. |
Example structure:
|
Blank lines are usually ignored and used for readability. |
Leading/trailing whitespace around section names, keys, and values is often trimmed by parsers. |
Sections
Define a section using square brackets |
|
Section names are typically case-insensitive, but this depends on the parser. |
(Depends on parser) |
A section applies to all subsequent key-value pairs until the next section is defined. |
|
The default (global) section has no header. |
|
Avoid special characters in section names unless specifically supported by your parser. |
Stick to alphanumeric characters, hyphens, and underscores. |
Empty sections are valid but usually don’t have an effect. |
|
Key-Value Pairs
Properties are defined as |
|
Whitespace around the |
All usually parsed as |
Keys within the same section should be unique. |
If duplicated, the parser might use the first, the last, or report an error. |
Key names are often case-insensitive. |
(Depends on parser) |
Values can contain various characters. Support for special characters ( |
Quoting values ( |
Trailing comments on a key-value line are usually not supported in standard INI. Comments must start at the beginning of a line. |
|
Comments
Lines starting with |
|
Comments must be on their own line. Trailing comments on value lines are non-standard. |
|
Comments are ignored by the parser. |
Use comments to explain sections, keys, or provide context. |
You can comment out lines to temporarily disable them. |
|
Blank lines can also function as visual separators, enhancing readability, and are ignored by parsers. |
|
Case Sensitivity & Whitespace
Section names and key names are conventionally case-insensitive, but this is parser-dependent. |
|
Values are typically case-sensitive unless the parser applies specific type-casting rules (e.g., for booleans). |
|
Leading and trailing whitespace around section names, keys, and values is usually trimmed. |
Often parsed as |
Whitespace within values is generally preserved, especially if the value is quoted. |
|
Whitespace around the |
All treated equally. |
INI Data Types & Best Practices
Values & Data Types
INI values are inherently strings. |
Parsing libraries interpret values into specific data types (integers, booleans, floats, etc.) based on conventions or explicit type hints (less common). |
Common conventions for Booleans:
|
Common conventions for Numbers:
|
Strings:
|
Array-like values:
|
Quoting and Escaping
Standard INI doesn’t define quoting or escaping. |
Parser behavior is key here. |
Many parsers support quoting values with |
|
How to include quotes within a quoted string? Parser-dependent. |
|
How to include |
|
Newlines in values:
|
Stick to single-line values for maximum compatibility. |
Best Practices & Tips
Keep it simple: INI is designed for simple key-value pairs and sections. Avoid complex nested structures. |
Use consistent casing: Even if the parser is case-insensitive, use consistent casing for keys and sections (e.g., camelCase, snake_case) for readability. |
Add comments: Explain sections, keys, and non-obvious values. Use |
Use blank lines: Separate sections and groups of related keys for better readability. |
Avoid special characters: Limit section and key names to alphanumeric, hyphens, and underscores for best compatibility. |
Be mindful of your parser: INI parsing is not strictly standardized. Features like quoting, escaping, case-sensitivity, and array handling vary. Consult your library’s documentation. |
Prefer simple values: If you need complex data structures (lists, nested objects), consider formats like JSON, YAML, or XML. |
Common Pitfalls
Trailing Comments: Placing comments after a key-value pair ( |
Case Sensitivity: Assuming case-insensitivity for keys/sections without checking the parser’s behavior. |
Whitespace: Relying on significant leading/trailing whitespace in keys or values without using quotes (and checking parser support for quotes). |
Duplicate Keys: Defining the same key multiple times within a section can lead to unpredictable results (first wins, last wins, error). |
Special Characters in Values: Using |
Complex Data: Trying to represent lists, dictionaries, or nested structures directly in standard INI syntax. INI is flat. |
Non-standard Features: Using features like includes, variable interpolation, or specific escape sequences unless explicitly supported by the target parser. |