• Stars
    star
    1,131
  • Rank 41,145 (Top 0.9 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 2 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A plugin for Tailwind CSS v3.2+ that provides utilities for container queries.

@tailwindcss/container-queries

A plugin for Tailwind CSS v3.2+ that provides utilities for container queries.

Installation

Install the plugin from npm:

npm install @tailwindcss/container-queries

Then add the plugin to your tailwind.config.js file:

// tailwind.config.js
module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@tailwindcss/container-queries'),
    // ...
  ],
}

Usage

Start by marking an element as a container using the @container class, and then applying styles based on the size of that container using the container variants like @md:, @lg:, and @xl::

<div class="@container">
  <div class="@lg:underline">
    <!-- This text will be underlined when the container is larger than `32rem` -->
  </div>
</div>

By default we provide container sizes from @xs (20rem) to @7xl (80rem).

Named containers

You can optionally name containers using a @container/{name} class, and then include that name in the container variants using classes like @lg/{name}:underline:

<div class="@container/main">
  <!-- ... -->
  <div class="@lg/main:underline">
    <!-- This text will be underlined when the "main" container is larger than `32rem` -->
  </div>
</div>

Arbitrary container sizes

In addition to using one of the container sizes provided by default, you can also create one-off sizes using any arbitrary value:

<div class="@container">
  <div class="@[17.5rem]:underline"></div>
    <!-- This text will be underlined when the container is larger than `17.5rem` -->
  </div>
</div>

Removing a container

To stop an element from acting as a container, use the @container-normal class.

Configuration

By default we ship with the following configured values:

Name CSS
@xs @container (min-width: 20rem /* 320px */)
@sm @container (min-width: 24rem /* 384px */)
@md @container (min-width: 28rem /* 448px */)
@lg @container (min-width: 32rem /* 512px */)
@xl @container (min-width: 36rem /* 576px */)
@2xl @container (min-width: 42rem /* 672px */)
@3xl @container (min-width: 48rem /* 768px */)
@4xl @container (min-width: 56rem /* 896px */)
@5xl @container (min-width: 64rem /* 1024px */)
@6xl @container (min-width: 72rem /* 1152px */)
@7xl @container (min-width: 80rem /* 1280px */)

You can configure which values are available for this plugin under the containers key in your tailwind.config.js file:

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      containers: {
        '2xs': '16rem',
      },
    },
  },
}

More Repositories

1

tailwindcss

A utility-first CSS framework for rapid UI development.
TypeScript
81,562
star
2

headlessui

Completely unstyled, fully accessible UI components, designed to integrate beautifully with Tailwind CSS.
TypeScript
25,564
star
3

heroicons

A set of free MIT-licensed high-quality SVG icons for UI development.
JavaScript
21,279
star
4

prettier-plugin-tailwindcss

A Prettier plugin for Tailwind CSS that automatically sorts classes based on our recommended class order.
TypeScript
5,382
star
5

tailwindcss-typography

Beautiful typographic defaults for HTML you don't control.
JavaScript
4,319
star
6

tailwindcss-forms

A plugin that provides a basic reset for form styles that makes form elements easy to override with utilities.
HTML
4,137
star
7

tailwindcss.com

The Tailwind CSS documentation website.
MDX
3,233
star
8

tailwindcss-intellisense

Intelligent Tailwind CSS tooling for Visual Studio Code
TypeScript
2,783
star
9

tailwindcss-jit

JavaScript
2,188
star
10

tailwindcss-custom-forms

A better base for styling form elements with Tailwind CSS.
JavaScript
1,553
star
11

tailwindcss-line-clamp

A plugin that provides utilities for visually truncating text after a fixed number of lines.
JavaScript
1,176
star
12

tailwindcss-aspect-ratio

JavaScript
956
star
13

designing-with-tailwindcss

Source code for the "Designing with Tailwind CSS" course.
CSS
712
star
14

heroicons.com

JavaScript
697
star
15

tailwindcss-setup-examples

675
star
16

tailwindui-vue

Deprecated, please use the Headless UI repo instead.
JavaScript
647
star
17

play.tailwindcss.com

JavaScript
638
star
18

tailwindcss-playground

HTML
516
star
19

tailwindui-react

Deprecated, please use the Headless UI repo instead.
TypeScript
433
star
20

tailwindcss-from-zero-to-production

Source code for the "Tailwind CSS Up and Running" screencast series.
JavaScript
379
star
21

blog.tailwindcss.com

JavaScript
342
star
22

tailwindui-issues

Bug fixes and feature request tracking for Tailwind UI.
233
star
23

webpack-starter

A quick and simple example of using Tailwind CSS with Webpack.
JavaScript
212
star
24

tailwindcss-plugin-examples

Examples to help you get started building your own Tailwind CSS plugins.
JavaScript
209
star
25

discuss

A place to ask questions, get help, or share what you've built with Tailwind CSS.
171
star
26

tailwind-play-api

PHP
44
star
27

minimal-tailwind-postcss-plugin

A simple PostCSS plugin designed to cover all of the tricky integration points a build-tool needs to support for Tailwind CSS.
JavaScript
11
star
28

reproduction-headlessui-vue

JavaScript
9
star
29

reproduction-headlessui-react

JavaScript
1
star