When working with any kind of code, you may come to a point where you need to label certain lines. You may want to stop and come back to work on the code another time and leave yourself a note so you don’t have to read through each line to make sure it is correct. You may also want to write yourself notes if you are a beginner and need to refer back to that text document to know what each line of code means/does. Another reason for adding comments would be if you were sharing your code with someone else. They need to know why you wrote the code that you did and what it is actually doing. I am going to show you how to write a comment in CSS and HTML. They are slightly different but will do the same thing. It will allow you to write anything you want in your text document without affecting the code itself.
<!– Link to Home page –>
<!– Link to Contact page –>
The red text shows the comments in HTML. It starts with “<!–“ and ends with “–>”. You can write anything you want between them. The purpose of comments is to write something without changing your code at all. I even like to add fun little comments if I am sharing my code with someone else because I know that whatever I write will NOT show up on the page.
/* 24 is also the current font size for the content section on the home page */
This is what a comment will look like on your CSS style sheet. It looks a little different than a comment in HTML, but it acts the same way. You can write whatever you want without changing your code. Start with “/*” and end with “*/”. It’s as simple as that.
These comments can go anywhere in your code. Just make sure to use the correct format for the type of code you are working with. Remember that the comments will not be interpreted, so you can write in any format you want to.
View upcoming HTML classes here.