w3resource

CSS Properties: How to set color initial property to its default value?

Go to Exercise page

Solution:

HTML Code:

<!DOCTYPE html><!-- Specifies the document type and version of HTML -->
<html>
<head>
<title>How to set color initial property to its default value</title><!-- Sets the title of the HTML document -->
<style type="text/css"> /* Begins a CSS style block */
div {
    color:initial; /* Sets the text color for all div elements to its initial/default value */
}
h1 {
    color: #FF0000; /* Sets the text color for all h1 elements to red */
}
</style><!-- Ends the CSS style block -->
</head>
<body>
<h1>w3resource Tutorial</h1><!-- Inserts an h1 element with the text "w3resource Tutorial" -->
<div>CSS, stands for Cascading Style Sheet is a computer language to describe presentation of HTML and XML web documents.</div><!-- Inserts a div element with text describing CSS -->
</body>
</html>

Explanation:

  • This HTML document demonstrates how to set the text color initial property to its default value using CSS.
  • The CSS style block defines rules for the div and h1 elements.
  • The text color for all div elements is set to its initial/default value using the color property set to initial.
  • The text color for all h1 elements is set to red (#FF0000) using the color property.
  • The HTML body contains an h1 element with the text "w3resource Tutorial" and a div element with text describing CSS.
  • The text color of the h1 element will appear as red, while the text color of the div element will revert to the default color specified by the browser.

Live Demo:

See the Pen color-initial-answer by w3resource (@w3resource) on CodePen.


See the solution in the browser

Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
Yes Yes Yes Yes Yes

Go to Exercise page

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/html-css-exercise/css-properties/color-initial-answer.php