Tailwind vs Bootstrap

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

内容简介: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.


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

查看所有标签

猜你喜欢:

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

正则表达式必知必会

正则表达式必知必会

Ben Forta / 杨涛、王建桥、杨晓云 / 人民邮电出版社 / 2007 / 29.00元

正则表达式是一种威力无比强大的武器,几乎在所有的程序设计语言里和计算机平台上都可以用它来完成各种复杂的文本处理工作。本书从简单的文本匹配开始,循序渐进地介绍了很多复杂内容,其中包括回溯引用、条件性求值和前后查找,等等。每章都为读者准备了许多简明又实用的示例,有助于全面、系统、快速掌握正则表达式,并运用它们去解决实际问题。 本书适合各种语言和平台的开发人员。一起来看看 《正则表达式必知必会》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

URL 编码/解码
URL 编码/解码

URL 编码/解码

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

正则表达式在线测试