Font Weight

Utilities for controlling the font weight of an element.

Class reference

Class
Properties
.font-hairlinefont-weight: 100;
.font-thinfont-weight: 200;
.font-lightfont-weight: 300;
.font-normalfont-weight: 400;
.font-mediumfont-weight: 500;
.font-semiboldfont-weight: 600;
.font-boldfont-weight: 700;
.font-extraboldfont-weight: 800;
.font-blackfont-weight: 900;

Usage

Control the font weight of an element using the .font-{weight} utilities.

Font Weight - 图1

  1. <p class="font-hairline ...">The quick brown fox ...</p>
  2. <p class="font-thin ...">The quick brown fox ...</p>
  3. <p class="font-light ...">The quick brown fox ...</p>
  4. <p class="font-normal ...">The quick brown fox ...</p>
  5. <p class="font-medium ...">The quick brown fox ...</p>
  6. <p class="font-semibold ...">The quick brown fox ...</p>
  7. <p class="font-bold ...">The quick brown fox ...</p>
  8. <p class="font-extrabold ...">The quick brown fox ...</p>
  9. <p class="font-black ...">The quick brown fox ...</p>

Responsive

To control the font weight of an element at a specific breakpoint, add a {screen}: prefix to any existing font weight utility. For example, use md:font-bold to apply the font-bold utility at only medium screen sizes and above.

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

Font Weight - 图2

all

Font Weight - 图3

sm

Font Weight - 图4

md

Font Weight - 图5

lg

Font Weight - 图6

xl

  1. <p class="font-normal sm:font-bold md:font-thin lg:font-semibold xl:font-black ...">The quick brown fox jumped over the lazy dog.</p>

The quick brown fox jumped over the lazy dog.

Hover

To control the font weight of an element on hover, add the hover: prefix to any existing style and decoration utility. For example, use hover:font-bold to apply the font-bold utility on hover.

Font Weight - 图7

  1. <div class="text-center text-blue-700">
  2. <a href="#" class="font-normal hover:font-bold">Hover over this link</a>
  3. </div>

Hover utilities can also be combined with responsive utilities by adding the responsive {screen}: prefix before the hover: prefix.

  1. <a href="#" class="... md:font-normal md:hover:font-bold ...">Link</a>

Focus

To control the font weight of an element on focus, add the focus: prefix to any existing style and decoration utility. For example, use focus:font-bold to apply the font-bold utility on focus.

Font Weight - 图8

  1. <input class="font-normal focus:font-bold ..." value="Focus me">

Focus utilities can also be combined with responsive utilities by adding the responsive {screen}: prefix before the focus: prefix.

  1. <input class="... md:font-normal md:focus:font-bold ..." value="Focus me">

Customizing

Font Weights

By default Tailwind provides 10 font-weight utilities. You change, add, or remove these by editing the theme.fontWeight section of your Tailwind config.

  1. // tailwind.config.js
  2. module.exports = {
  3. theme: {
  4. fontWeight: {
  5. - hairline: 100,
  6. + 'extra-light': 100,
  7. - thin: 200,
  8. light: 300,
  9. normal: 400,
  10. medium: 500,
  11. - semibold: 600,
  12. bold: 700,
  13. - extrabold: 800,
  14. + 'extra-bold': 800,
  15. black: 900,
  16. }
  17. }
  18. }

Responsive and pseudo-class variants

By default, only responsive, hover and focus variants are generated for font weight utilities.

You can control which variants are generated for the font weight utilities by modifying the fontWeight property in the variants section of your tailwind.config.js file.

For example, this config will also generate active and group-hover variants:

  1. // tailwind.config.js
  2. module.exports = {
  3. variants: {
  4. // ...
  5. - fontWeight: ['responsive', 'hover', 'focus'],
  6. + fontWeight: ['responsive', 'hover', 'focus', 'active', 'group-hover'],
  7. }
  8. }

Disabling

If you don’t plan to use the font weight utilities in your project, you can disable them entirely by setting the fontWeight property to false in the corePlugins section of your config file:

  1. // tailwind.config.js
  2. module.exports = {
  3. corePlugins: {
  4. // ...
  5. + fontWeight: false,
  6. }
  7. }

← Font Style   Font Variant Numeric →