Do Tailwind CSS arbitrary values affect performance?

I’m using Tailwind CSS in a project and I’m curious about the performance implications of using arbitrary values.

The project performance is critical, rather than achieving a pixel-perfect UI. So, consider these alternatives:

# Opt 1
<div class="px-11">
  <!-- content -->
</div>

# Opt 2
<div class="px-[2.8125rem]">
  <!-- content -->
</div>

I assume that both options are equal in terms of performance, but I haven’t found information to confirm this. Therefore, I’m curious to understand if my assumption is incorrect.

My questions are:

  1. Which of these alternatives is better for performance and why?

  2. Consider to use arbitrary values (like px-[2.8125rem]) everywhere. Does it increase the size of the generated CSS file significantly compared to standard utility classes (like px-11)?

I appreciate any insights or advice.

Thank you!

2

@DA2. answered it well in the comments. But since no one has posted an answer, I’ll summarize it here.

Answer

The performance of these two approaches is identical.

Tailwind generates all utility classes as stylesheets at build time. The first approach, px-11, generates the following utility class:

.px-11 {
  padding-left: 2.75rem;
  padding-right: 2.75rem;
}

The second approach, px-[2.8125rem], generates the following utility class:

.px-[2.8125rem] {
    padding-left: 2.8125rem;
    padding-right: 2.8125rem;
}

Both approaches generate an equal number of classes with the same attributes.

Reusing the same arbitrary value will not significantly increase the size of the package.

No matter how many times you use px-[2.8125rem], it will only generate one style class. This is not a feature of Tailwind, but a reuse mechanism inherent in style sheets.

But using different arbitrary values produces different classes

For example, if you use px-[2.1rem], px-[2.2rem], px-[2.3rem], Tailwind will generate a style class for each of them. However, the size of a class is not many bytes, so it still does not significantly increase the package size.

Suggestions

When you really need to use an arbitrary value, just do it.

Arbitrary values do not have any impact on performance, nor do they significantly affect package size. It is worth it if it results in a sizable visual effect.

If you need to reuse an arbitrary value everywhere, configure it as a theme value.

Theme values are more elegant than arbitrary values. It can provide higher readability and ease of maintenance.

//tailwind.config.js
export default {
  theme: {
    extend: {
      padding: {
        '11.25': '2.8125rem',
      },
    }
  },
  plugins: [],
}

You can then use px-11.25 to achieve the same effect.

Do not abuse arbitrary values.

The default utility classes should be prioritized at all times. Use arbitrary values only if you really have no choice.

One of the major benefits of Tailwind is that it reduces the range of values that can be chosen, making it easier to maintain consistency and maintainability by standardizing the values in your project. Having different arbitrary values everywhere can have a big impact on code readability.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật