HTML5 Flashcards
Say Hello to HTML Elements
<h1>Hello</h1>
-> That’s an HTML element (An HTML element is written using a start tag and an end tag, and with the content in between).
Most HTML elements have an opening tag and a closing tag.
Opening tags look like this:
<h1>
Closing tags look like this:
</h1>
The only difference between opening and closing tags is the forward slash after the opening bracket of a closing tag.
Headline with the h2 Element
The h2 element you will be adding in this step will add a level two heading to the web page.
This element tells the browser about the structure of your website. h1 elements are often used for main headings, while h2 elements are generally used for subheadings. There are also h3, h4, h5 and h6 elements to indicate different levels of subheadings.
It is not recommended that you use headings just to make the text big or bold, because search engines use headings to index the web page structure and content.
Inform with the Paragraph Element
p elements are the preferred element for paragraph text on websites. p is short for “paragraph”.
You can create a paragraph element like this:
<p>I'm a p tag!</p>
Browsers automatically add an empty line before and after a paragraph.
Note: As a convention, all HTML tags are written in lowercase, for example <p></p> and not <p></p>.
Fill in the Blank with Placeholder Text
Web developers traditionally use lorem ipsum text as placeholder text. The lorem ipsum text is randomly scraped from a famous passage by Cicero of Ancient Rome.
Lorem ipsum text has been used as placeholder text by typesetters since the 16th century, and this tradition continues on the web.
Comment out/Uncomment HTML
Commenting is a way that you can leave comments for other developers within your code without affecting the resulting output that is displayed to the end user.
Commenting is also a convenient way to make code inactive without having to delete it entirely.
Comments in HTML start with
Introduction to HTML5 Elements
HTML5 introduces more descriptive HTML tags. These include main, header, footer, nav, video, article, section and others.
These tags give a descriptive structure to your HTML, make your HTML easier to read, and help with Search Engine Optimization (SEO) and accessibility. The main HTML5 tag helps search engines and other developers find the main content of your page.
Example usage, a main element with two child elements nested inside it:
<h1>Hello World</h1>
<p>Hello Paragraph</p>
Forms
- The Web Forms 2.0 specification allows for creation of more powerful forms and more compelling user experiences.
- Date pickers, color pickers, and numeric stepper controls have been added.
- Input field types now include email, search, and URL.
- PUT and DELETE form methods are now supported.
Integrated API (Application Programming Interfaces)
- Drag and Drop
- Audio and Video
- Offline Web Applications
- History
- Local Storage
- Geolocation
- Web Messaging
Add Images to Your Website
You can add images to your website by using the img element, and point to a specific image’s URL (“uniform resource locators”) using the src attribute.
An example of this would be:
<img></img>
Note that img elements are self-closing.
All img elements must have an alt attribute. The text inside an alt attribute is used for screen readers to improve accessibility and is displayed if the image fails to load.
Note: If the image is purely decorative, using an empty alt attribute is a best practice.
Ideally the alt attribute should not contain special characters unless needed.
Let’s add an alt attribute to our img example above:
<img></img>
Loading images takes time. Using large images can slow down your page, so use them with care.
By default, the <img></img> element uses the inherit dimensions of its image file.
The width attribute sets an explicit dimension for the image. There’s a corresponding height attribute, as well. Setting only one of them will cause the image to scale proportionally, while defining both will stretch the image. Dimension values are specified in pixels, and you should never include a unit (e.g., width=’75px’ would be incorrect).
The width and height attributes can be useful, but it’s usually better to set image dimensions with CSS so you can alter them with media queries.
Link to External Pages with Anchor Elements
You can use a (anchor) elements to link to content outside of your web page.
a elements need a destination web address called an href attribute*. They also need anchor text. Here’s an example:
<a>this links to freecodecamp.org</a>
Then your browser will display the text this links to freecodecamp.org as a link you can click. And that link will take you to the web address https://www.freecodecamp.org.
Note: Links can be either absolute or relative.
- In the same way that an element adds meaning to the content it contains, an HTML “attribute” adds meaning to the element it’s attached to.
The “value” of the attribute in either single or double quotation marks.
Link to Internal Sections of a Page with Anchor Elements
a (anchor) elements can also be used to create internal links to jump to different sections within a webpage.
To create an internal link, you assign a link’s href attribute to a hash symbol # plus the value of the id attribute for the element that you want to internally link to, usually further down the page. You then need to add the same id attribute to the element you are linking to. An id is an attribute that uniquely describes an element.
Below is an example of an internal anchor link and its target element:
<a>Contacts</a>
…
<h2>Contacts</h2>
When users click the Contacts link, they’ll be taken to the section of the webpage with the Contacts header element.
Note: the target=”_blank” attribute in the anchor tag causes the linked document to open in a new window tab. A visited link is underlined and purple.
By default, most browsers replace the current page with the new one.
Nest an Anchor Element within a Paragraph
You can nest links within other text elements.
<p>
Here's a <a> link to www.freecodecamp.org</a> for you to follow.
</p>
Let’s break down the example. Normal text is wrapped in the p element:
<p> Here's a ... for you to follow. </p>
Next is the anchor element <a> (which requires a closing tag </a>):
<a> … </a>
target is an anchor tag attribute that specifies where to open the link. The value _blank specifies to open the link in a new tab. The href is an anchor tag attribute that contains the URL address of the link:
<a> … </a>
The text, link to www.freecodecamp.org, within the a element is called anchor text, and will display the link to click:
<a>link to freecodecamp.org</a>
The final output of the example will look like this:
Here’s a link to www.freecodecamp.org for you to follow.
Make Dead Links Using the Hash Symbol
Sometimes you want to add a elements to your website before you know where they will link.
This is also handy when you’re changing the behavior of a link using JavaScript, which we’ll learn about later.
Turn an Image into a Link
You can make elements into links by nesting them within an a element.
Nest your image within an a element. Here’s an example:
<a><img></img></a>
Remember to use # as your a element’s href property in order to turn it into a dead link.
Create a Bulleted Unordered List
HTML has a special element for creating unordered lists, or bullet point style lists.
Unordered lists start with an opening <ul> element, followed by any number of <li> elements. Finally, unordered lists close with a </li></ul>.
For example:
<ul><li>milk</li><li>cheese</li></ul>
would create a bullet point style list of milk and cheese.
The HTML specification defines strict rules about what elements can go inside other elements. In this case, <ul> elements should only contain <li> elements, which means you should never ever write something like this:
<ul><p>Add a "ul" element (it stands for unordered list)</p> </ul>
Instead, you should wrap that paragraph with </li><li> tags:
<ul><li><p>Add a "ul" element (it stands for unordered list)</p></li></ul>
</li></ul>
Create an Ordered List
HTML has another special element for creating ordered lists, or numbered lists.
Ordered lists start with an opening <ol> element, followed by any number of <li> elements. Finally, ordered lists are closed with the </li></ol> tag.
For example:
<ol><li>Garfield</li><li>Sylvester</li></ol>
would create a numbered list of Garfield and Sylvester.
Step-by-step procedures like recipes, instructions, and even tables of contents are good candidates for ordered lists, while <ul> lists are better for representing item inventories, product features, pro/con comparisons, and navigational menus.</ul>
Create a Text Field
Now let’s create a web form.
input elements are a convenient way to get input from your user.
You can create a text input like this:
Note that input elements are self-closing.