![]() |
In HTML, adding color to text and elements is typically done using CSS. However, there are several approaches to add color directly in HTML, without using CSS. We will discuss the following approaches to add color without CSS in HTML Elements. Table of Content Approach 1: Using Font TagUse <font> tag to specify the color of text within the tag. In font tags, we have to use color attributes to provide color names or codes. Syntax<font color="value">
Example: Illustration ofaddingd color in HTML without CSS Using Font Tag. HTML
Output: ![]() Output Approach 2: Using JavaScriptDefine a JavaScript function called changeColor that is used to change the color of an HTML element with the id “myElement”. Here we used <script> tagto add javascript code in HTML. Syntax<script>
<!-- javascript body -->
</script>
Example: Illustration of adding color in HTML without CSS Using JavaScript HTML
Output: ![]() Output Approach 3: Using SVG tag with fill attributeSVG tag allows us to create shapes or text in HTML along witha fill attribute which is used to assign the color to that shape or text. In the below example we have created some shapes with different colors. Syntax<svg width="value" height="value">
<tag fill="value">Text or Shape</tag>
</svg>
Example: Illustration ofaddingd color in HTML without CSS using SVG tag with fill attribute. HTML
Output: ![]() Output Approach 4: Using Text Color AttributeThe text attribute in the <body> tag sets the default text color for all text within the body of the HTML document. Syntax<body text="value">
Example: Illustration of add color in HTML without CSS using Text Color Attribute HTML
Output: ![]() Output Approach 5: Using the bgcolor AttributeThe bgcolor attribute is used to setthe background color ofan element or entire page. Use the attribute inside the <body> tag. Syntax<body bgcolor="value">
Example: Illustration of adding color in HTML without CSS Using the bgcolor Attribute HTML
Output: ![]() Output |
Reffered: https://www.geeksforgeeks.org
HTML |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |