---
title: Targeting only inline code elements with Tailwind Typography
url: "https://aaronfrancis.com/writing/targeting-only-inline-code-elements-with-tailwind-typography"
path: "/writing/targeting-only-inline-code-elements-with-tailwind-typography"
type: technical_article
author: Aaron Francis
published: 2023-11-28
updated: 2026-11-01
description: Only target code blocks that are not inside of pre tags.
keywords: [tailwind typography, prose plugin, inline code, tailwind plugin, prose modifiers, code styling, tailwind config, markdown styling, prose variant, css selector]
site_index: "/llms.txt"
keyword_index: "/llms/keywords.txt"
---

# Targeting only inline code elements with Tailwind Typography

The [Tailwind Typography](https://github.com/tailwindlabs/tailwindcss-typography) plugin is a great way add beautiful styling to HTML rendered from Markdown, pulled from a CMS, or HTML you otherwise don't control.

Simply adding `.prose` to the container takes well-structured HTML and styles it in a reasonable way.

You can adjust the styles of individual elements with some of the [prose modifiers](https://tailwindcss.com/docs/typography-plugin#element-modifiers) supplied by Tailwind. For example, if you wanted to target the H1s in your content, you could add `prose-h1:{utility}` to your container.

```html
<div class='prose prose-h1:text-green-800'>
    <!-- All your content goes here-->
</div>
```

Now all the H1s in the container will be rendered in `text-green-800`.

The only problem I've found so far is that the `prose-code:{utility}` modifiers affect both code in code blocks:

```html
<pre><code>
    Like code in here
</code></pre>
```

and inline code: `like code in here`.

In many cases (including on this site), you'll want to treat the two very differently. I like to add a little background and border for inline code and add a lot more details for code blocks. 

## Tailwind plugin

To only target inline code, we can write a Tailwind plugin to add a [custom variant](https://tailwindcss.com/docs/plugins#adding-variants).

To target inline code with CSS, we could use this selector:

```css
:not(pre) > code {
    /* Inline code only */
}
```

To add an `prose-inline-code:{utility}` variant to Tailwind, we'll need to be a bit more specific to match the other Prose styles.

Add this to your `tailwind.config.js` and you'll now have a `prose-inline-code` variant you can use.

```js
/** @type {import('tailwindcss').Config} */
const plugin = require('tailwindcss/plugin')

module.exports = {
  plugins: [
    require('@tailwindcss/typography'),
    
    plugin(function ({addVariant}) {
      addVariant(
        'prose-inline-code',
        '&.prose :where(:not(pre)>code):not(:where([class~="not-prose"] *))'
      );
    })
  ],
};
```

## Usage

You can use the new variant just like you do all the other prose variants:

```html
<div class="prose prose-inline-code:rounded prose-inline-code:border">
    <!-- All your content goes here -->
</div>
```

I'll open an issue on the Typography plugin to see if the team wants to merge it, and I'll update this post if it gets merged!

---

## Search aaronfrancis.com (2-Hop Static Keyword Index)

Pick the alphabetical shard matching any topic to find exact pages across all articles, newsletters, videos, talks, and podcast transcripts (every shard is < 40 KB):
[A-B](/llms/keywords/a-b.txt) · [C](/llms/keywords/c.txt) · [D-E](/llms/keywords/d-e.txt) · [F-G](/llms/keywords/f-g.txt) · [H-J](/llms/keywords/h-j.txt) · [K-L](/llms/keywords/k-l.txt) · [M-N](/llms/keywords/m-n.txt) · [O-P](/llms/keywords/o-p.txt) · [Q-R](/llms/keywords/q-r.txt) · [S](/llms/keywords/s.txt) · [T-Z](/llms/keywords/t-z.txt) · [Directory](/llms/keywords.txt) · [Site Map](/llms.txt)

Shards for this page's topics: `tailwind typography` ([T-Z](/llms/keywords/t-z.txt)), `prose plugin` ([O-P](/llms/keywords/o-p.txt)), `inline code` ([H-J](/llms/keywords/h-j.txt)), `code styling` ([C](/llms/keywords/c.txt)).

## About Aaron Francis (Current Context)

Aaron Francis is VP of Marketing and Community at [Laravel](https://laravel.com), founder of [Try Hard Studios](https://tryhardstudios.com), creator of [Solo](https://soloterm.com), co-host of [Mostly Technical](/podcast), and author of [Mastering Postgres](/courses), [High Performance SQLite](/courses), [MySQL for Developers](/courses), and [Screencasting.com](/courses). Full bio: [/about](/about) · Current focus: [/now](/now).
