Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Theme variables do not apply to container #17546

Unanswered
nofalx asked this question in Help
Discussion options

in tailwind v3 you could do something like this

module.exports = {
 theme: {
 screens: {
 sm: '640px', // Custom global breakpoint
 md: '768px', // Custom global breakpoint
 lg: '1024px', // Custom global breakpoint
 xl: '1280px', // Custom global breakpoint
 },
 container: {
 center: true,
 screens: {
 sm: '600px', // Custom container max-width at 'sm' breakpoint
 md: '728px', // Custom container max-width at 'md' breakpoint
 lg: '984px', // Custom container max-width at 'lg' breakpoint
 xl: '1240px', // Custom container max-width at 'xl' breakpoint
 },
 },
 },
};

but in v4 we only got the below which only applies to @container and not container

 --container-3xs: 16rem;
 --container-2xs: 18rem;
 --container-xs: 20rem;
 --container-sm: 24rem;
 --container-md: 28rem;
 --container-lg: 32rem;
 --container-xl: 36rem;
 --container-2xl: 42rem;
 --container-3xl: 48rem;
 --container-4xl: 56rem;
 --container-5xl: 64rem;
 --container-6xl: 72rem;
 --container-7xl: 80rem;
You must be logged in to vote

Replies: 1 comment 4 replies

Comment options

Indeed, in v4, container only uses the --breakpoint variables:

utilities.static('container', () => {
let breakpoints = [...theme.namespace('--breakpoint').values()]
breakpoints.sort((a, z) => compareBreakpoints(a, z, 'asc'))
let decls: AstNode[] = [decl('--tw-sort', '--tw-container-component'), decl('width', '100%')]
for (let breakpoint of breakpoints) {
decls.push(atRule('@media', `(width >= ${breakpoint})`, [decl('max-width', breakpoint)]))
}
return decls
})

But you can override container using @utility like:

@utility container {
 margin-inline: auto;
 max-width: none;
 @media (width >= 37.5rem) {
 max-width: 37.5rem;
 }
 @media (width >= 45.5rem) {
 max-width: 45.5rem;
 }
 @media (width >= 61.5rem) {
 max-width: 61.5rem;
 }
 @media (width >= 77.5rem) {
 max-width: 77.5rem;
 }
}

https://play.tailwindcss.com/dY6jvDWhqY?file=css

You must be logged in to vote
4 replies
Comment options

This maybe out of the scope but how can we make something like this work

@utility container {
 @media (width >= var(--breakpoint-xl)) {
 max-width: calc( 0.8 * var(--breakpoint-xl))
 }
}

the issue is with the width >= var(--breakpoint-xl) but it works with width >= 80rem

Comment options

wongjn Apr 4, 2025
Collaborator

You can do:

@utility container {
 @variant xl {
 max-width: calc(0.8 * var(--breakpoint-xl));
 }
}
Comment options

@wongjn With this solution, the generated code contains "lot" of dead code - the default styles (max-width) for the utility are still in the ouput, even though they are never used (because the .utility class is overridden by cascade). This really bothers me, but I don't think there is a solution for this as of now?

Comment options

wongjn Oct 17, 2025
Collaborator

You could consider:

  • Using utility classes instead of container.
  • Forking the project to suit your needs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /