1

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

 1 month ago
source link: https://www.geeksforgeeks.org/how-to-change-the-text-color-size-by-accessing-the-html-element/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

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.

<!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:

Capture-300x129.PNG

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.

<!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:

Capture-300x171.PNG

Combining the above two codes, we get:

<!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:

cssgfg-300x158.png

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:

<!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:

Capture-300x134.PNG

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.

<!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:

Capture-300x128.PNG

“This course was packed with amazing and well-organized content! The project-based approach of this course made it even better to understand concepts faster. Also the instructor in the live classes is really good and knowledgeable.”- Tejas | Deutsche Bank

With our revamped Full Stack Development Program: master Node.js and React that enables you to create dynamic web applications.

So get ready for salary hike only with our Full Stack Development Course.

Last Updated : 30 Jan, 2022
Like Article
Save Article
Share your thoughts in the comments

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK