w3resource

HTML CSS Exercise: Type selector

Solution:

HTML Code :

<!DOCTYPE HTML><!-- Document type declaration -->
<html lang="en"><!-- Opening HTML tag with language attribute set to English -->
<head><!-- Head section containing metadata -->
<meta charset=utf-8><!-- Character encoding declaration -->
<title>CSS Type selector example</title><!-- Title of the HTML document -->
<style type="text/css"> /* Opening style tag for CSS with type attribute */
h1{ /* Type selector targeting all h1 elements */
color:#4b6c9c; /* Set color of h1 elements */
}
</style><!-- Closing style tag -->
</head><!-- Closing head tag -->
<body><!-- Body section of the HTML document -->
<h1>This is heading one</h1><!-- h1 element with text content -->
</body><!-- Closing body tag -->
</html><!-- Closing HTML tag -->

Explanation:

  • The HTML document declares the document type and specifies the language as English.
  • Character encoding is set to UTF-8 to support a wide range of characters.
  • CSS is used to style the <h1> element using a type selector.
  • The style rule sets the color of all <h1> elements to a specific shade of blue.
  • The <h1> element in the body of the document displays text content.

Live Demo :

See the Pen type-selector-answer by w3resource (@w3resource) on CodePen.


Supported browser

Firefox logo Chrome logo Opera logo Safari logo Internet Explorer logo
YesYesYesYesYes

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/type-selector-answer.php