Skip to content

MD048 - Code fence style should be consistent

Aliases: code-fence-style

What this rule does

Ensures all code blocks use the same fence markers - either ``` or ~~~ consistently.

Why this matters

  • Consistency: Mixed fence styles look unprofessional
  • Readability: Consistent markers make code blocks easier to spot
  • Tool compatibility: Some tools may expect one style over another

Examples

✅ Correct (using ``` throughout)

```javascript
function hello() {
  console.log("Hello, world!");
}
```

```python
def hello():
    print("Hello, world!")
```

✅ Correct (using ~~~ throughout)

~~~javascript
function hello() {
  console.log("Hello, world!");
}
~~~

~~~python
def hello():
    print("Hello, world!")
~~~

❌ Incorrect (mixed styles)

```javascript
function hello() {
  console.log("Hello, world!");
}
```

~~~python
def hello():
    print("Hello, world!")
~~~

🔧 Fixed

```javascript
function hello() {
  console.log("Hello, world!");
}
```

```python
def hello():
    print("Hello, world!")
```

Configuration

[MD048]
style = "consistent"  # Options: "consistent", "backtick", "tilde"

Style options

  • "consistent" (default): Use the most prevalent style in your document (in case of a tie, backtick ``` is preferred as it's more widely supported)
  • "backtick": Always use ``` markers
  • "tilde": Always use ~~~ markers

Automatic fixes

This rule automatically converts all code fence markers to match your configured style or the most prevalent style in the document.

Learn more

  • MD031 - Code blocks need blank lines around them
  • MD040 - Code blocks should have a language specified
  • MD046 - Code block style should be consistent