HTML Intro
HTML Intro
What is HTML?
HTML is the standard markup language for creating Web pages.
• HTML stands for Hyper Text Markup Language
• HTML describes the structure of Web pages using markup
• HTML elements are the building blocks of HTML pages
• HTML elements are represented by tags
• HTML tags label pieces of content such as "heading", "paragraph", "table", and so on
• Browsers do not display the HTML tags, but use them to render the content of the page
HTML Versions
Since the early days of the web, there have been many versions of HTML:
VERSION YEAR
XHTML 2000
HTML5 2014
Example Explained
• The <!DOCTYPE html> declaration defines this document to be HTML5
• The <html> element is the root element of an HTML page
• The <head> element contains meta information about the document
• The <title> element specifies a title for the document
• The <body> element contains the visible page content
• The <h1> element defines a large heading
• The <p> element defines a paragraph
HTML Document
• All HTML documents must start with a document type declaration: <!
DOCTYPE html>.
• Element <!DOCTYPE> is intended to indicate the type of the document - DTD
(document type definition), for the browser to know how to parse the page.
• The <!DOCTYPE> declaration is not an HTML tag, it is an instruction to the web
browser about what version of HTML the page is written in.
• The HTML document itself begins with <html> and ends with </html>.
• The visible part of the HTML document is between <body> and </body>.
Tags
Opening and closing tags
<tag>Some text</tag>
<tag />
<first-tag>
<second-tag>Some text</second-tag>
</first-tag>
Comments:
<!-- Comment content -->
HTML Introduction
• Headings
<h1>, <h2>, <h3>, <h4>, <h5>, <h6>
• Example:
<tag attribute1="value" attribute2="value"> ... </tag>
• Extend the capabilities of individual tags. The order of the attributes doesn’t matter.
• Examples: id, class, name, title, style, src, type
• All HTML elements can have attributes
• Attributes provide additional information about an element
• Attributes are always specified in the start tag
• Attributes usually come in name/value pairs like: name="value“
Example: title attribute is an optional tooltip (on ANY element)
HTML Images
• HTML images are defined with the <img> tag.
• The source file (src), alternative text (alt), width, and height are provided as attributes:
Example
<img src=“image.jpg" alt=“CVR logo" width="104" height="142">
• The src attribute specifies the image URL
• If the browser is unable to fetch the image, it will show the alt text
• If placed in an a anchor, the image becomes a link
• Other attributes are width and height: their value can be given as pixels or percentage of
window.
• If not used, the image will be shown in its actual size
• Images
<img src="img/picture.png" alt="Alt text" />
• Links
<a href="https://www.google.com/">Go to Google</a>
• <br> is an empty element without a closing tag (the <br> tag defines a line break).
• Empty elements can be "closed" in the opening tag like this: <br />.
• HTML5 does not require empty elements to be closed. But if you want stricter validation, or
if you need to make your document readable by XML parsers, you must close all HTML
elements properly.
The title Attribute
• Here, a title attribute is added to the <p> element. The value of the title attribute will be
displayed as a tooltip when you mouse over the paragraph:
Example
<p title="I'm a tooltip">This is a paragraph.</p>
• The font-size property defines the text size for an HTML element:
Example
<h1 style="font-size:60px;">Heading 1</h1>
<h1 style="font-size:300%;">This is a heading</h1>
<p style="font-size:160%;">This is a paragraph.</p>
HTML Background Color
• The background-color property defines the background color for an HTML element.
• This example sets the background color for a page to powderblue:
Example
<body style="background-color:powderblue;">
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
HTML Text Color
• The color property defines the text color for an HTML element:
Example
<h1 style="color:blue;">This is a heading</h1>
<p style="color:red;">This is a paragraph.</p>
HTML Fonts
• The font-family property defines the font to be used for an HTML element:
Example
<h1 style="font-family:verdana;">This is a heading</h1>
<p style="font-family:courier;">This is a paragraph.</p>
HTML Text Alignment
• The text-align property defines the horizontal text alignment for an HTML
element:
Example
<h1 style="text-align:center;">Centered Heading</h1>
<p style="text-align:center;">Centered paragraph.</p>
• 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:
• HTML also defines special elements for defining text with a special meaning.
• HTML uses elements like <b> and <i> for formatting output, like bold or italic text.
• Formatting elements were designed to display special types of text:
Example
<p><b>This text is bold</b></p>
<p><i>This text is italic</i></p>
<p>This is<sub> subscript</sub> and <sup>superscript</sup></p>
<b> - Bold text
<strong> - Important text
<i> - Italic text
<em> - Emphasized text
HTML Text <mark> - Marked text
Formatting <small> - Small text
<del> - Deleted text
<ins> - Inserted text
<sub> - Subscript text
<sup> - Superscript text
Unordered HTML List - Choose List Item
Marker
• The CSS list-style-type property is used to define the style of the list item marker:
Value Description
Type Description
type="1" The list items will be numbered with numbers (default)
type="A" The list items will be numbered with uppercase letters
type="a" The list items will be numbered with lowercase letters
type="I" The list items will be numbered with uppercase roman numbers
type="i" The list items will be numbered with lowercase roman numbers
HTML Description Lists
HTML also supports description lists
A description list is a list of terms, with a description of each term.
The <dl> tag defines the description list, the <dt> tag defines the term (name), and the
<dd> tag describes each term
Example
<dl>
<dt>HTML</dt>
<dd>Hypertext Markup Language</dd>
<dt>HTTP</dt>
<dd>Hypertext Transfer Protocol</dd>
</dl>