Html overlays. How to make comments in html

In this lesson, I will talk about how comments in HTML, CSS, PHP... Comments are text that is not visible on the web page. They are used for all sorts of explanations, reminders, descriptions for webmasters, which allows you to structure the document. Comments are indispensable when debugging code, they allow you to quickly navigate the markup of a web page and find required block... Comments are often used to debug HTML code. For example, you can temporarily comment out a specific block of code so that it does not run, and if necessary, it can be easily restored.

HTML comments

In HTML, comments are formed using symbols:... Thus, any text between these symbols is a comment. Let's consider an example:

CSS Comments

CSS comments are created using the symbols: / * and * /. To create a comment, you just need to place the web page code between these symbols:

/ * Beginning of a block with styles for Body * / body (background: #efeded; font-family: Verdana, Helvetica, sans-serif; font-size: 12px; margin: 0px; padding: 0px;) / * End of a block with styles for Body * /

PHP Comments

PHP comments can be single-line or multi-line:

1) Single line comments in PHP are created using the symbols: //. You just need to put this symbol in front of the line and it will be commented out. This option is used when the comment consists of only one line.

2) To implement multi-line comments, the following symbols are used: / * and * /. This option is useful if the comment spans multiple lines.

Thus, we have learned to do

I'll start this article with what comments are for. Suppose you are developing a module with a complex structure. Or you make a layout with many element attachments. In such cases, it is best to mark some parts of the code somehow - for this, there are comments.

Now I will show in detail the four types of comments, more precisely, all their types for four different codes.

Comments in HTML markup

In order to add a comment to HTML markup, use:

Everything in these tags is not visible on the screen, but can be viewed in the source code.

Comments in CSS styles

To add a comment to CSS styles, use:

Everything that is in these tags is not taken into account when forming styles, but is available for viewing in the styles file itself.

JavaScript Comments

For adding comments in JavaScript there are their two types.

First type:

// Text, code or other

Second type:

/ * Text, code or other * /

Anything in these tags is not taken into account when executing the script, but is viewable in the JavaScript file itself.

Comments in PHP code

This programming language, unlike the previous ones, has 3 types of comments.

First type:

// Text, code or other

Second type:

/ * Text, code or other * /

And the third type:

# Text, code or other

Anything in these tags is not taken into account when executing the script and is visible only in the PHP file itself.

Note!

/ * / * My code * / * /

will give you an error.

Sometimes it becomes necessary to comment out the html code. Why might this be necessary? To disable its effect for a while, but not delete it at all. It's just convenient, so in this article I will show you how.

How to comment out a line in html

There is a special tag for this - ... All the code that needs to be commented out is inserted into it. For example, html has three paragraphs. For some reason, you need to remove one of them for a while, but not remove it from the code.

This is how this tag is used to comment out html. The angle bracket opens first, then goes exclamation mark and two hyphens. Next, you need to write something that directly turns into a comment.

In our case, this is the code that creates the paragraph. Thus, the browser will ignore this code, it will remain visible only in text editorand you won't see it on the web page. The comment must also be closed with a double hyphen and an angle bracket.

You can comment out as many lines as you like in html. Just close the tag where you want the comment to end. If you are using a normal code editor, then the commented out part will be highlighted differently. For example, in Notepad ++ it looks like this:

Why do you need comments in html

In general, they are left by web developers when creating a site, so that later it would be easier for them and others to understand the code. This is a very good development tone, because even people who are poorly versed in site building can somehow navigate the code based on clear comments.

Also, as already mentioned, you can enclose other tags in the comment and thus disable their effect for a while. This is a great technique for spotting layout errors when you need to find the cause. incorrect display some element.

Now you know how it works, what it is for and how to comment out the html yourself.

Before learning how to make comments in html, you need to figure out what they are for. If you are interested in such information, you are probably already in the know, so we will not dwell on this issue. Some people don't pay enough attention to the placement of comments in their codes. In single page sites, this error may go unnoticed. But when it comes to huge portals, small comments will save time and make your life easier. Plus, notes allow other developers to understand your code when additional explanation is needed.

goal

Sometimes creating an html page is not complete without confusing codes and ever-repeating tags. New classes, selectors, id-identifiers, etc. All this can literally drive you crazy. Html comments are designed to ease the plight of web developers. After all, when the site code stretches far down, it is difficult to remember what and where is. It is the comments that help to make small notes right in the html-code that will not be visible to your users. Newbies rarely use this tag. But already experienced specialists single out a huge, useful property comments. This tag is especially effective when several developers are working on the code at once. Instead of asking questions and interrupting your partner from work every time, you just need to look at the comments.

Creature

So that your code appears new line with a comment, you must add the following entry:... This is what this tag looks like in html. Anything inside it will not be displayed to users. Html comments should not stretch over several lines and contain any code (this is considered bad form). They should contain only some description of the developer's intentions regarding the insertion of this particular tag, attribute or value. Although among high level There is a popular belief among experts that the code should be written in such a way that no additional explanation is required. But, unfortunately, not everyone has such a gift for writing html pages.

Features:

Tag has some peculiarities. For example, you can add any other tags inside it, but you cannot create nested comments. This will lead to a not quite expected result. Html comments are widely used for testing web pages. For example, when you need to look at a site without a specific tag, but you cannot delete it, since it will be difficult to restore the entire source... In this case, you just need to put the necessary part of the page in the comments. And then the tag will be ignored by the browser. But it is worth noting that all comments can be traced if you open the source code of the page. And every user can do this. Therefore, you should not put any important information inside this tag.

Did you like the article? To share with friends: