2 Ways to Add Default Font Color and Size in TailwindCSS

TailwindCSS resets the default styles of every HTML element. If you are following a design system, you might have a default font size and font color for the website. TailwindCSS provides you with different ways to add your default font size and color to the web page.

Method 1: Adding Default Font Size and Color in TailwindCSS

This is the perfect and recommended method to add default font color and size to your tailwind project. For this method to work, you have to set the default font color and size in the base layer. If you use this method, no matter how many HTML files you have, all the web pages will have the default font size and color. Here is a working code example of adding default styles in the base layer.

In the above example, you can use your own style without using @apply directive. Please check how to edit base styles in TailwindCSS for more information. The output of the above code will look like the following screenshot.

Change default font size and color in tailwindcss

Method 2: Add Classes to Body Tags on Web Pages

The second method is to add font classes to the body tag of your web page in order to change the default size and color. This method is effective when you don’t want a default size and color for every page and you want every web page to have a different default font size and color. The following example adds default font sizes and colors to the body of the page.

Conclusion

There are 2 ways to change the default font size and color in TailwindCSS. The first method is to add the font size and color to the base layer. The second method is to add classes to the body tag of every web page. If you are looking to add custom google fonts or custom fonts from a local file, you can check our blog posts on both these topics.

 

Latest articles

Related articles