Adjusting Font Weights in Tailwind CSS
Adjusting Font Weights in Tailwind CSS
Font weight in Tailwind CSS controls the thickness of the text. Tailwind provides a set of utilities to adjust font weight, which can help you emphasize certain text, create a hierarchy, or improve readability.
1. Font Weight Utilities
Tailwind CSS provides utility classes to adjust font weights using a range of predefined values. These utilities map to standard font-weight values, which you can apply to any text element.
Utility Classes
font-thin
: Sets the font weight to100
.font-extralight
: Sets the font weight to200
.font-light
: Sets the font weight to300
.font-normal
: Sets the font weight to400
(default).font-medium
: Sets the font weight to500
.font-semibold
: Sets the font weight to600
.font-bold
: Sets the font weight to700
.font-extrabold
: Sets the font weight to800
.font-black
: Sets the font weight to900
.
Font Weight Values:
100
: Thin200
: Extra Light300
: Light400
: Normal500
: Medium600
: Semi Bold700
: Bold800
: Extra Bold900
: Black
Example Usage:
Thin Font Weight
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thin Font Weight Example</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@3.0.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<p class="font-thin bg-blue-500 text-white p-4">
This text has a thin font weight.
</p>
</body>
</html>
Normal Font Weight
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Normal Font Weight Example</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@3.0.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<p class="font-normal bg-red-500 text-white p-4">
This text has a normal font weight.
</p>
</body>
</html>
Bold Font Weight
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bold Font Weight Example</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@3.0.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<p class="font-bold bg-green-500 text-white p-4">
This text has a bold font weight.
</p>
</body>
</html>
Black Font Weight
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Black Font Weight Example</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@3.0.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<p class="font-black bg-yellow-500 text-white p-4">
This text has a black font weight.
</p>
</body>
</html>
2. Customizing Font Weights
You can extend or customize font weights in your tailwind.config.js
file if you need specific values that are not included in the default configuration.
Configuration Example:
// tailwind.config.js
module.exports = {
theme: {
extend: {
fontWeight: {
'extra-light': '100',
'extra-bold': '800',
},
},
},
};
Using Custom Font Weights:
Extra Light Font Weight
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Extra Light Font Weight Example</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@3.0.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<p class="font-extra-light bg-gray-800 text-white p-4">
This text has an extra light font weight.
</p>
</body>
</html>
Extra Bold Font Weight
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Extra Bold Font Weight Example</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@3.0.0/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<p class="font-extra-bold bg-gray-900 text-white p-4">
This text has an extra bold font weight.
</p>
</body>
</html>
Summary
Font Weight Utilities:
font-thin
: Font weight100
.font-extralight
: Font weight200
.font-light
: Font weight300
.font-normal
: Font weight400
(default).font-medium
: Font weight500
.font-semibold
: Font weight600
.font-bold
: Font weight700
.font-extrabold
: Font weight800
.font-black
: Font weight900
.
Custom Font Weights:
- Define custom values in
tailwind.config.js
for additional font weights.
- Define custom values in