Comments - A Smarter Way To Learn HTML & CSS (2015)

A Smarter Way To Learn HTML & CSS(2015)

59
Comments

Commenting is a way to tell the browser to ignore certain portions of text that you include within the body of code. Comments are for the human, not the machine. They help you and others understand your code when it comes time to revise. You can also use commenting to comment out portions of your code for testing and debugging.

In HTML any text enclosed by an opening <!-- tag and a closing --> tag is invisible to the browser. In the following code “Beginning of questionnaire form” is a comment that the browser ignores.

<!-- Beginning of questionnaire form -->
<form action="questionnaire.php" method="post">
<fieldset>
<legend>Contact info</legend>
<label>First name: <input type="text" name="first-name" size="15" maxlength="30"></label>
[etc.]

Here’s a multi-line comment. When you write a multi-line comment, put the tags on their own separate lines for readability.

<!--
Note to myself. Think about combining the
questionnaire form with the feedback form.
-->

You can also comment CSS code, but the tags are different. It’s /* to open, */ to close.

/* Styles for headings */
h1 {
font-size: 3em;
}
h2 {
[etc.]

You can have mutli-line CSS comments. Again, put tags on their own separate lines for readability.

/*
This CSS file was created on May 28, 2018.
The styles are optimized for a learning site.
*/

In your HTML file add a multi-line comment. In your CSS file add a multi-line comment. Save the files. Display the page. (The HTML comment should not display.)

Sample HTML code is at:
http://asmarterwaytolearn.com/htmlcss/practice-59-1.html.

Sample CSS code is at:
http://asmarterwaytolearn.com/htmlcss/practice-59-2.html.

Find the interactive coding exercises for this chapter at:
http://www.ASmarterWayToLearn.com/htmlcss/59.html