How To Change Font Size In CSS

Changing the font size in CSS is an essential skill for web developers and designers. By altering the font size, you can improve the readability of your website and enhance its overall appearance.

This tutorial will guide you through various techniques to change the font size in CSS.

Step 1: Inline CSS

Using inline CSS is a straightforward option to modify the font size of a specific element.

Add the style attribute inside the HTML tag, then set the font size with the help of the font-size property. Take a look at the example below:

In this example, the font size of the paragraph will be 20 pixels.

Step 2: Internal CSS

If you wish to style multiple elements of the same type within an HTML page, an internal CSS would be more appropriate.

Use the <style> tag inside the <head> section of the page and define the styles for the desired elements:

This code will set the font size to 20 pixels for all the <p> elements of the page.

Step 3: External CSS

For large web projects, using an external CSS file is best for managing styling efficiently.

Create a separate CSS file and add the font-size property to the desired elements. Then, link it to the HTML page using the <link> tag in the <head> section:

This method will set the font size of all <p> elements to 20 pixels, by linking the external CSS file to the HTML page.

Step 4: Using units for font size

Various units can be used for font size, such as pixels (px), em, rem, and percentages (%). Choose the one that best suits your needs:

Full Code

Output

Conclusion

In this tutorial, you have learned several techniques to change the font size of elements in CSS. You can now apply inline CSS, Internal CSS, or external CSS while considering the various units for font size. These techniques will offer greater control over the appearance of your website and help you create a more visually appealing user experience.