Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind plugin for responsive font sizes

Tags:

tailwind-css

Does anybody know any existing plugin for Tailwind CSS which makes font sizes responsive, except for lower and upper screen size where font size is fixed? Similar to the CSS:

body { font-size: calc(16px + (26 - 16) * ((100vw - 768px) / (1280 - 768))); }
@media screen and (max-width: 768px) { body { font-size: 16px; }}
@media screen and (min-width: 1280px) { body { font-size: 26px; }}
  • lower screen width - fixed font size
  • screen sizes in between - responsive font size from 16px to 26px
  • wider screen width - fixed font size
like image 369
MrB Avatar asked Dec 13 '25 06:12

MrB


1 Answers

1- Define font sizes for each breakpoint on tailwind.config.js

module.exports = {
    theme: {
      extend: {
        fontSize: {
          'body-lg': '1rem',
          'body': '.875rem',
        }
      }
    }
  }

2- Create classes on global.css by importing definitions from config file.

@layer base {
  body {
    @apply text-body;
  }
  
  @screen lg { /* applying font size for lg breakpoint */
    body {
      @apply text-body-lg;
    }
  }
}
like image 61
zonay Avatar answered Dec 16 '25 20:12

zonay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!