Skip to content

Conversation

@adamwathan
Copy link
Member

@adamwathan adamwathan commented Nov 10, 2017

This could've been two separate PRs but it's really just the consolidation of #99 and #100 but moved into the config file instead of being made available as at-rules.

This PR adds support for a new options key in the config file, with two options so far:

{
    // ...
    options: {
        prefix: 'tw-', // Defaults to ''
        important: true, // Default to false
    }
}

Prefix

The prefix option causes all of Tailwind's utilities to be generated with the given prefix.

This is (shockingly) more complex than it sounds, so there's a few rules worth understanding.

  1. The prefix is added to the beginning of the utility name, not the full class name.

    This means that if you set a prefix of tw-, you'll get utilities that look like this:

    .tw-text-blue { ... }
    .hover:tw-text-blue { ... }
    .sm:tw-text-blue { ... }
    .md:tw-text-blue { ... }
    .lg:tw-text-blue { ... }
    .xl:tw-text-blue { ... }

    ...not like this:

    .tw-text-blue { ... }
    .tw-hover:text-blue { ... }
    .tw-sm:text-blue { ... }
    .tw-md:text-blue { ... }
    .tw-lg:text-blue { ... }
    .tw-xl:text-blue { ... }

    This may seem counter-intuitive at first, keep reading.

  2. Your own classes that Tailwind touches with features like @responsive do not adopt this prefix.

    For example, this custom class wrapped in @responsive:

    @responsive {
        .foo { color: blue }
    }

    ...will generate this code:

    .foo { color: blue }
    @media (min-width: 576px) {
        .sm:foo { color: blue }
    }
    @media (min-width: 768px) {
        .md:foo { color: blue }
    }
    @media (min-width: 992px) {
        .lg:foo { color: blue }
    }
    @media (min-width: 1200px) {
        .xl:foo { color: blue }
    }

    ...not this code:

    .tw-foo { color: blue }
    @media (min-width: 576px) {
        .sm:tw-foo { color: blue }
    }
    @media (min-width: 768px) {
        .md:tw-foo { color: blue }
    }
    @media (min-width: 992px) {
        .lg:tw-foo { color: blue }
    }
    @media (min-width: 1200px) {
        .xl:tw-foo { color: blue }
    }

    This is the reason for putting the prefix at the beginning of the utility name, not the class name.

    If we put the prefix at the beginning of the full class, your own custom utilities would have no prefix, and the responsive prefixes would look different:

    <div class="tw-text-blue custom-foo tw-md:text-red md:custom-bar">
        <!-- ... -->
    </div>

    This inconsistency was ugly enough that it felt like putting the prefix before just the utility portion was the right move, because the only other option was prefixing your own custom utilities too, and that didn't feel right either.

Important

Important is simpler; it just makes all of Tailwind's utilities !important.

It doesn't make any of your own custom utilities that use Tailwind features important though; if you want that behavior, simply mark them as !important yourself:

@responsive {
    .foo {
        color: blue !important;
    }
}

One important special case here is the .container class. Using the important option does not make the .container class important.

This is because that class isn't really a utility; it's more of a component. It already gets special treatment in the codebase in that it doesn't get responsive variations generated (.md:container, .lg:container, etc.).

Since it's more of a component, it makes sense that it's styles should be overridable if needed, even though I don't know why you'd ever do that.

The End.

If you have opinions about all the prefix positioning crap I am open to hearing them, we argued about it for a while and this seemed like the best solution.

adamwathan and others added 9 commits November 4, 2017 23:13
Wrapping a set of rules with this at-rule will make every single
property in those classes !important.

I don't intend to use this in core, but it's really useful for folks
who want to use Tailwind on top of an existing base of CSS where the
non-important versions of our utilities might not be enough to defeat
the specificity of their existing styles.

Using this at-rule, someone could import Tailwind into their codebase
like this:

```
@Important {
  @tailwind utilities;
}
```

...and then all of their Tailwind utilities would be !important, making
it easy to use them to override their existing CSS.
Doesn't apply to `.container` since it's an oddball non-utility.
Copy link
Member

@reinink reinink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bravo!

@adamwathan adamwathan changed the base branch from master to develop November 11, 2017 12:48
@adamwathan adamwathan closed this Nov 11, 2017
@adamwathan adamwathan deleted the options-important-prefix branch November 23, 2017 13:49
DCzajkowski pushed a commit to DCzajkowski/tailwindcss that referenced this pull request Jul 23, 2019
thecrypticace pushed a commit that referenced this pull request Nov 21, 2025
Here is everything you need to know about this update. Please take a
good look at what changed and the test results before merging this pull
request.

### What changed?




