Intro To HTML
Intro To HTML
What is HTML?
• Tags in HTML are not case sensitive. This means they can be written
in uppercase or lowercase. For example, a <title> tag could be written
as <title>, <TITLE>, <Title>, <tITle>, etc., and it will work. However,
it is best practice to write all tags in lowercase for consistency and
readability.
Anatomy of an HTML element
Anatomy of an HTML element
• The opening tag: This consists of the name of the element (in this example, p for
paragraph), wrapped in opening and closing angle brackets. This opening tag
marks where the element begins or starts to take effect. In this example, it
precedes the start of the paragraph text.
• The content: This is the content of the element. In this example, it is the
paragraph text.
• The closing tag: This is the same as the opening tag, except that it includes a
forward slash before the element name. This marks where the element ends.
Failing to include a closing tag is a common beginner error that can produce
peculiar results.
Nesting Elements
• Elements can be placed within other elements. This is called nesting. If we
wanted to state that our cat is very grumpy, we could wrap the word very in a
<strong> element, which means that the word is to have strong(er) text
formatting:
<img src="https://raw.githubusercontent.com/mdn/beginner-
html-site/gh-pages/images/firefox-icon.png"
alt="Firefox icon" />
Attributes contain extra information about the element that won't appear in the content. In this example, the class attribute is an identifying name used to target the element with style information.
Attributes
• Attributes contain extra information about the element that won't appear in
the content. In this example, the class attribute is an identifying name used to
target the element with style information.
Attributes contain extra information about the element that won't appear in the content. In this example, the class attribute is an identifying name used to target the element with style information.
Attributes
• Attributes contain extra information about the element that won't appear in
the content. In this example, the class attribute is an identifying name used to
target the element with style information.
Attributes contain extra information about the element that won't appear in the content. In this example, the class attribute is an identifying name used to target the element with style information.
Attributes
• An attribute should have:
A space between it and the element name. (For an element with more than one attribute,
the attributes should be separated by spaces too.)
The attribute name, followed by an equal sign.
An attribute value, wrapped with opening and closing quote marks.
Attributes contain extra information about the element that won't appear in the content. In this example, the class attribute is an identifying name used to target the element with style information.
• Alt - The alt attribute specifies a text description of the image. For example:
alt="The Firefox icon".
• Width - The width attribute specifies the width of the image with the unit being
pixels. For example: width="300".
• Height - The height attribute specifies the height of the image with the unit being
pixels. For example: height="300".
Attributes contain extra information about the element that won't appear in the content. In this example, the class attribute is an identifying name used to target the element with style information.
Boolean attributes
• Boolean attributes can only have one value, which is generally the same as the
attribute name. For example, consider the disabled attribute, which you can
assign to form input elements.
//Shorthand
<input type="text" disabled />
Attributes contain extra information about the element that won't appear in the content. In this example, the class attribute is an identifying name used to target the element with style information.
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>My test page</title>
</head>
<body>
<p>This is my page</p>
</body>
</html>
Attributes contain extra information about the element that won't appear in the content. In this example, the class attribute is an identifying name used to target the element with style information.
Whitespace in HTML
• No matter how much whitespace you use inside HTML element content (which can include one or
more space characters, but also line breaks), the HTML parser reduces each sequence of
whitespace to a single space when rendering the code.
<p id="whitespace">Dogs
are
silly.</p>
HTML comments
• HTML has a mechanism to write comments in the code. Browsers ignore
comments, effectively making comments invisible to the user. The purpose of
comments is to allow you to include notes in the code to explain your logic or
coding.
<meta
name="description"
content="The MDN Web Docs site
provides information about Open Web technologies
including HTML, CSS, and APIs for both websites and
progressive web apps." />
Many <meta> features just aren't used anymore. For example, the keyword <meta> element (<meta
name="keywords" content="fill, in, your, keywords, here">) — which is supposed to provide keywords
for search engines to determine relevance of that page for different search terms — is ignored by
search engines, because spammers were just filling the keyword list with hundreds of keywords,
biasing results.
Other types of metadata
Open Graph Data is a metadata protocol that Facebook invented to provide richer metadata for websites.
<meta
property="og:image"
content="https://developer.mozilla.org/mdn-social-share.png" />
<meta
property="og:description"
content="The Mozilla Developer Network (MDN) provides
information about Open Web technologies including HTML, CSS, and APIs for
both websites and HTML Apps." />
<meta property="og:title" content="Mozilla Developer Network" />
Adding custom icons to your site
The most commonly used of these is the favicon (short for "favorites icon", referring to its use in the
"favorites" or "bookmarks" lists in browsers).
A favicon can be added to your page by:
Saving it in the same directory as the site's index page, saved in .ico format (most also support
favicons in more common formats like .gif or .png)
Adding the following line into your HTML's <head> block to reference it: