What Is HTML
What Is HTML
What is HTML?
Example
Example Explained
An HTML element is defined by a start tag, some content, and an end tag:
The HTML element is everything from the start tag to the end tag:
<h1>My First Heading</h1>
<p>My first paragraph.</p>
Note: Some HTML elements have no content (like the <br> element). These
elements are called empty elements. Empty elements do not have an 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:
View in Browser
HTML Page Structure
Note: The content inside the <body> section will be displayed in a browser. The
content inside the <title> element will be shown in the browser's title bar or in the
page's tab.
HTML History
Since the early days of the World Wide Web, there have been many versions of
HTML:
Year Version
1989 Tim Berners-Lee invented www
1991 Tim Berners-Lee invented HTML
1993 Dave Raggett drafted HTML+
1995 HTML Working Group defined HTML 2.0
1997 W3C Recommendation: HTML 3.2
1999 W3C Recommendation: HTML 4.01
2000 W3C Recommendation: XHTML 1.0
2008 WHATWG HTML5 First Public Draft
2012 WHATWG HTML5 Living Standard
2014 W3C Recommendation: HTML5
2016 W3C Candidate Recommendation: HTML 5.1
2017 W3C Recommendation: HTML5.1 2nd Edition
2017 W3C Recommendation: HTML5.2
HTML Editors
Learn HTML Using Notepad or TextEdit
Web pages can be created and modified by using professional HTML editors.
However, for learning HTML we recommend a simple text editor like Notepad
(PC) or TextEdit (Mac).
We believe that using a simple text editor is a good way to learn HTML.
Follow the steps below to create your first web page with Notepad or TextEdit.
Step 1: Open Notepad (PC)
Windows 8 or later:
Open the Start Screen (the window symbol at the bottom left on your screen).
Type Notepad.
Windows 7 or earlier:
Save the file on your computer. Select File > Save as in the Notepad menu.
Name the file "index.htm" and set the encoding to UTF-8 (which is the preferred
encoding for HTML files).
Open the saved HTML file in your favorite browser (double click on the file, or
right-click - and choose "Open with").
HTML Documents
All HTML documents must start with a document type declaration: <!DOCTYPE
html>.
The HTML document itself begins with <html> and ends with </html>.
The visible part of the HTML document is between <body> and </body>.
The <!DOCTYPE> declaration represents the document type, and helps browsers
to display web pages correctly.
It must only appear once, at the top of the page (before any HTML tags).
The <!DOCTYPE> declaration is not case sensitive.
The <!DOCTYPE> declaration for HTML5 is:
HTML Headings
HTML headings are defined with the <h1> to <h6> tags.
<h1> defines the most important heading. <h6> defines the least important
heading:
HTML Paragraphs
HTML Links
HTML Images
The source file (src), alternative text (alt), width, and height are provided as
attributes:
How to View HTML Source
Have you ever seen a Web page and wondered "Hey! How did they do that?"
HTML Elements
An HTML element is defined by a start tag, some content, and an end tag.
The HTML element is everything from the start tag to the end tag:
Note: Some HTML elements have no content (like the <br> element). These
elements are called empty elements. Empty elements do not have an end tag!
Nested HTML Elements
HTML elements can be nested (this means that elements can contain other
elements).
The following example contains four HTML elements (<html>, <body>, <h1> and
<p>):
Example Explained
The <html> element is the root element and it defines the whole HTML document.
Then, inside the <body> element there are two other elements: <h1> and <p>:
Some HTML elements will display correctly, even if you forget the end tag:
However, never rely on this! Unexpected results and errors may occur if you forget
the end tag!
The <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>.
The HTML standard does not require lowercase tags, but W3C recommends
lowercase in HTML, and demands lowercase for stricter document types like
XHTML.
HTML Attributes
There are two ways to specify the URL in the src attribute:
Notes: External images might be under copyright. If you do not get permission to
use it, you may be in violation of copyright laws. In addition, you cannot control
external images; it can suddenly be removed or changed.
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".
Tip: It is almost always best to use relative URLs. They will not break if you
change domain.
The following
example specifies
English as the
language and United
States as the
country:
The title attribute (and all other attributes) can be written with uppercase or
lowercase like title or TITLE.
We Suggest: Always
Quote (“) Attribute
Values
The HTML standard
does not require quotes
around attribute values.
However, W3C recommends quotes in HTML, and demands quotes for stricter
document types like XHTML.
In some situations, when the attribute value itself contains double quotes, it is
necessary to use single quotes.
Chapter Summary:
HTML headings are titles or subtitles that you want to display on a webpage.
Search engines use the headings to index the structure and content of your web
pages.
Users often skim a page by its headings. It is important to use headings to show the
document structure.
<h1> headings should be used for main headings, followed by <h2> headings, then
the less important <h3>, and so on.
Note: Use HTML headings for headings only. Don't use headings to make text BIG
or bold.
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:
HTML Paragraphs
A paragraph
always starts on a
new line, and
browsers
automatically
add some white
space (a margin)
before and after a
paragraph.
HTML Display
You cannot be sure how
HTML will be displayed.
The <br> tag is an empty tag, which means that it has no end tag.
The Poem Problem
HTML Styles
The HTML
style attribute is
used to add
styles to an
element, such as
color, font, size,
and more.
Setting the style of an HTML element, can be done with the style attribute.
Background Color
Text Color
The CSS color property defines the text color for an HTML element:
Fonts
The CSS font-family property defines the font to be used for an HTML element:
Text Size
The CSS font-size
property defines the text
size for an HTML
element:
Text Alignment
The CSS text-
align property
defines the
horizontal text
alignment for an
HTML element:
Chapter Summary
Use the style attribute for styling HTML elements
Use background-color for background color
Use color for text colors
Use font-family for text fonts
Use font-size for text sizes
Use text-align for text alignment
HTML Text Formatting
Tip: Use the global title attribute to show the description for the
abbreviation/acronym when you mouse over the element.
Notice that there is an exclamation point (!) in the start tag, but not in the end tag.
Note: Comments are not displayed by the browser, but they can help document
your HTML source code.
Add Comments
With comments you can
place notifications and
reminders in your HTML
code.
Hide Content
Comments can be used to
hide content.
This can be helpful if you
hide content temporarily.