Skip to content

Add reduce-motion variant #2071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 27, 2020
Merged

Add reduce-motion variant #2071

merged 3 commits into from
Jul 27, 2020

Conversation

adamwathan
Copy link
Member

@adamwathan adamwathan commented Jul 24, 2020

Updated 2020-07-27:

This PR adds new motion-reduced and motion-safe variants that allow you to conditionally apply CSS based on the prefers-reduced-motion media feature.

It can be useful in conjunction with transition and animation utilities to disable problematic motion for users who are sensitive to it:

<div class="... transition duration-150 ease-in-out motion-reduced:transition-none ...">

...or to explicitly opt-in to motion to make sure it's only being shown to users who haven't opted out:

<div class="... motion-safe:transition duration-150 ease-in-out ...">

Generally I think motion-safe is the better approach, but I've included both for completeness.

These can be combined with responsive variants and pseudo-class variants as well:

<!-- With responsive variants -->
<div class="sm:motion-reduced:translate-y-0"></div>

<!-- With pseudo-class variants -->
<div class="motion-reduced:hover:translate-y-0"></div>

<!-- With responsive and pseudo-class variants -->
<div class="sm:motion-reduced:hover:translate-y-0"></div>

This is the first example of "stackable" variants in Tailwind and is something we may expose to plugin authors in the future, but for now is just hardcoded for these core variants while we work out the internal details.

@adamwathan
Copy link
Member Author

adamwathan commented Jul 24, 2020

One limitation I should mention, due to how Tailwind is currently designed, these variants can not be stacked with regular variants like hover, so you can't do this:

reduce-motion:hover:transition-none

I bet this won't be a real issue in practice but it is a bit annoying, and this limitation will be really annoying when we start working on dark mode :/ not sure how to solve without a breaking change to how variants work.

Edit: Solved in latest update.

@menthol
Copy link

menthol commented Jul 25, 2020

One limitation I should mention, due to how Tailwind is currently designed, these variants can not be stacked with regular variants like hover, so you can't do this:

reduce-motion:hover:transition-none

I bet this won't be a real issue in practice but it is a bit annoying, and this limitation will be really annoying when we start working on dark mode :/ not sure how to solve without a breaking change to how variants work.

Start to think about a 2.0 version with the breaking changes needed for the future.

@adamwathan adamwathan merged commit 05fe015 into master Jul 27, 2020
@adamwathan adamwathan deleted the reduced-motion branch July 27, 2020 20:13
workashutosh pushed a commit to workashutosh/tailwindcss that referenced this pull request Apr 3, 2025
This pull request includes a small change to the
`src/docs/outline-width.mdx` file. The change modifies the description
to clarify the usage of `outline` utilities.

*
[`src/docs/outline-width.mdx`](diffhunk://#diff-a7a0467902b75954570708cc09d471f346011c3bce60b92e96aaa0c8b21f56daL22-R22):
Changed "and" to "or" in the description to clarify that either
`outline` or `outline-<number>` utilities can be used to set the width
of an element's outline.

---------

Co-authored-by: Philipp Spiess <[email protected]>
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.

2 participants