DEV Community

paulomoro
paulomoro

Posted on • Updated on

HTML AND CSS COMMENTS, USES AND IMPORTANCE

What is a Comment?
A comment is an explanation or description of the source code of a program, They are piece of codes that are ignored the compiler or interpreter
The syntax of comments in various programming languages varies considerably.

Importance and Uses of Comment
As a programmer comments helps in making codes easy to understand, easy to debug and also stimulate code readability between the programmer and others.
Comments are also used to document programs and remind programmers of what tricky things they just did with the code and also helps the later generation for understanding and maintenance of code.

HTML5 COMMENTS
HTML5 comments are placed in between <!-- ... --> tags. So, any content placed with-in <!-- ... --> (comment)tags will be treated as a comment and will be completely ignored by the browser.

Example:

<!-- This is a HTML5 comment -->

VALID AND NON VALID COMMENTS
Comments do not nest each other, i.e a comment should not be placed inside another comment. Also when writing comments we do well to make sure that there are no spaces in the start-of comment string.

e.g

< !-- This is an invalid HTML5 comment -->

from that example we can say it is an invalid comment because a space occurs between the left angle bracket and the exclamation mark and as a result the web browser will not ignore it.

<!-- This is an valid HTML5 comment -->
This is a valid comment because it contains no space between the left bracket and the exclamation mark.

MULTI LINE COMMENTS
So far we have seen single line comments, but HTML supports multi-line comments as well. You can comment multiple lines by the special beginning tag <!-- ... and ending tag --> placed before the first line and end of the last line as shown in the given example below.

      <!-- 
         This is a multiline comment and it can
         span through as many as lines you like.
      -->

CSS Comment
CSS uses the C-like "comment block"-style comments: /* */ . This allows for multi-line comments, and you can quickly use it to disable portions of your code.

e.g

/* css comment */

Note
Don't use comments as an excuse for unclean code. It can be tempting, when you're in a rush, to poorly write codes, then write a comment that explains what it actually does or why you took the shortcuts that you did.
This might be OK as a temporary fix, but don't make it standard practice. Instead, strive to make your code itself as clean and readable as possible. This keeps the need for comments minimal in the first place.

Oldest comments (2)

Collapse
 
waleedd1 profile image
waleedd1 • Edited

As there are many who are into HTML AND CSS COMMENTS, USES AND IMPORTANCE so we all can say that do my accounting homework will be what we are looking forward to for them as well. You can see that and we will be able to talk about this for now as well.

Collapse
 
simfpayn profile image
simfpayn

Students may use the dissertation writing services review to contact top essay writing experts who will aid them with high-quality assignments. If the pupils choose seasoned specialists, the experts have years of experience in the industry.