Sie sind auf Seite 1von 18

HTML

INTRODUCTION
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.

A Simple HTML Document


Example
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<h1>My First Heading</h1>


<p>My first paragraph.</p>

1
</body>
</html>

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 Tags
HTML tags are element names surrounded by angle brackets.

<tagname>content goes here...</tagname>

HTML tags normally come in pairs like <p> and </p>.

The first tag in a pair is the start tag, the second tag is
the end tag.

The end tag is written like the start tag, but with
a forward slash inserted before the tag name.

The start tag is also called the opening tag, and the end tag
the closing tag.

Web Browsers
The purpose of a web browser (Chrome, IE, Firefox, Safari) is to
read HTML documents and display them.

2
The browser does not display the HTML tags, but uses
them to determine how to display the document.

HTML Page Structure


Below is a visualization of an HTML page structure:

3
The <!DOCTYPE> Declaration
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 HTML is:

<!DOCTYPE html>

4
HTML Editors
Write 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 using a simple text editor is a good way to learn HTML.

Follow the four 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:

Open Start > Programs > Accessories > Notepad

Step 1: Open TextEdit (Mac)


Open Finder > Applications > TextEdit

Also change some preferences to get the application to save files


correctly. In Preferences > Format > choose "Plain Text"

Then under "Open and Save", check the box that says "Ignore rich text
commands in HTML files".

5
Then open a new document to place the code.

Step 2: Write Some HTML


<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>

Step 3: Save the HTML Page


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).

6
You can use either .htm or .html as file extension. There is no
difference, it is up to you.

Step 4: View the HTML Page in Your


Browser
Open the saved HTML file in your favorite browser (double click
on the file, or right-click - and choose "Open with").

The result will look much like this:

7
HTML BASICS
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>.

HTML Headings
HTML headings are defined with the <h1> to <h6> tags.

<h1> defines the most important heading. <h6> defines the


least important heading.

Example :-
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>

HTML Paragraphs
8
HTML paragraphs are defined with the <p> tag.

Example :-
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

HTML Links
HTML links are defined with the <a> tag.

Example :-
<a href="https://www.google.com">This is a
link</a>
The link's destination is specified in the href attribute.

Attributes are used to provide additional information about


HTML elements.

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="google.jpg" alt="W3Schools.com" width="104" height
="142">

9
HTML ELEMENTS
HTML ELEMENTS
An HTML element usually consists of a start tag and end tag,
with the content inserted in between.

<tagname>Content goes here...</tagname>

The HTML element is everything from the start tag to the end
tag.

<p>My first paragraph.</p>


HTML elements with no content are called empty elements.
Empty elements do not have an end tag, such as the <br>
element (which indicates a line break).

Start Element End


Tag Content Tag
<h1> My First Heading. </h1>

10
<p> My first paragraph. </p>
<br>

Nested HTML Elements


HTML elements can be nested (elements can contain
elements).

All HTML documents consist of nested HTML elements.

This example contains four HTML elements:

Example :-
<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>


<p>My first paragraph.</p>

</body>
</html>

Example Explained :
(1) The <html> element defines the whole document.

It has a start tag <html> and an end tag </html>.

The element content is another HTML element (the <body>


element).

(2) The <body> element defines the document body.

11
It has a start tag <body> and an end tag </body>.

The element content is two other HTML elements (<h1> and <p>).

(3) The <h1> element defines a heading.

It has a start tag <h1> and an end tag </h1>.

The element content is: My First Heading.

(4) The <p> element defines a paragraph.

It has a start tag <p> and an end tag </p>.

The element content is: My first paragraph.

Do Not Forget the End Tag


Some HTML elements will display correctly, even if you
forget the end tag.

Example
<html>
<body>

<p>This is a paragraph
<p>This is a paragraph

</body>
</html>

Empty HTML Elements


HTML elements with no content are called empty elements.

<br> is an empty element without a closing tag (the <br> tag


defines a line break).

12
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.

Use Lowercase Tags


HTML tags are not case sensitive: <P> means the same as
<p>.

The HTML5 standard does not require lowercase tags, but


W3C recommends lowercase in HTML,
and demands lowercase for stricter document types like
XHTML.

HTML TAGS
Some HTML Tags are explained below :-

1) <!DOCTYPE>
The <!DOCTYPE> declaration must be the very first thing in
your HTML document, before the <html> tag.

13
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.

In HTML 4.01, the <!DOCTYPE> declaration refers to a DTD,


because HTML 4.01 was based on SGML. The DTD specifies the
rules for the markup language, so that the browsers render the
content correctly.

HTML5 is not based on SGML, and therefore does not require a


reference to a DTD.

Tip: Always add the <!DOCTYPE> declaration to your


HTML documents, so that the browser knows what type
of document to expect.

2) <html> Tag
The <html> tag tells the browser that this is an HTML
document.

The <html> tag represents the root of an HTML document.

The <html> tag is the container for all other HTML elements
(except for the <!DOCTYPE> tag).

3) <head> Tag
The <head> element is a container for all the head elements.

The <head> element can include a title for the


document, scripts, styles, meta information, and more.

The following elements can go inside the <head> element:

<title> (this element is required in an HTML document)

<style>

<base>

14
<link>

<meta>

<script>

<noscript>

4) <title> Tag
The <title> tag is required in all HTML documents and
it defines the title of the document.

The <title> element:

defines a title in the browser toolbar.

provides a title for the page when it is added to


favoriates.

displays a title for the page in search-engine


results.

Note: You can NOT have more than one <title>


element in an HTML document.

Tip: If you omit the <title> tag, the document will


not validate as HTML.

5) <body> Tag
The <body> tag defines the document's body.

The <body> element contains all the contents of an


HTML document, such as text, hyperlinks, images,
tables, lists, etc.

15
6) <h1> to <h6> Tags
The <h1> to <h6> tags are used to define HTML headings.

<h1> defines the most important heading. <h6> defines


the least important heading.

Example:-
The six different HTML headings:

<h1>This is heading 1</h1>


<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>

7) <p> Tag
The <p> tag defines a paragraph.

Browsers automatically add some space (margin) before and


after each <p> element. The margins can be modified with CSS
(with the margin properties).

Example :-
A paragraph is marked up as follows:
<p>This is some text in a paragraph.</p>

16
17
18

Das könnte Ihnen auch gefallen