Tailwind vs Bootstrap

栏目: IT技术 · 发布时间: 5年前

内容简介:Tailwind CSS has recently benefited from an upwards trend of popularity and there is an increasing amount of front-end developers who choose to stick with the new CSS Framework as a new alternative. In this article I want to explore the differences between

Tailwind CSS has recently benefited from an upwards trend of popularity and there is an increasing amount of front-end developers who choose to stick with the new CSS Framework as a new alternative. In this article I want to explore the differences between Tailwind and Bootstrap and give you as much insight as possible on this topic.

Tailwind vs Bootstrap

Bootstrap

The initial release of Bootstrap happened on August 19, 2011, nearly 9 years ago. Fun fact is that it was created during a hackathon by the Twitter development team and later it was developed and maintained by Mark Otto, Jacob Thornton and a small group of core developers.

Shortly it became one of the most popular CSS Frameworks out there and it currently is the sixth-most-starred project on GitHub and it is currently being used by millions of developers worldwide.

Tailwind CSS

According to the project’s Github contributor list the project was originally developed by Adam Wathan and the first release dates back to October 22, 2019. It is described as a utility-first CSS framework and they claim that development is faster with this new method.

Having introduced some basic facts about the two frameworks I would like to lay out the comparison benchmarks that we will delve into in this article. We will talk about the development process, the number of components, performance and community.

Developing with Bootstrap

Bootstrap is based on the Object Oriented CSS methodology which has become one of the most popular ways of managing stylesheets and classes. Before OOCSS we used to create separate classes and styles for any component that looked different. For example, if you had 10 buttons in your application you would have 10 different classes for those buttons.

With Object Oriented CSS you would instead have a lot more classes for the sizing and style of the button. This would ensure a more modular and DRY stylesheet and you wouldn’t have to create a new class for a button which you would need to be smaller only.

Apart from this Bootstrap is also using the most popular CSS preprocessors, namely Sass . If you don’t know what Sass is, basically it enables you to use functions and variables in stylesheets. If your primary color is red, in a regular CSS file that same color would be repeated across all declarations. With Sass, such properties can become variables so if you want to change the color red, you can simply just change it in one place and it will propagate in the whole application.

At Themesberg we create our themes using Sass and we try to make our stylesheets to use variables and mixins (functions) as much as possible so that the developers purchasing our products can have an easier time adapting colors & fonts to their liking.

Developing with Tailwind CSS

Tailwind CSS is a utility-first CSS framework. What this means is that instead of writing a lot of CSS you will be writing a lot of classes for the HTML elements. In Tailwind CSS you have classes for almost all kinds of margins, padding, backgrounds, font sizes, font families, text colors, shadows and so on.

Let’s take a look how the markup of a primary button differs from Bootstrap and Tailwind CSS:

Bootstrap Primary Button

<button type="button">Primary</button>

Tailwind CSS Button

<button>

  Button

</button>

As you can see the markup is quite a bit more simple in the case of Bootstrap, so you might be asking why wouldn’t you use Bootstrap as it is more simple? Let me give you a scenario: what if you wanted to make the button just slightly smaller in a particular page? Would you want to create a whole new sizing class just for that unique case? In this scenario, using Tailwinds many padding classes would be easier and you wouldn’t even have to touch the css file.

Another great feature that I observe is the fact that you can also set hover, active and focus states using classes. This is a feature that Bootstrap never had and personally I felt like it would’ve been useful many times.

May I add that Tailwind also offers the possibility to create classes such as .btn-blue for components that are repeated many more times in your html files using component classes. Here’s an example:

<!-- Extracting component classes: -->

<button>

  Button

</button>

 

<style>

  .btn {

    @apply font-bold py-2 px-4 rounded;

  }

  .btn-blue {

    @apply bg-blue-500 text-white;

  }

  .btn-blue:hover {

    @apply bg-blue-700;

  }

</style>

Instead of Sass, Tailwind CSS uses post-css and a config file to set up the variables and configuration of your stylesheets. You can add, remove or update colors, spacings, fonts, shadows anything that you can think of.

Base set of components

In this case I must say that Bootstrap has a clear advantage because of its wide set of components including cards, modals, accordions, nav tabs and so on. Tailwind CSS has only a handful of components according to their documentation, the full list being:

  • Alerts
  • Buttons
  • Cards
  • Forms
  • Flexbox grids
  • Navigation

This compared to Bootstrap’s 21 set of components . However, Tailwind CSS does have a lot more utility classes than Bootstrap does and using them you can create any type of component you want.

Performance

Bootstrap has 4 files that are required to include into your project to get the full benefit of the CSS Framework. Together they amount up to 308.25kb including jQuery, Popper.js, Bootstrap JS and the main Bootstrap CSS file.

In comparison, Tailwind CSS only requires the base stylesheet file which amounts up to 27kb. It is true that Bootstrap has a much larger set of components and functionality, however if you don’t need certain components such as modals or accordions perhaps Tailwind is a better choice for more lightweight projects.

Community

Bootstrap has been around for more than 9 years and being the most popular CSS Framework it has a large community of developers, forums, tools and so on. You can find countless of Stackoverflow threads answering to just about any question you might have about certain situations.

In the case of Tailwind CSS there is still much room to grow in terms of its community, however it is growing day by day and the number of tools and websites related to it are also increasing.

Conclusion

In conclusion I believe that deciding whether to choose Tailwind CSS or Bootstrap should be more based on your personal preference regarding writing styles and classes. There is no clear performance or quality advantage that any of the frameworks might have, except the fact that Bootstrap does still come with a much larger set of components.

At the end of the day I recommend you try out Tailwind CSS and see if the utility-first way of building user interfaces for the web is a preferred way for you to work.

What are your preferences and which CSS Framework do you regularly use for your projects? Leave your thoughts in the comment section.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

C标准库

C标准库

P. J. Plauger / 卢红星、徐明亮、霍建同 / 人民邮电出版社 / 2009-7 / 79.00元

本书是由世界级C语言专家编写的C标准库经典著作。英文版已经重印十多次,影响了几代程序员。 本书结合C标准的相关部分,精辟地讲述了每一个库函数的使用方法和实现细节,而这正是一个真正的C程序员所必须掌握的。更重要的是,书中给出了实现和测试这些函数的完整源代码,可以让你更深入地学习C语言。不仅如此,本书还讨论了一些即使是最有经验的C程序员通常也不熟悉的知识,比如国际化和独立于区域设置的程序的编写、......一起来看看 《C标准库》 这本书的介绍吧!

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具