HTML and CSS: Programming Comments
Overview
Comments written in code by developers provide a mechanism to help explain the purpose and function of that code.The code will need to be maintained and will change. Comments can be used while developing code to provide reminders or 'to do' lists or notes of improvement opportunities. Comments are not processed nor displayed to the user in the rendered document in HTML and CSS. Comments may be placed in any available white space.
Prepare
- Read: 📄 HTML Comment
Tag - w3schools.com
HTML comments are not rendered in the browser. - Read: 📄 CSS Comments - MDN
CSS comments have no effect on the layout or presentation of a document.
<!-- This is a comment -->
CSS Comment Example
/* This is a comment */
Feel free to use comments as needed in your learning activities and assignments to remind you of things that you want to reference or document for future use. Those comments are for you, however, remember that organizations may have comment requirements given many developers might work on a project over its lifetime.
Code comments may even be snippets of code.
The concept of a comment is used even in your git
commits which again, are
especially useful to track history and to give context to your commits to your dev team.
Activity Instructions
- Open up any HTML or CSS document in VS Code.
- Use
ctrl+/
(⌘+/
) to comment out the line of code where you cursor is currently located or lines of code that you have selected. - Pressing
ctrl+/
again will toggle the commented out line(s) of code.
Optional Resources
- CSS Comments - MDN