group-focus classes in a Tailwind page do nothing when the field is focused
group-focus:opacity-100 has no effect when the field inside the group is focusedShort answer
group-focus styles the target only while the element that carries the group class has focus itself. It does nothing if the parent lacks group, if focus sits on a child such as an input, if Tailwind never generated the class, or if nested groups are mixed up. Use group-focus-within when a child takes the focus.
Fix it fast
1Find out which cause you have
List every use of group-focus in your templates, then check each one for a parent with the group class and for the element that really takes the focus. After that, look in the browser's inspector at whether a rule for the class shows up for the target.
grep -rn "group-focus" resources/views resources/js2Match what you see, then jump to its fix
- 1
The group-focus class sits on a child, but no parent has group, or the group class is on a sibling instead of an ancestorNo ancestor carries the group classFix - 2
The group is a div or a form, and the focus goes to an input or a button inside itFocus sits on a child, and the group itself never takes focusFix - 3
The class is in the HTML, but searching the built CSS for it finds nothingTailwind never generated the classFix - 4
One group sits inside another, and the style reacts to the wrong element or to noneNested groups answer to the wrong parentFix
- 1
What does the error look like?
group-focus:opacity-100 has no effect when the field inside the group is focusedThe class is in the HTML, but the built CSS has no rule for it
Cause 1 of 4
No ancestor carries the group class
1Check
The group-* variants style an element from the state of a parent that you mark with the group class. Without that class, nothing is there to be focused.
grep -rnE "class=\"([^\"]* )?group( [^\"]*)?\"" resources/views | head2Fix
Add group to the ancestor whose state should drive the style, and keep the styled element inside it.
<div class="group ...">
<label class="opacity-50 group-focus:opacity-100 ...">Name</label>
</div>3Verify
Focus the group element and watch the label change. The inspector lists the group-focus rule for the label.
npm run build
grep -rl "group-focus" public/Confirmed by tailwindcss.com
Cause 2 of 4
Focus sits on a child, and the group itself never takes focus
1Check
group-focus reacts when the group element itself has focus. A div is not focusable unless it has tabindex, so focusing the input inside it never triggers group-focus. The focus-within variant exists for this: it applies when an element or one of its descendants has focus, and the group variants work with every pseudo-class variant.
grep -rn "group-focus:" resources/views | head2Fix
Use group-focus-within when a child takes the focus. Make the group itself focusable with tabindex only if the group should take focus on its own.
<div class="group ...">
<label class="opacity-50 group-focus-within:opacity-100 ...">Name</label>
<input type="text" class="..." />
</div>3Verify
Click into the input. The label changes while the input has focus.
npm run build
grep -rl "group-focus-within" public/Confirmed by tailwindcss.com
Cause 3 of 4
Tailwind never generated the class
1Check
Tailwind reads your source files as plain text and cannot interpret string concatenation, so a class built from pieces is never seen. It also skips files listed in .gitignore and the node_modules directory. Build, then look for the rule.
npm run build
grep -rl "group-focus" public/2Fix
Write class names out in full, so a map holds the complete strings. Register extra source folders with @source in your CSS entry file.
{{-- fails: Tailwind sees only pieces --}}
<div class="group-focus:text-{{ $color }}-600"></div>
{{-- works: complete class names exist in the source --}}
@php
$focusColors = ['blue' => 'group-focus:text-blue-600', 'red' => 'group-focus:text-red-600'];
@endphp
<div class="{{ $focusColors[$color] }}"></div>
/* resources/css/app.css: a folder Tailwind skips by default */
@import "tailwindcss";
@source "../../vendor/acme/ui-kit/resources/views";3Verify
After a new build, the built CSS contains the group-focus rule, and the style applies.
npm run build
grep -rl "group-focus" public/Confirmed by tailwindcss.com
Cause 4 of 4
Nested groups answer to the wrong parent
1Check
When groups are nested, an unnamed group variant does not say which parent you mean. The documentation names the groups for that case: give the parent a name with group/name and use group-focus/name on the target.
grep -rn "class=\"[^\"]*group" resources/views | head2Fix
Name the parent group, and put the same name on the variant.
<div class="group/card ...">
<div class="group/field ...">
<input type="text" class="..." />
<span class="opacity-0 group-focus-within/field:opacity-100 ...">Saved</span>
</div>
<p class="text-gray-500 group-focus-within/card:text-gray-900 ...">Hint</p>
</div>3Verify
Focus the input. Each element reacts to the group named in its own class.
npm run build
grep -rl "group-focus-within" public/Confirmed by tailwindcss.com
How do I stop it coming back?
- Put group on the element whose state you mean, and use group-focus-within whenever the focus will land on a child.
- Never build Tailwind classes from pieces such as text-{{ $color }}-600. Keep every complete class in a map.
- Name groups when you nest them, so each variant says which parent it follows.
- Search the built CSS for a class that does not apply, before you debug the template.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Web apps
focus:outline-none does not remove the focus border in Tailwind
A ring still shows around the field when focused
focus:outline-none only controls the CSS outline.
3 causes, each with a fixWeb apps
Tailwind md:, lg: and sm: classes do not override as expected
md:flex still applies on large screens
Tailwind is mobile-first: a plain class applies at every width, and sm:, md: or lg: applies at that width and above.
3 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
Laravel cannot find a Sass or JS entry in the Vite manifest
Unable to locate file in Vite manifest: resources/sass/app.scss
The @vite directive asks the built manifest for a file, and that file is listed only if it is an entry in the laravel() input option and the assets were built after adding it.
3 causes, each with a fixWeb apps
Hydration failed after adding next-themes dark mode
Console reports a server and client mismatch on the html element
next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.
3 causes, each with a fixWeb apps
Next.js fails with Cannot find module 'tailwindcss'
Error: Cannot find module 'tailwindcss'
Next.js loads Tailwind through PostCSS, so the error means the package named in postcss.config is not installed where the build runs.
3 causes, each with a fix