What is Tailwind CSS preflight?

Tailwind CSS is a popular utility-first CSS framework that provides a set of pre-defined classes for rapidly styling web pages. One of the features that Tailwind CSS provides is the preflight feature.

The preflight feature is a step in the process of generating the final CSS file that is used in your web pages. It essentially checks that the CSS file generated by Tailwind CSS is ready for production and that it will not cause any issues. It is based on a set of predefined checks that assess the CSS file and its usage of the classes.

The preflight feature will check for any CSS that is not being used, and any classes that are used but not defined in your Tailwind CSS config file, and will remove them. This can help to reduce the size of your CSS file, which in turn can improve the performance of your web pages.

The preflight feature can also check for any duplicates in your CSS file, it can help you to keep your CSS lean, and only including what is needed.

Preflight can be enabled by adding it to the module.exports of your tailwind config file:

module.exports = {
    future: {
        removeDeprecatedGapUtilities: true,
        purgeLayersByDefault: true,
        defaultLineHeights: true,
        standardFontWeights: true
    },
    ...
}

It's worth noting that the preflight feature may not be necessary for all projects, and it can be disable depending on your project needs. Additionally, it is a best practice to test your website after enabling the preflight feature, since it might break some classes or styles you are currently using.

In summary, Tailwind CSS preflight feature is a step in the process of generating the final CSS file that is used in your web pages. It checks that the CSS file generated by Tailwind CSS is ready for production and will not cause any issues. It removes any CSS that is not being used, any classes that are used but not defined in your Tailwind CSS config file, checks for any duplicates and keeps your CSS lean. Enabling it can help to improve the performance of your web pages, but it should be used with caution and testing, since it might break some existing styles.

Additional resources
  • Frontend web development courses

    Beginner-friendly courses focusing on HTML, CSS, and JavaScript.

    View Courses
  • Frontend web development projects

    Beginner-friendly projects focusing on HTML, CSS, and JavaScript.

    View Projects
  • Free website templates

    Collection of free, high-quality website templates for your next project.

    View Templates