×

HTML Font Size

The HTML <font> tag uses the size attribute to specify the size of the text. We can set the size attribute’s value from 1 to 7. The default size of the font is 3.

You should not use the font size to display paragraphs as headings or to display headings as paragraphs. Every tag in HTML has a purpose, so use the HTML tag as per the requirement.

Use appropriate HTML tags, such as <h1> to <h6> for headings and <p> for paragraphs. The <h1> tag represents the main heading or important heading of the page once used in a web page, and the <h6> tag represents a less important heading.

We do not specify heading tags for size, but we use them for specifying the titles and importance of something.

We can also use the style attribute to change the font size of an HTML document. We can also use font-size property and define it inside the <style> tag.

Syntax:

There are three ways in which we can provide font size to the element:

  • Using <font> tag with size attribute:
<font size="value"> Some text </font>
  • Using style attribute with font-size property:
<element_name style="font-size: value"> Some text </ element_name>
  • Using font-size property inside the <style> tag:
<style> font-size: 20px; </style>

Examples of HTML Font Size

Example 1:

This example demonstrates the use of the <font> tag with the size attribute. We are using font sizes from 1 to 7.

<!DOCTYPE html>
<html>
<head>
    <title>
        Example 1 of HTML Font Size
    </title>
</head>


<body>
<div> 
    <font size="1"
          <p> The size of this text is 1. </p>
    </font>
</div>
<div> 
    <font size="2"
          <p> The size of this text is 2. </p>
    </font>
</div>
<div> 
    <font size="3"
          <p> The size of this text is 3. </p>
    </font>
</div>
<div> 
    <font size="4"
          <p> The size of this text is 4. </p>
    </font>
</div>
<div> 
    <font size="5"
          <p> The size of this text is 5. </p>
    </font>
</div>
<div> 
    <font size="6"
          <p> The size of this text is 6. </p>
    </font>
</div>
<div> 
    <font size="7"
          <p> The size of this text is 7. </p>
    </font>
</div>
</body>
</html>

Output:

The output shows the text of different font sizes.

HTML Font Size

Example 2:

This example shows the use of HTML font sizes. We are using font size as inline style attribute to provide the size to <h1> and <p> element.

<!DOCTYPE html>
   <html>    
      <head>      
         <title> Example 2 of HTML Font Size </title>    
      </head>    
      <body>      
         <h1 style="color: purple; font-size:55px;"> Font Size </h1>      
         <p style="color: blue; font-size:35px;"> This is paragraph 1. </p>
         <p style="color: red; font-size:65px;"> This is paragraph 2. </p>    
         <p style="color: green; font-size:33px;">This is paragraph 3. </p>    
         <p style="color: pink; font-size: 45px;">This is paragraph 4. </p>    
      </body>
</html>

Output:

The output shows text of different sizes applied to them by using the font-size property inside the style attribute.

HTML Font Size

Example 3:

In this example, we are using the font size inside the <style> tag to provide size to the HTML form elements.

<!DOCTYPE html>  
<html>  
<head>  
<title> Example 3 of HTML Font Size </title>  
<style>
body {  
font-family: Arial, Helvetica, sans-serif;  
background-color: violet;  
font-size:20px;
}   
.container {  
padding: 50px;  
background-color: #a3eaea;
font-size:20px;  
}  
input[type=text] {  
  padding: 12px; 
  width: 100%;  
  border: none;  
  margin: 2px 0 20px 0;  
  font-size:20px;
  background: lavenderblush;  
}  
input[type=text]:focus {  
background-color: rgb(164, 183, 189);  
font-size:20px;
outline: none;
}  
</style>
</head>  
<body bgcolor="cyan">  
<center>  
<h1> Applying Font size in the form </h1>  
</center>  
<form class="container"> 
    <label for="firstname"> First Name: </label>  <input type="text" name="firstname" value="First name">
    <br> 
    <br>
    <label for="lastname"> Last Name: </label>  
    <input type="text" name="lastname" value="Last name">
    <br>
    <br>
    <label for="Email-id"> Email Id: </label> 
    <input type="text" name="Email-id" value="Email-id">
    <br>
    <br>
    <label for="Employee-Id"> Employee Id: </label>
    <input type="text" name="Employee-Id" value="Employee-id">
    <br>
    <br>
    <label for="Gender"> Gender: </label>
    <select name="Gender">
        <option value="Male"> MALE </option>
        <option value="Female"> FEMALE </option>
        <option value="Other"> OTHER </option>
    </select>
    <br>
    <br>
    <label for="Phone Number"> Phone Number: </label>
    <input type="text" name="Phone Number" value="Phone Number">
    <br>
    <br>
   <button type="Submit"> SUBMIT </button>
   <button type="Reset"> RESET </button>
  </form>
</body>  
</html>

Output:

The output shows a form with different font sizes applied on the elements.

HTML Font Size

Browser Support:

The following browsers support it:

  • Google Chrome
  • Internet Explorer
  • Microsoft Edge
  • Opera
  • Mozilla Firefox
  • Safari

Related Topics

HTML5 Button Tag

HTML Button Tag The < button > tag is used on the webpage to construct a clickable button inside the HTML. Within the < button>....</button > tag, we can place content...

2 minutes read.

What does HTML stand for?

HTML stands for Hyper Text Markup Language. We use this markup language to design a web page. Web browsers use this language to showcase text, videos, images, audio and other...

6 minutes read.

HTML <svg> tag

SVG is used to determine the vector-based graphics in XML format. What is SVG? We utilize SVG tag to specify visuals for the website. The attribute of SVG in a HTML document...

2 minutes read.

How to change font in HTML

To give style to the content of your website, you may change the font of the text and make your website look attractive to the user. There are several methods which...

4 minutes read.

HTML5 Tags

HTML5 Tags A list of newly included tags is provided in HTML5. These HTML 5 tags (elements) provide a better structure for the document. This list shows description of all HTML...

3 minutes read.

HTML Event Attributes

HTML Event Attributes If a browser responds to the user behavior, an event is called. For example, if we click on the submit button, a box of details will appear on...

4 minutes read.

HTML <br> tag

HTML is referred to as Hyper Text Markup Language, which is the most popular language for creating Web pages. HTML explains the construction of a Web page. It contains a...

4 minutes read.

HTML <address> Tag

Hyper Text Markup Language, HTML is the best markup language for creating Web pages. HTML consists of a wide variety of elements. In all of these elements, one element is...

4 minutes read.

HTML Anchor

HTML Anchor The HTML anchor tags define a hyperlink that links to other pages on one page. It can create hyperlinks to any web page and files, locations or any other...

3 minutes read.

HTML Unordered List

In HTML, we have <ul> tag which defines the unordered list. And it is also known as bulleted list, because as we know it is not ordered list therefore it...

2 minutes read.

HTML Forms

Forms are required when we want to collect data from the user. Html forms consists of different fields to take user inputs such as: input, text area, checkbox, password, radio...

4 minutes read.

HTML Frames

Frames in Html is used to divide the browser into different sections where each section can load different Html documents. Collection of frame is known as Frameset. Creating frames:We use frameset...

2 minutes read.

HTML <sub> tag

The sub element in HTML is used to describe one or more subscript texts. If The sub tag shows the text which is presented in a smaller font and below...

2 minutes read.

HTML Id Attribute

The HTML id attribute represents the unique identifier for an element of the HTML document. Each element has its unique identifier. The id attribute is a global attribute that can be...

12 minutes read.

What is a Container tag?

In HTML, there are different types of tags or say instructions which make the developer specify various elements in the document and make the browsers understand what to display. Tags in...

5 minutes read.

Responsive HTML5 and CSS3 Tutorial

Introduction to HTML5 Tutorial HTML5 is the latest and upgraded version of HTML. HTML is a hypertext markup language. Technically, it is not a programming language. It is a markup language. HTML...

17 minutes read.

HTML 5 Tutorial

What is HTML5? HTML5 is a programming language which stands for the acronym Hyper Text Markup Language 5. It is program that enables the appearance of web pages to be changed, as well as changes...

5 minutes read.

HTML Font Size

The HTML <font> tag uses the size attribute to specify the size of the text. We can set the size attribute’s value from 1 to 7. The default size of...

4 minutes read.

HTML Reset Button

The HTML reset button is used to reset all values in the form. It clears all input fields. Reset is the value of the type attribute of the button element. The...

6 minutes read.

Html &lt;dd> Tag

In an HTML description list, an item's definition or description is indicated using the definition description ("dd" tag). A <dd> tag can contain paragraphs, line breaks, images, links, and lists. It...

4 minutes read.