Changing Text Size in HTML: A Guide to Adjusting Font Sizes in Web Development

Estimated read time 3 min read

Introduction to Text Size in HTML

In web development, controlling the size of text is essential for creating visually appealing and readable web pages. HTML provides several methods to change the text size, allowing you to customize the appearance of your content. In this article, we will explore various techniques to adjust text size in HTML and understand how to apply them effectively.

Using HTML Tags for Text Size

HTML offers a set of tags that allow you to specify different levels of importance and formatting for your text. These tags can indirectly affect the text size. Here are some commonly used tags:

Heading Tags (<h1> to <h6>)

Heading tags (<h1> to <h6>) are used to define different levels of headings in a document. The <h1> tag represents the highest level of heading, while the <h6> tag represents the lowest level. The size of the text within heading tags is predefined by the browser, with <h1> being the largest and <h6> being the smallest.

<h1>This is a heading</h1>
<h2>This is a subheading</h2>

Paragraph Tag (<p>)

The <p> tag is used to define a paragraph of text. The default size of text within <p> tags is determined by the browser’s default styles.

<p>This is a paragraph of text.</p>

Span Tag (<span>)

The <span> tag is an inline element used to apply styles to specific parts of a text within a larger block of content. By applying CSS styles to the <span> tag, you can control the size of the text within it.

<p>This is a <span style="font-size: 18px;">custom-sized text</span> within a paragraph.</p>

Using CSS for Text Size

CSS (Cascading Style Sheets) provides more precise control over the appearance of HTML elements, including text size. By applying CSS styles to HTML elements, you can customize the text size according to your requirements. Here are some commonly used CSS properties for text size:


The font-size property is used to set the size of the text. You can specify the size in various units such as pixels (px), percentages (%), or relative units like em or rem. Here’s an example:

<p style="font-size: 18px;">This is a paragraph with custom text size.</p>

em and rem Units

The em and rem units are relative units of measurement for text size. The em unit is relative to the font size of the parent element, while the rem unit is relative to the root (top-level) element. By using these units, you can create scalable and responsive text sizes. Here’s an example:

<p style="font-size: 1.2em;">This is a paragraph with scaled text size.</p>

H2: Using CSS Classes

To maintain consistency and apply the same text size across multiple elements, you can define CSS classes and apply them to the desired HTML elements. Here’s an example:

    .large-text {
        font-size: 24px;

<p class="large-text">This is a paragraph with a large text size.</p>

By defining the .large-text

Mark Stain

My name is Mark Stein and I am an author of technical articles at EasyTechh. I do the parsing, writing and publishing of articles on various IT topics.

You May Also Like

More From Author

+ There are no comments

Add yours