If you want to customize font sizes in CSS, you can use relative values like 'em' in combination with setting the font size on the 'body' element. By setting a base font size on the 'body', you can then use 'em' values to adjust the size of other elements in a nested manner. For example, if the 'body' font size is set to '16px' and you use '1em' for other elements, they will also be '16px.' Using '2em' would make them '32px.'
body {
font-size: 16px;
}
h1 {
font-size: 2em; // 16 * 2 = 32px
}
p {
font-size: 1.5em; // 16 * 1.5 = 24px;
}
If you are working with SASS, you can define font size variables and easily modify them. This allows for easy adjustments to font sizes throughout your project.
$font-size-sm: 16px;
$font-size-lg: 32px;
h1 {
font-size: $font-size-lg;
}
p {
font-size: $font-size-sm;
}
Additionally, you can perform calculations using these variables to make dynamic changes to font sizes. However, be cautious about maintaining consistent scale ratios between different font sizes to avoid visual inconsistencies.
For specific projects, like the one I work on, you may need to adjust font sizes based on different environments. In these cases, using SASS variables to define font sizes and creating separate style sheets for each environment can streamline the process.