#### ✳️ @​emnapi/runtime (1.6.0 → 1.7.1) ·
[Repo](https://github.com/toyobayashi/emnapi)



<details>
<summary>Release Notes</summary>
<h4><a
href="https://github.com/toyobayashi/emnapi/releases/tag/v1.7.1">1.7.1</a></h4>

<blockquote><h2 dir="auto">What's Changed</h2>
<ul dir="auto">
<li>move Node-API version detection by <a
href="https://bounce.depfu.com/github.com/toyobayashi">@toyobayashi</a>
in <a
href="https://bounce.depfu.com/github.com/toyobayashi/emnapi/pull/182">#182</a>
</li>
<li>feat: support SharedArrayBuffer in napi_create_dataview by <a
href="https://bounce.depfu.com/github.com/toyobayashi">@toyobayashi</a>
in <a
href="https://bounce.depfu.com/github.com/toyobayashi/emnapi/pull/183">#183</a>
</li>
</ul>
<p dir="auto"><strong>Full Changelog</strong>: <a
href="https://bounce.depfu.com/github.com/toyobayashi/emnapi/compare/v1.7.0...v1.7.1"><tt>v1.7.0...v1.7.1</tt></a></p></blockquote>
<h4><a
href="https://github.com/toyobayashi/emnapi/releases/tag/v1.7.0">1.7.0</a></h4>

<blockquote><h2 dir="auto">What's Changed</h2>
<ul dir="auto">
<li>feat: add napi_create_object_with_properties method by <a
href="https://bounce.depfu.com/github.com/toyobayashi">@toyobayashi</a>
in <a
href="https://bounce.depfu.com/github.com/toyobayashi/emnapi/pull/181">#181</a>
</li>
</ul>
<p dir="auto"><strong>Full Changelog</strong>: <a
href="https://bounce.depfu.com/github.com/toyobayashi/emnapi/compare/v1.6.0...v1.7.0"><tt>v1.6.0...v1.7.0</tt></a></p></blockquote>
<p><em>Does any of this look wrong? <a
href="https://depfu.com/packages/npm/@emnapi%2Fruntime/feedback">Please
let us know.</a></em></p>
</details>

<details>
<summary>Commits</summary>
<p><a
href="https://github.com/toyobayashi/emnapi/compare/86d68f88ec3cc3949a555c93a633fa8997534413...f40577ad6013236e46bef57d829ece20773997bb">See
the full diff on Github</a>. The new version differs by 6 commits:</p>
<ul>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/f40577ad6013236e46bef57d829ece20773997bb"><code>1.7.1</code></a></li>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/c95f961fbcd33be46cdcc7ae77fb299c773a675a"><code>feat:
support SharedArrayBuffer in napi_create_dataview (#183)</code></a></li>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/92964e3738bd380c9c66bfc2cf8f332d108035f1"><code>move
Node-API version detection (#182)</code></a></li>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/11f4936f39121d0d79bc4901cf14dca02ef4abea"><code>1.7.0</code></a></li>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/44bd3c798d97952d5dccc2fc9ab14494b9ef7964"><code>[Backport]
feat: add napi_create_object_with_properties method
(#181)</code></a></li>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/62ab842b64f14da4a9838861758cbcb5c8465900"><code>ci:
fix version retrieval</code></a></li>
</ul>
</details>












---
![Depfu
Status](https://depfu.com/badges/edd6acd35d74c8d41cbb540c30442adf/stats.svg)

[Depfu](https://depfu.com) will automatically keep this PR
conflict-free, as long as you don't add any commits to this branch
yourself. You can also trigger a rebase manually by commenting with
`@depfu rebase`.

<details><summary>All Depfu comment commands</summary>
<blockquote><dl>
<dt>@​depfu rebase</dt><dd>Rebases against your default branch and
redoes this update</dd>
<dt>@​depfu recreate</dt><dd>Recreates this PR, overwriting any edits
that you've made to it</dd>
<dt>@​depfu merge</dt><dd>Merges this PR once your tests are passing and
conflicts are resolved</dd>
<dt>@​depfu cancel merge</dt><dd>Cancels automatic merging of this
PR</dd>
<dt>@​depfu close</dt><dd>Closes this PR and deletes the branch</dd>
<dt>@​depfu reopen</dt><dd>Restores the branch and reopens this PR (if
it's closed)</dd>
<dt>@​depfu pause</dt><dd>Ignores all future updates for this dependency
and closes this PR</dd>
<dt>@​depfu pause [minor|major]</dt><dd>Ignores all future minor/major
updates for this dependency and closes this PR</dd>
<dt>@​depfu resume</dt><dd>Future versions of this dependency will
create PRs again (leaves this PR as is)</dd>
</dl></blockquote>
</details>

Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>
thecrypticace pushed a commit that referenced this pull request Nov 21, 2025
Here is everything you need to know about this upgrade. Please take a
good look at what changed and the test results before merging this pull
request.

### What changed?




#### ✳️ emnapi (1.6.0 → 1.7.1) ·
[Repo](https://github.com/toyobayashi/emnapi)



<details>
<summary>Release Notes</summary>
<h4><a
href="https://github.com/toyobayashi/emnapi/releases/tag/v1.7.1">1.7.1</a></h4>

<blockquote><h2 dir="auto">What's Changed</h2>
<ul dir="auto">
<li>move Node-API version detection by <a
href="https://bounce.depfu.com/github.com/toyobayashi">@toyobayashi</a>
in <a
href="https://bounce.depfu.com/github.com/toyobayashi/emnapi/pull/182">#182</a>
</li>
<li>feat: support SharedArrayBuffer in napi_create_dataview by <a
href="https://bounce.depfu.com/github.com/toyobayashi">@toyobayashi</a>
in <a
href="https://bounce.depfu.com/github.com/toyobayashi/emnapi/pull/183">#183</a>
</li>
</ul>
<p dir="auto"><strong>Full Changelog</strong>: <a
href="https://bounce.depfu.com/github.com/toyobayashi/emnapi/compare/v1.7.0...v1.7.1"><tt>v1.7.0...v1.7.1</tt></a></p></blockquote>
<h4><a
href="https://github.com/toyobayashi/emnapi/releases/tag/v1.7.0">1.7.0</a></h4>

<blockquote><h2 dir="auto">What's Changed</h2>
<ul dir="auto">
<li>feat: add napi_create_object_with_properties method by <a
href="https://bounce.depfu.com/github.com/toyobayashi">@toyobayashi</a>
in <a
href="https://bounce.depfu.com/github.com/toyobayashi/emnapi/pull/181">#181</a>
</li>
</ul>
<p dir="auto"><strong>Full Changelog</strong>: <a
href="https://bounce.depfu.com/github.com/toyobayashi/emnapi/compare/v1.6.0...v1.7.0"><tt>v1.6.0...v1.7.0</tt></a></p></blockquote>
<p><em>Does any of this look wrong? <a
href="https://depfu.com/packages/npm/emnapi/feedback">Please let us
know.</a></em></p>
</details>

<details>
<summary>Commits</summary>
<p><a
href="https://github.com/toyobayashi/emnapi/compare/86d68f88ec3cc3949a555c93a633fa8997534413...f40577ad6013236e46bef57d829ece20773997bb">See
the full diff on Github</a>. The new version differs by 6 commits:</p>
<ul>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/f40577ad6013236e46bef57d829ece20773997bb"><code>1.7.1</code></a></li>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/c95f961fbcd33be46cdcc7ae77fb299c773a675a"><code>feat:
support SharedArrayBuffer in napi_create_dataview (#183)</code></a></li>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/92964e3738bd380c9c66bfc2cf8f332d108035f1"><code>move
Node-API version detection (#182)</code></a></li>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/11f4936f39121d0d79bc4901cf14dca02ef4abea"><code>1.7.0</code></a></li>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/44bd3c798d97952d5dccc2fc9ab14494b9ef7964"><code>[Backport]
feat: add napi_create_object_with_properties method
(#181)</code></a></li>
<li><a
href="https://github.com/toyobayashi/emnapi/commit/62ab842b64f14da4a9838861758cbcb5c8465900"><code>ci:
fix version retrieval</code></a></li>
</ul>
</details>












---
![Depfu
Status](https://depfu.com/badges/edd6acd35d74c8d41cbb540c30442adf/stats.svg)

[Depfu](https://depfu.com) will automatically keep this PR
conflict-free, as long as you don't add any commits to this branch
yourself. You can also trigger a rebase manually by commenting with
`@depfu rebase`.

<details><summary>All Depfu comment commands</summary>
<blockquote><dl>
<dt>@​depfu rebase</dt><dd>Rebases against your default branch and
redoes this update</dd>
<dt>@​depfu recreate</dt><dd>Recreates this PR, overwriting any edits
that you've made to it</dd>
<dt>@​depfu merge</dt><dd>Merges this PR once your tests are passing and
conflicts are resolved</dd>
<dt>@​depfu cancel merge</dt><dd>Cancels automatic merging of this
PR</dd>
<dt>@​depfu close</dt><dd>Closes this PR and deletes the branch</dd>
<dt>@​depfu reopen</dt><dd>Restores the branch and reopens this PR (if
it's closed)</dd>
<dt>@​depfu pause</dt><dd>Ignores all future updates for this dependency
and closes this PR</dd>
<dt>@​depfu pause [minor|major]</dt><dd>Ignores all future minor/major
updates for this dependency and closes this PR</dd>
<dt>@​depfu resume</dt><dd>Future versions of this dependency will
create PRs again (leaves this PR as is)</dd>
</dl></blockquote>
</details>

Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants