×

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

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 Wbr Tag

The Line Break Opportunity element A word break opportunity is a place in text from where the browser breaks a line. This opportunity is represented by the element wbr in the...

2 minutes read.

HTML Elements

An HTML element is nothing but a starting tag and then some content and then the closing tag. So we can say HTML elements is everything from the starting tag...

3 minutes read.

HTML Basic Tags

Heading Tags: This tag represents the document header. It is said to be a good practice if every document starts with Heading. Heading tags ranges from H1 to H6 i.e....

3 minutes read.

HTML Tutorial

Introduction This HTML tutorial helps beginners and professionals to learn HTML easily. HTML is a widely used web technology for website development. It stands for Hyper Text Markup Language. It is mainly used to...

7 minutes read.

HTML Images

HTML has <img> tag to display image on the web pages or web application. This tag is an empty tag i.e. we don't have to close this tag while using. SYNTAX: <img src="source address" attributes="alt, height, width"> Example: <html>   <body>   <center>Image tag Example</center>   <img src="https://www.tutorialandexample.com/resources/images/favicon.png"    alt="tutorialandexample"/>   </body>   </html> Output: Image...

1 minute 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.

HTML <strong> tag

The strong element in HTML is used to display the real significant information in bold so that the user or reader will understand it easily. Syntax: <p> <strong>………… </strong> </p> Example Here, we will demonstrate how to...

2 minutes read.

Html &lt;datalist >Tag

The autocomplete feature in HTML files is provided by the <datalist> tag. It can be used in conjunction with an input tag to enable users to quickly fill out form...

4 minutes read.

Design a tribute page using HTML and CSS

A tribute page is a webpage based on a person who inspired us in our life. In this article, we will create a webpage of Mahatma Gandhi. We are going...

5 minutes read.

HTML <script> Tag

For embedding a client -side script, we use script tag in html tag. This <script> tag can be used for containing scripting statements. It can also point another external script file...

2 minutes read.

How to insert spaces/tabs in text using HTML/CSS

What is HTML? HTML or HyperText Markup Language is used to design web pages. It was released in 1993. The file extension name for HTML file is “.html”. An HTML file...

4 minutes read.

CSS Clearfix

CSS Clearfix: A clearfix (or clear float) in CSS is for a component to clear or fix the child component, so we don’t need to insert additional markup. The clear...

4 minutes read.

How to Create a Portfolio Gallery using HTML and CSS?

First, before starting this, the user should know some of the basics of HTML and CSS to create a portfolio gallery. To add more functionality to the website, we can also...

7 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 <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 <section> tag

The section element in HTML is used to define sections in a document. Syntax of Section Tag: <body> <h1>……….</h1> <section> <h2>……….</h2> <p> …………………………</p> </section> <section> <h2>………..</h2> <p>…………………………. <p> </section> </body> Examples of Section Tag Example 1: In this example, we use the HTML "section" element...

3 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.

How to add Google Translate Button on your Webpage?

Google translator is a multi-language translator used for translating the webpage. Google develops it. In today's digital age, it is essential because information is available worldwide in some specific language...

5 minutes read.

HTML Video

HTML VIDEO: HTML5 has introduced the <video> tag to embed video into the webpage directly without using the plug-ins.   Syntax: <video attributes >     <source src="address" type="video/mp4">     Your browser does not support the video tag.   </video> <video width="320" height="240" controls>     <source src="mountain.mp4" type="video/mp4">     Your browser does not support the video tag.   </video> Output: ← Prev ...

1 minute read.