Coding Notes
2023.07.10
The alt Attribute
The required alt
attribute for the <img>
tag specifies an alternate text for an image, if the image for some reason cannot be displayed. This can be due to a slow connection, or an error in the src
attribute, or if the user uses a screen reader.
1 | <img src="img_girl.jpg" alt="Girl with a jacket"> |
HTML Comment Tag
You can add comments to your HTML source by using the following syntax:
1 | <!-- Write your comments here --> |
CSS Comments
Comments are used to explain the code, and may help when you edit the source code at a later date.
Comments are ignored by browsers.
A CSS comment is placed inside the <style>
element, and starts with /*
and ends with */
:
1 | /* This is a single-line comment */ |
JavaScript Comments
JavaScript comments can be used to explain JavaScript code, and to make it more readable.
JavaScript comments can also be used to prevent execution, when testing alternative code.
Single Line Comments
Single line comments start with //
.
Any text between //
and the end of the line will be ignored by JavaScript (will not be executed).
This example uses a single-line comment before each code line:
1 | // Change heading: |
Multi-line Comments
Multi-line comments start with /*
and end with */
.
Any text between /*
and */
will be ignored by JavaScript.
This example uses a multi-line comment (a comment block) to explain the code:
1 | /* |