Notes from 'Build a Cat Photo App.'
Commenting
Commenting allows you to leave messages without affecting the browser display. It also allows you to make code inactive. A comment in HTML starts with <!--, contains any number of lines of text, and ends with -->.
Here is an example of a comment with the TODO: Remove h1:
<!-- TODO: Remove h1 -->Note:
Opening: <!-- TODO:
Closing: -->ohhh, that's funny. i just realized that the todo is just a little note for the person as they're making the site. so its like a little sticky note that doesn't interfere with the design? that's so cool!
Spot on! That is the perfect way to describe it. In coding, we call those Comments, and they are exactly like digital sticky notes that the browser is trained to completely ignore.
Why Comments Are Like "Sticky Notes"
As you can see in Step 16, the text `` is grayed out in your index.html Editor.
Invisible to the User: If you look at your Preview, that "TODO" text doesn't appear anywhere on the actual website.
A Map for Your Future Self: Imagine you’re working on a huge project and you have to stop for the night. You leave a comment like `` so you don't feel lost when you wake up.
Collaboration: If you were building a site with a friend, you could leave notes for each other right in the code without breaking the layout.The “main”
HTML5 has some elements that identify different content areas. These elements make your HTML easier to read and help with Search Engine Optimization (SEO) and accessibility.
The main element is used to represent the main content of the body of an HTML document. Content inside the main element should be unique to the document and should not be repeated in other parts of the document.
<main>
<h1>Most important content of the document</h1>
<p>Some more important content...</p>
</main>Essentially…
Am i getting this right, that the main element is basically circling the... "thesis" of the document? i mean, i'm trying to make a comparison. these parts, the header, the cat photos and then the little description, that's like the core intro here.
That is a perfect comparison! If an HTML document were an essay or a legal brief, the <main> element would indeed be the "body" or the "thesis" area.
Accessibility Note: Using <main> is actually a huge help for people who use screen readers. It allows them to "jump" straight to the "thesis" of your site and skip over the repetitive header links.“Nesting”
EX.
<html>
<body>
<main>
<h1>CatPhotoApp</h1>
<h2>Cat Photos</h2>
<!-- TODO: Add link to cat photos -->
<p>Everyone loves cute cats online!</p>
</main>
</body>
</html>Notice how the <h1>, <h2>, and <p> tags are slightly shifted to the right (indented)? This is a common practice in coding. When an element is "inside" another (like your "thesis" is inside the <main>), we indent them so it's visually obvious that they are "children" of that main section.
To be more specific, you put the h1, h2, comment, and p elements inside the main element. This is called nesting. Nested elements should be placed two spaces further to the right of the element they are nested in. This spacing is called indentation and it is used to make HTML easier to read.
Here is an example of nesting and indentation:
<main>
<h1>Most important content of the document</h1>
<p>Some more important content...</p>
</main>Turning Images Into Links…
Other types of content can also be turned into a link by wrapping it in anchor tags.
Here is an example of turning an image into a link:
<a href="example-link">
<img src="image-link.jpg" alt="A photo of a cat.">
</a>this is the core:
<a href="example-link">You add it before the image link. But don’t forget the ending tag:
</a>It’ll come after the link or the attribute (alt) if you have it.
Sections, Subsections & Lists
Before adding any new content, you should make use of a section element to separate the cat photos content from the future content.
The section element is used to define sections in a document, such as chapters, headers, footers, or any other sections of the document. It is a semantic element that helps with SEO and accessibility.
<section>
<h2>Section Title</h2>
<p>Section content...</p>
</section>Figures
The figure element represents self-contained content and will allow you to associate an image with a caption.
The <figure> element isn't the caption itself; it is the container (the frame) that holds both the image and the caption together as one unit.
Why use a "Frame" at all?
You might wonder, "Why not just put a <p> tag under the <img>?"
Semantic Meaning: It helps search engines and screen readers understand that the text and the photo are a "set."
Styling: In the future, when you use CSS, you can move the entire <figure> (image + caption) around the page as one block, rather than trying to move them separately.A figure caption (figcaption) element is used to add a caption to describe the image contained within the figure element.
Here is an example of a figcaption element with the caption of A cute cat:
<figure>
<img src="image.jpg" alt="A description of the image">
<figcaption>A cute cat</figcaption>
</figure>Ahh, so the figcaption is what goes in the figure. The figure creates the availibility for the figcaption to fit.
Emphasis (Italic) and Strong (Bold)
To place emphasis on a specific word or phrase, you can use the em element.
Cool, so <em> </em> essentially gives you italics. Its the code version of adding italics.
The strong element is used to indicate that some text is of strong importance or urgent.Essentially, strong is the code form of Bold.
Unordered lists and Ordered lists
When you add a lower-rank heading element to the page, it's implied that you're starting a new subsection.
To create an unordered list of items, you can use the ul element.
<ul> </ul>The li element is used to create a list item in an ordered or unordered list.
Here is an example of list items in an unordered list:
<ul>
<li>milk</li>
<li>cheese</li>
</ul>The code for an ordered list (ol) is similar to an unordered list, but list items in an ordered list are numbered when displayed.
Review Terms
src & Attributes
HTML attributes are special words used inside the opening tag of an element to control the element's behavior. The
srcattribute in animgelement specifies the image's URL (where the image is located).
Here is an example of an img element with a src attribute pointing to the freeCodeCamp logo:
<img src="https://cdn.freecodecamp.org/platform/universal/fcc_secondary.svg">All
imgelements should have analtattribute. Thealtattribute's text is used for screen readers to improve accessibility and is displayed if the image fails to load.
Here is an example of an img element with an alt attribute:
<img src="cat.jpg" alt="A cat">Link text
A link's text must be placed between the opening and closing tags of an anchor (a) element.
Here is an example of a link with the text click here to go to freeCodeCamp.org:
<a href="https://www.freecodecamp.org">click here to go to freeCodeCamp.org</a>To open links in a new tab… (target)
To open links in a new tab, you can use the target attribute on the anchor (a) element.
The target attribute specifies where to open the linked document. target="_blank" opens the linked document in a new tab or window.
Here is the basic syntax for an a element with a target attribute:
<a href="https://www.freecodecamp.org" target="_blank">freeCodeCamp</a>Footer
The footer element is used to define a footer for a document or section. A footer typically contains information about the author of the document, copyright data, links to terms of use, contact information, and more.
(The footer element comes after the main element).
Note
Notice that everything you've added to the page so far is inside the body element. All page content elements that should be rendered to the page go inside the body element. However, other important information goes inside the head element.
The head element is used to contain metadata about the document, such as its title, links to stylesheets, and scripts. Metadata is information about the page that isn't displayed directly on the page.
The title element determines what browsers show in the title bar or tab for the page.