HTML5: How to comment HTML tags?
Go To Exercise page(Hyperlink)
Solution :
HTML Code :
<!-- Declare the document type as HTML5 -->
<!DOCTYPE html>
<!-- Start the HTML document -->
<html>
<!-- Start the head section containing metadata about the document -->
<head>
<!-- Set the character encoding to UTF-8 -->
<meta charset="utf-8">
<!-- Set the title of the document to "JS Bin" -->
<title>JS Bin</title>
<!-- Close the head section -->
</head>
<!-- Start the body section containing the content of the document -->
<body>
<!-- Create a paragraph with the text "HTML Tutorial" -->
<p>HTML Tutorial</p>
<!--
The following line is commented out:
<p>Python Tutorial</p>
Uncommenting it would display "Python Tutorial" in the document.
-->
<!-- Create another paragraph with the text "PHP Tutorial" -->
<p>PHP Tutorial</p>
<!-- Close the body section -->
</body>
<!-- Close the HTML document -->
</html>
Sample Output:
HTML Tutorial PHP Tutorial
Explanation:
The above HTML code defines a basic HTML5 document with metadata in the head section and a body containing paragraphs with different tutorial names. One of the paragraphs is commented out and won't be displayed.
- <!DOCTYPE html>: Declares the document type as HTML5.
- <html>: Marks the beginning of the HTML document.
- <head>: Contains metadata about the document, such as character encoding and the title.
- <meta charset="utf-8">: Sets the character encoding to UTF-8.
- <title>JS Bin</title>: Sets the title of the HTML document to "JS Bin."
- </head>: Closes the head section.
- <body>: Contains the actual HTML document content.
- <p>HTML Tutorial</p>: Creates a paragraph with the text "HTML Tutorial."
- <!--<p>Python Tutorial</p>-->: This line is commented out and won't be displayed. If uncommented, it would create a paragraph with the text "Python Tutorial."
- <p>PHP Tutorial</p>: Creates a new paragraph with the text "PHP Tutorial."
- </body>: Closes the body section.
- </html>: Marks the end of the HTML document.
Live Demo :
See the Pen comment-answer by w3resource (@w3resource) on CodePen.
View the example in the browser
Supported browser
Yes | Yes | Yes | Yes | Yes |
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
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/basic/comment-answer.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics