HTML5 Flashcards
declaration defines that this document is an HTML5 document
declaration defines that this document is an HTML5 document
element is the root element of an HTML page
element contains meta information about the HTML page
element specifies a title for the HTML page (which is shown in the browser’s title bar or in the page’s tab)
element defines the document’s body, and is a container for all the visible contents, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
<h1></h1>
element defines a large heading, can have up to 6, h1, h2, h3, etc each gets smaller, it’s good practice to only use one h1
<p></p>
element defines a paragraph
What is an HTML Element?
An HTML element is defined by a start tag, some content, and an end tag:
Content goes here…
The HTML element is everything from the start tag to the end tag:
Web Browsers
The purpose of a web browser (Chrome, Edge, Firefox, Safari) is to read HTML documents and display them correctly.
A browser does not display the HTML tags, but uses them to determine how to display the document:
<a></a>
HTML links are defined with the <a> tag:</a>
Example
</a><a>This is a link</a>
<img></img>
HTML images are defined with the <img></img> tag.
The source file (src), alternative text (alt), width, and height are provided as attributes:
Example
<img></img>
<br></br>
The <br></br> tag defines a line break, and is an empty element without a closing tag:
HTML is Not Case Sensitive
HTML tags are not case sensitive: <p> means the same as </p><p>.
The HTML standard does not require lowercase tags, but W3C recommends lowercase in HTML, and demands lowercase for stricter document types like XHTML.</p>
HTML Attributes
All HTML elements can have attributes
Attributes provide additional information about elements
Attributes are always specified in the start tag
Attributes usually come in name/value pairs like: name=”value”
The href Attribute
The <a> tag defines a hyperlink. The href attribute specifies the URL of the page the link goes to:</a>
Example
</a><a>Visit W3Schools</a>
The src Attribute
The <img></img> tag is used to embed an image in an HTML page. The src attribute specifies the path to the image to be displayed:
Example
<img></img>
There are two ways to specify the URL in the src attribute:
1. Absolute URL - Links to an external image that is hosted on another website. Example: src=”https://www.w3schools.com/images/img_girl.jpg”.2.
Relative URL - Links to an image that is hosted within the website. Here, the URL does not include the domain name. If the URL begins without a slash, it will be relative to the current page. Example: src=”img_girl.jpg”. If the URL begins with a slash, it will be relative to the domain. Example: src=”/images/img_girl.jpg”.
The width and height Attributes for images
The <img></img> tag should also contain the width and height attributes, which specifies the width and height of the image (in pixels):
Example
<img></img>
The alt Attribute
The required alt attribute for the <img></img> tag specifies an alternate text for an image, if the image for some reason cannot be displayed. This can be due to slow connection, or an error in the src attribute, or if the user uses a screen reader.
Example
<img></img>
The style Attribute
The style attribute is used to add styles to an element, such as color, font, size, and more.
Example
<p>This is a red paragraph.</p>
The lang Attribute
You should always include the lang attribute inside the tag, to declare the language of the Web page. This is meant to assist search engines and browsers.
The following example specifies English as the language:
…
Country codes can also be added to the language code in the lang attribute. So, the first two characters define the language of the HTML page, and the last two characters define the country.
The following example specifies English as the language and United States as the country:
…
The title Attribute
The title attribute defines some extra information about an element.
The value of the title attribute will be displayed as a tooltip when you mouse over the element:
Example
<p>This is a paragraph.</p>
Single or Double Quotes?
Double quotes around attribute values are the most common in HTML, but single quotes can also be used.
In some situations, when the attribute value itself contains double quotes, it is necessary to use single quotes:
<p>
Or vice versa:
</p>
<p></p>
Bigger Headings
Each HTML heading has a default size. However, you can specify the size for any heading with the style attribute, using the CSS font-size property:
Example
<h1>Heading 1</h1>
HTML Horizontal Rules
The <hr> tag defines a thematic break in an HTML page, and is most often displayed as a horizontal rule.
The <hr> element is used to separate content (or define a change) in an HTML page:
Example <h1>This is heading 1</h1> <p>This is some text.</p> <hr> <h2>This is heading 2</h2> <p>This is some other text.</p> <hr>
The <hr> tag is an empty tag, which means that it has no end tag.
HTML Line Breaks
The HTML <br></br> element defines a line break.
Use <br></br> if you want a line break (a new line) without starting a new paragraph:
Example
<p>This is<br></br>a paragraph<br></br>with line breaks.</p>
The <br></br> tag is an empty tag, which means that it has no end tag.
The Poem Problem
This poem will display on a single line:
Example
<p>
My Bonnie lies over the ocean.
My Bonnie lies over the sea.
My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me.
</p>
Solution - The HTML <pre> Element
The HTML <pre> element defines preformatted text.
The text inside a <pre> element is displayed in a fixed-width font (usually Courier), and it preserves both spaces and line breaks:
Example
<pre>
My Bonnie lies over the ocean.
My Bonnie lies over the sea.
My Bonnie lies over the ocean.
Oh, bring back my Bonnie to me.
</pre>
</pre></pre></pre>
HTML Styles
The HTML style attribute is used to add styles to an element, such as color, font, size, and more.
The HTML Style Attribute
Setting the style of an HTML element, can be done with the style attribute.
The HTML style attribute has the following syntax:
Background Color
The CSS background-color property defines the background color for an HTML element
Example
Set the background color for a page to powderblue:
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
Text Color
The CSS color property defines the text color for an HTML element:
Example
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
Fonts
The CSS font-family property defines the font to be used for an HTML element:
Example
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
Text Size
The CSS font-size property defines the text size for an HTML element:
Example
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
Text Alignment
The CSS text-align property defines the horizontal text alignment for an HTML element:
Example
<h1>Centered Heading</h1>
<p>Centered paragraph.</p>
HTML Formatting Elements
Formatting elements were designed to display special types of text:
<b> - Bold text <strong> - Important text <i> - Italic text <em> - Emphasized text - Marked text <small> - Smaller text <del> - Deleted text <ins> - Inserted text <sub> - Subscript text <sup> - Superscript text</sup></sub></ins></del></small></em></i></strong></b>
HTML <b> and <strong> Elements</strong></b>
The HTML <strong> element defines text with strong importance. The content inside is typically displayed in bold.</strong>
</strong>
HTML <i> and <em> Elements</em></i>
The HTML <em> element defines emphasized text. The content inside is typically displayed in italic.</em>
</em>
HTML <small> Element</small>
The HTML <small> element defines smaller text:</small>
HTML Element
The HTML element defines text that should be marked or highlighted:
Example
<p>Do not forget to buy milk today.</p>
HTML <del> Element</del>
The HTML <del> element defines text that has been deleted from a document. Browsers will usually strike a line through deleted text:</del>
Example
<p>My favorite color is <del>blue</del> red.</p>
</del>
HTML <ins> Element</ins>
The HTML <ins> element defines a text that has been inserted into a document. Browsers will usually underline inserted text:</ins>
Example
<p>My favorite color is <del>blue</del> <ins>red</ins>.</p>
</ins>
HTML Element
The HTML element defines subscript text. Subscript text appears half a character below the normal line, and is sometimes rendered in a smaller font. Subscript text can be used for chemical formulas, like H2O:
Example
<p>This is subscripted text.</p>
</sub>
HTML Element
</sup>
The HTML element defines superscript text. Superscript text appears half a character above the normal line, and is sometimes rendered in a smaller font. Superscript text can be used for footnotes, like WWW[1]:
Example
<p>This is superscripted text.</p>
</sup>
HTML <blockquote> for Quotations</blockquote>
The HTML <blockquote> element defines a section that is quoted from another source.
Browsers usually indent <blockquote> elements.
Example
<p>Here is a quote from WWF's website:</p>
<blockquote>
For 50 years, WWF has been protecting the future of nature.
The world's leading conservation organization,
WWF works in 100 countries and is supported by
1.2 million members in the United States and
close to 5 million globally.
</blockquote>
</blockquote></blockquote>
HTML for Short Quotations
The HTML tag defines a short quotation.
Browsers normally insert quotation marks around the quotation.
Example
<p>WWF's goal is to: Build a future where people live in harmony with nature.</p>