What is INI?
INI (Initialization) is a simple configuration file format that uses plain text to store settings in a structured way. Originally popularized by Windows, INI files organize settings into sections with key-value pairs, making them easy to read and edit by humans.
Quick Tools
INI Syntax
INI files have a simple structure: sections enclosed in square brackets, followed by key-value pairs. Comments typically start with a semicolon (;) or hash (#).
Basic INI Example
; This is a comment # This is also a comment [database] host = localhost port = 5432 name = myapp user = admin [server] host = 0.0.0.0 port = 3000 debug = false [logging] level = info format = json
Syntax Rules
Sections
Sections group related settings together. Section names are enclosed in square brackets and are case-insensitive in many implementations.
[SectionName] key1 = value1 key2 = value2 [AnotherSection] key3 = value3
Key-Value Pairs
Each setting is a key-value pair separated by an equals sign (=) or colon (:). Whitespace around the separator is usually ignored.
[settings] ; These are equivalent name = John Doe name=John Doe name : John Doe
Values
Values can be strings, numbers, or booleans. Quotes around strings are optional but recommended for values with special characters.
[types] ; String values name = John Doe path = "C:\Program Files\App" ; Numeric values port = 8080 timeout = 30.5 ; Boolean values enabled = true debug = false active = yes disabled = no
Comments
; Semicolon comment (traditional) # Hash comment (also common) [database] host = localhost ; Inline comment (some parsers support this)
Real-World Examples
php.ini (PHP Configuration)
[PHP] engine = On short_open_tag = Off precision = 14 output_buffering = 4096 [Date] date.timezone = UTC [mail function] SMTP = localhost smtp_port = 25 [Session] session.save_handler = files session.gc_maxlifetime = 1440
my.cnf / my.ini (MySQL Configuration)
[mysqld] port = 3306 socket = /var/run/mysqld/mysqld.sock datadir = /var/lib/mysql max_connections = 150 innodb_buffer_pool_size = 256M [client] port = 3306 socket = /var/run/mysqld/mysqld.sock
Git Configuration (.gitconfig)
[user] name = John Doe email = john@example.com [core] editor = vim autocrlf = input [alias] co = checkout br = branch st = status
Desktop Entry (.desktop files on Linux)
[Desktop Entry] Name = My Application Comment = A useful application Exec = /usr/bin/myapp Icon = myapp Terminal = false Type = Application Categories = Utility;
INI vs Other Formats
| Feature | INI | TOML | YAML | JSON |
|---|---|---|---|---|
| Comments | Yes (; #) | Yes (#) | Yes (#) | No |
| Nested sections | Limited | Yes | Yes | Yes |
| Arrays | No standard | Yes | Yes | Yes |
| Typed values | No | Yes | Yes | Yes |
| Specification | No official | Yes | Yes | Yes |
| Simplicity | Very simple | Simple | Complex | Simple |
Limitations of INI
- No official specification - Different parsers may behave differently
- No nested structures - Only one level of sections supported
- No native arrays - Lists require workarounds like repeated keys or comma-separated values
- All values are strings - Type conversion depends on the application
- No multi-line values - Long values can be hard to manage
When to Use INI
Good For
- Simple configuration files
- Legacy application settings
- Flat key-value data
- Human-edited configs
- Windows applications
Not Ideal For
- Nested data structures
- Lists and arrays
- Complex configurations
- Typed data requirements
- Cross-platform standards