Comments in HTML
Many times, there might be situations, where you need to explain what you have done, or there might be something that you do not want to be there on the web page when displayed in the browser, but you want it to be in your HTML file. In such situations, you can make use of comments, which are here for our escape.
Well, the comment is just something that is ignored by the browser. At times, we might require to write something on our web page which would be just for us, and not the user, like what the particular line of code does(or something like that), in such cases, you can use the comments.
You can also use the comments if you do not want to execute some line of code, but still, you want to keep it in the HTML file. All you need to do is just comment on the statement you don’t want and it will be ignored by the browser(since the comments are just ignored) …
Well, here is how you write comments →
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Some heading here…</title>
</head>
<body>
<!– this is just some comment –>
<div>This is some text…</div>
</body>
</html>
If you try to open the file in the browser, you can find that the comment is just ignored. Now, understand that the comment starts with a <!– and ends with a –>.
So, something between the <!– and –> will be a comment.
Now, if you want some line to be there in your file, but don’t want it to be displayed on the web page, you can just make it as a comment, and it will be ignored. Have a look at that too →
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Some heading here…</title>
</head>
<body>
<!– this is just some comment –>
<div>This is some text…</div>
<!– <div>this is a div, but it is going to be ignored, because it is a comment</div> –>
</body>
</html>
Well, now if you try to open the file again, you will find that the commented div is not present there. This is because we have commented on it.
We can use the comments as and when required.
Well, now if you try to open the file again, you will find that the commented div is not present there. This is because we have commented on it.
We can use the comments as and when required.