Open In App

How to change the text color & size by accessing the HTML element ?

Last Updated : 30 Jan, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

You would want to make your HTML text look nice for many reasons. HTML provides you with the option to edit the text size, font, color etc according to your liking. To do so, you’ll need to alter their appearance using CSS’s color and font-size properties. This article will provide you with two methods on how to make your HTML texts look good.

Method 1: Using an Inline Style attribute

With the color and font-size properties, you may modify the color and size of your text from inside its tag. This is referred to as inline CSS. Color, font, size, and other styles can be applied to an element using the HTML style attribute. CSS (Cascading Style Sheets) is a style sheet language for describing the appearance of a document authored in a markup language like HTML. We’ll show you how to use some of the most common CSS properties here.

  1. The text color is determined by the CSS color attribute.
  2. The font-size attribute in CSS determines the text size that will be displayed.

The style attribute can be used to change the appearance of an HTML element. This is a CSS property. The syntax for the HTML style attribute is as shown in:

<tagname style="property:value;">

The <style> tag is used to define an article’s style information (CSS). You declare how HTML components should render in a browser using the style> element.

Attributes: There are two attributes in this tag, which are listed below:

  • media: Indicates the media/device for which the media resource is best suited.
  • type: The media type of the <style> tag is given here.

The <style> also works well with global attributes and event attributes.

Example: Using the <style> tag to access the HTML element, this example shows how to change the text color.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>Font Color</title>
</head>
  
<body>
    <h1 style="color:green;">Hello GeeksforGeeks.</h1>
    <h2 style="color:green;">Hello GeeksforGeeks.</h2>
    <h3 style="color:green;">Hello GeeksforGeeks.</h3>
    <p style="color:green;">Hello GeeksforGeeks.</p>
  
</body>
  
</html>


Output:

The font-size property in CSS determines the size of the text in an HTML element.

Example: Using the <style> tag to access the HTML element, this example shows how to change the text size.

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>Font Color</title>
</head>
  
<body>
    <h1 style="font-size:500%;">This is GeeksforGeeks.</h1>
    <p style="font-size:300%;">This is GeeksforGeeks.</p>
  
</body>
  
</html>


Output:

Combining the above two codes, we get:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <title>Font Color</title>
</head>
  
<body>
    <h1 style="font-size:300%; color:green;">
        This is GeeksforGeeks.
      </h1>
    <h2 style="color:green;">Hello GeeksforGeeks.</h2>
    <h3 style="color:green;">Hello GeeksforGeeks.</h3>
    <p style="color:green;">Hello GeeksforGeeks.</p>
  
</body>
  
</html>


Output:

Method 2: Using Internal CSS:

If a single HTML page has a distinct style, an internal style sheet may be used. The internal style is defined within the head section’s <style> tag. 

Syntax:

<style>
    h1 {
        property-name=property: value;
    }
</style>

Example: The following example will make you understand it better:

HTML




<!DOCTYPE html>
<html>
  
<head>
    <style>
        h1 {
            color: green;
            font-size: 50px;
        }
    </style>
</head>
  
<body>
  
    <h1>This is GeeksforGeeks.</h1>
      
<p>This is GeeksforGeeks.</p>
  
  
</body>
  
</html>


 Output:

Another way to change the font size and color is by using the <font> tag. Although its discarded, the HTML <font> tag can still be used and is required by some web services. The face attribute, which describes the font to be used, must be included when using the FONT tag. 

Syntax:

<font attribute="value"> Content </font>

Example: Have a look at the following example.

HTML




<!Doctype Html>
<Html>
  
<Head>
    <Title>
    </Title>
</Head>
  
<Body>
    <font color="green">
        <font size="7"> Welcome to GeeksforGeeks </font> <br>
    </font>
    <font color="black">
        Hi this is GeeksforGeeks learning. <br>
    </font>
</Body>
  
</Html>


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads