Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

გავეცნოთ HTML-ს

This translation is incomplete. Please help translate this article from English.

სანამ დაიწყებთ

იმისათვის რომ აითვისოთ ეს მასალა თქვენ უკვე უნდა იცოდეთ რა არის  ბრაუზერი.

თუ თქვენ ასევე შეგიძლიათ ტექსტურ ფაილებთან მუშაობა, შეგიძლიათ გამოსცადოთ სტატიაში ნაჩვენები მაგალითები.

When you look at a web page in a web browser, you see, at the simplest level, words. These words usually have some style characteristics, such as different fonts, font sizes and colors. In many cases a page also displays images or maybe video. Sometimes there is a form where you can enter (or search) for information, or customize the display of the page to your liking. Often a page contains content that moves or changes while the rest of the page remains the same.

რამოდენიმე ტექნოლოგია (როგორებიცაა CSS, JavaScript, Flash, AJAX, JSON) შეიძლება იქნას გამოყენებული რომ შექმნათ ვებ გვერდის კომპონენტი. მაგრამ, ყველაზე მარტივ დონეზე, ვებ გვერდი არის HTML (HyperText Markup Language). HTML-ის გარეშე, არ არსებობს ვებ გვერდი. HTML ეს არის პლატფორმა რომელზეც დაშენებულია ყველა სხვა ვებ ტექნოლოგია, მსოფლიო სტანდარტი რომელიც შეიქმნა და ვითარდება  World Wide Web Consortium (W3C)-ის და Web Hypertext Application Technology Working Group (WHATWG)-ის მიერ. WHATWG მიიჩნევს HTML-ს "ცოცხალ სტანდარტად" რომელიც მუდმივად ვითარდება, whereas the W3C works on both "snapshots" of HTML, the most current of which is HTML5 and on the evolution of HTML (HTML 5.1).

The HTML specification defines a single language that can be written using the relaxed HTML syntax, but also the more strict XML (Extensible Markup Language) one, and also addresses the needs of web applications. HTML does not describe the style and formatting of content, but only the content itself and its meaning.

The creator of a web page can use CSS  to define the appearance and layout of texts and other materials. Current best practices in web development encourage the use of CSS rather than explicit presentational HTML.

This article provides an introduction to HTML. If you've ever wondered what goes on behind the scenes in your web browser, this article is the place to start learning.

A brief history of HTML

In the late 1980s, Tim Berners-Lee was working as a physicist at CERN (the European Organization for Nuclear Research). He devised a way for scientists to share documents over the internet. Prior to his invention, communication via the internet was limited to plain text, using technologies such as email, FTP (File Transfer Protocol), and Usenet-based discussion boards. The invention of HTML made use of a model of content stored on a central server that could be transferred and displayed on a local workstation via a browser. It simplified access to content and enabled the display of "rich" content (such as sophisticated text formatting and the display of images).

რა არის HTML-ი?

HTML-ი არის მარკირების ენა. ის ეუბნება ბრაუზერს რა კონტენტი გამოიტანოს. HTML გამოყოფს "კონტენტს" (ტექსტს, ფოტოებს, აუდიო, ვიდეო, და ...) "პრეზენტაციისგან" (განმარტება რა ტიპისაა კონტენტი და ინსტრუქცია როგორ უნდა გამოჩნდეს). HTML-ი იყენებს წინასწარ დადგენილ ელემენტებს კონტენტის ტიპის აღწერისათვის. ელემენტი შეიცავს ერთ ან მეტ "ტეგს" რომელიც შეიცავს ან გამოხატავს კონტენტს. ტეგები არის ჩასმული წვეტიან ფრჩხილებში, და "დამხურავი" ტეგი (რომელიც მიანიშნებს კონტენტის დასასრულს) იწყება დახრილი ხაზით.

მაგალითად, პარაგრაფი შეიცავს გაზსნის ტეგს "<p>" და დახურვის ტეგს "</p>".  ქვემოთ ნაჩვენებია პარაგრაფის მაგალითი:

<p>შენ დაიწყე HTML-ის შესწავლა.</p>

როცა ეს გამოდის ვებ გვერდზე, გამოიყურება ესე:

ბრაუზერი იყენებს ტეგებს როგორც ინდიკატორს როგორ გამოიტანოს კონტენტი.

ელემენტი რომელიც შეიცავს კონტენტს ასევე შეიძლება შეიცავდეს სხვა ელემენტს. მაგალითად, აქცენტის ელემენტი ("<em>") შეიძლება ჩაისვას პარაგრაფის ელემენტში, რომ დაამატოს აქცენტი სიტყვაზე ან ფრაზაზე:

<p>თქვენ <em>დაიწყეთ</em> HTML-ის შესწავლა.</p>

გამოტანისას გამოიყურება ესე:

Some elements do not contain other elements. For example, the image tag ("<img>") specifies the file name of the content (an image) as an attribute:

<img src="smileyface.jpg" alt="Smiley face" >

Often a forward slash is placed before the final angle bracket to indicate the end tag of an empty element in XHTML (which is an XML schema that implements HTML elements).

The rest of this article goes into greater detail regarding the concepts introduced in this section. However, if you want to see HTML in action, check out Mozilla Thimble, which is an interactive online editor that helps you learn how to write HTML markup. Also, see HTML Elements for a list of available elements and a description of their use.

Elements — the basic building blocks

HTML consists of a set of elements. Elements define the semantic meaning of their content. Elements include everything between two matching element tags, including the tags themselves. For example, the "<p>" element indicates a paragraph; the "<img>" element indicates an image. See the HTML Elements page for a complete list.

Some elements have very precise meaning, as in "this is an image", "this is a heading", or "this is an ordered list." Others are less specific, such as "this is a section on the page" or "this is part of the text." Yet others are used for technical reasons, such as "this is identifying information for the page that should not be displayed." Regardless, in one way or another all HTML elements have a semantic value.

Most elements may contain other elements, forming a hierarchic structure. A very simple but complete web page looks like this:

<html>
  <body>
    <p> you are in your beginning stage of HTML</p>
  </body>
</html>

As you can see, the <html> element surround the rest of the document, and the <body> element surround the page content. This structure is often thought of as a tree with branches (in this case, the <body> and <p> elements) growing from the trunk (<html>). This hierarchical structure is called the DOM: the Document Object Model.

Tags

HTML documents are written in plain text. They can be written in any text editor that allows content to be saved as plain text, such as Notepad, Notepad++, or Sublime,  but most HTML authors prefer to use a specialized editor that highlights syntax and shows the DOM. Tag names may be written in either upper or lower case. However, the W3C (the global consortium that maintains the HTML standard) recommends using lower case (and XHTML requires lower case).

HTML attaches special meaning to anything that starts with the less-than sign ("<") and ends with the greater-than sign (">"). Such markup is called a tag. Make sure to close the tag, as some tags are closed by default, whereas others might produce unexpected errors if you forget the end tag. 

Here is a simple example:

<p>This is text within a paragraph.</p>

In this example there is a start tag and a closing tag. Closing tags are the same as the start tag but also contain a forward slash immediately after the leading less-than sign. Most elements in HTML are written using both start and closing tags. Start and closing tags should be properly nested--that is, closing tags should be written in the opposite order of the start tags. Proper nesting is one rule that must be obeyed in order to write valid code.

This is an an example of valid code:

<em>I <strong>really</strong> mean that</em>.

This is an example of invalid code:

Invalid: <em>I <strong>really</em> mean that</strong>.

Note that in the valid example, the closing tag for the nested element is placed before the closing tag for the element in which it is nested. In the invalid code, they are nested.

Until the adoption of the HTML5 parsing rules, browsers didn't interpret invalid code in the same way and produced different results when they encountered invalid code. Browsers were forgiving to Web authors, but unfortunately not all in the same way, resulting in almost unpredictable results in case of invalid HTML. These days are over with the latest evolution of browsers, like Internet Explorer 10, Firefox 4, Opera 11.60, Chrome 18, or Safari 5, as they implement the now-standard invalid-code-parsing rules. Invalid code results in the same DOM tree on all modern browsers.

Some elements do not contain any text content or any other elements. These are empty elements and need no closing tag. This is an example:

<img src="smileyface.jpg" alt="Smiley face" >

Empty elements in XHTML mode are usually closed using a trailing forward slash.

<img src="smileyface.jpg" alt="Smiley face" />

In HTML this slash has a meaning that is not implemented in Firefox so it should not be used.  Empty elements must not be closed in HTML mode.

Attributes

The start tag may contain additional information, as in the preceding example. Such information is called an attribute. Attributes usually consist of 2 parts:

  • An attribute name
  • An attribute value

A few attributes can only have one value. They are Boolean attributes and may be shortened by only specifying the attribute name or leaving the attribute value empty. Thus, the following 3 examples have the same meaning:

<input required="required">

<input required="">

<input required>

Attribute values that consist of a single word or number may be written as they are, but as soon as there are two or more strings of characters in the value, it must be written within quotation marks. Both single quotes (') and double quotes (") are allowed. Many developers prefer to always use quotes to make the code less ambiguous to the eye and to avoid mistakes. The following is such a mistake:

<p class=foo bar> (Beware, this probably does not mean what you think it means.)

In this example the value was supposed to be "foo bar" but since there were no quotes the code is interpreted as if it had been written like this:

<p class="foo" bar="">

Named character references

Named character references (often casually called entities) are used to print characters that have a special meaning in HTML. For example, HTML interprets the less-than and greater-than symbols as tag delimiters. When you want to display a greater-than symbol in the text, you can use a named character reference. There are four common named character references one must know:

  • &gt; denotes the greater than sign (>)
  • &lt; denotes the less than sign (<)
  • &amp; denotes the ampersand (&)
  • &quot; denotes double quote (")

There are many more entities, but these four are the most important because they represent characters that have a special meaning in HTML.

Doctype and comments

In addition to tags, text content, and entities, an HTML document must contain a doctype declaration as the first line. 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, doctype refers to a DTD (Document Type Definition) as it was based on SGML. There are three different doctype declarations in HTML 4.01.

HTML 4.01 Strict

This DTD contains all HTML elements and attributes, but does NOT INCLUDE presentational or deprecated elements (like font). Framesets are not allowed.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR/html4/strict.dtd">

HTML 4.01 Transitional

This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font). Framesets are not allowed.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "https://www.w3.org/TR/html4/loose.dtd">

HTML 4.01 Frameset

This DTD is equal to HTML 4.01 Transitional, but allows the use of frameset content.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "https://www.w3.org/TR/html4/frameset.dtd">

In HTML 5, there is only one declaration and is written like this:

<!DOCTYPE html>

The doctype has a long and intricate history, but for now all you need to know is that this doctype tells the browser to interpret the HTML and CSS code according to W3C standards and not try to pretend that it is Internet Explorer from the 90's. (See quirks mode.)

HTML has a mechanism for embedding comments that are not displayed when the page is rendered in a browser. This is useful for explaining a section of markup, or leaving notes for other people who might work on the page, or for leaving reminders for yourself. HTML comments are enclosed in symbols as follows:

<!-- This is comment text -->

A complete but small document

Putting this together, here is a tiny example of an HTML document. You can copy this code to a text editor, save it as myfirstdoc.html, and load it in a browser. Make sure you are saving it using the character encoding UTF-8. Since this document uses no styling it will look very plain, but it is only a small start.

<!DOCTYPE html>
<html lang="en">
<head>
  <title>A RMScreenprint</title>
</head>
<body>
  <h1>Main heading in my document</h1>
  <!-- Note that it is "h" + "1", not "h" + the letters "one" -->
  <p>Look Ma, I am coding <abbr title="Hyper Text Markup Language">HTML</abbr>.</p>
</body>
</html>

Document Tags and Contributors

 Contributors to this page: cotne95
 Last updated by: cotne95,