Documente Academic
Documente Profesional
Documente Cultură
HTML stands for Hyper Text Markup Language HTML is a markup language A markup language is a set of markup tags The tags describe document content HTML documents contain HTML tags and plain text HTML documents are also called web pages
HTML Tags
HTML markup tags are usually called HTML tags
HTML tags are keywords (tag names) surrounded by angle brackets like <html> HTML tags normally come in pairs like <b> and </b> 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, with a forward slash before the tag name Start and end tags are also called opening tags and closing tags
An HTML element starts with a start tag / opening tag An HTML element ends with an end tag / closing tag The element content is everything between the start and the end tag Some HTML elements have empty content Empty elements are closed in the start tag Most HTML elements can have attributes
HTML Versions
Since the early days of the web, there have been many versions of HTML: Version HTML HTML+ HTML 2.0 HTML 3.2 HTML 4.01 XHTML 1.0 HTML5 XHTML5 Year 1991 1993 1995 1997 1999 2000 2012 2013
Web Browsers
The purpose of a web browser (such as Google Chrome, Internet Explorer, Firefox, Safari) is to read HTML documents and display them as web pages. The browser does not display the HTML tags, but uses the tags to interpret the content of the page:
HTML Editors
HTML can be edited by using a professional HTML editor like:
Adobe Dreamweaver Visual Studio Microsoft Expression Web CoffeeCup HTML Editor
However, for learning HTML we can also use a simple text editor like Notepad (PC) or TextEdit (Mac). Using a simple text editor is a good way to learn HTML. Follow the 4 steps below to create your first web page with Notepad.
Accessories Notepad
Tip: Always add the <!DOCTYPE> declaration to your HTML documents, so that the browser knows what type of document to expect. There are many different documents on the web, and a browser can only display an HTML page 100% correctly if it knows the HTML type and version used.
Common Declarations
HTML5 <!DOCTYPE html> HTML 4.01 Transitional <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 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" "http://www.w3.org/TR/html4/strict.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" "http://www.w3.org/TR/html4/frameset.dtd">
XHTML 1.0 Transitional <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> XHTML 1.0 Frameset This DTD is equal to XHTML 1.0 Transitional, but allows the use of frameset content. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> XHTML 1.0 Strict This DTD contains all HTML elements and attributes, but does NOT INCLUDE presentational or deprecated elements (like font). Framesets are not allowed. The markup must also be written as wellformed XML. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> XHTML 1.1
This DTD is equal to XHTML 1.0 Strict, but allows you to add modules (for example to provide ruby support for East-Asian languages).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
HTML Tags
Tag <html> <body> <h1> to <h6> <hr> <!--> Description Defines an HTML document Defines the document's body Defines HTML headings Defines a horizontal line Defines a comment
<br>
Often <strong> renders as <b>, and <em> renders as <i>. However, there is a difference in the meaning of these tags: <b> or <i> defines bold or italic text only. <strong> or <em> means that you want the text to be rendered in a way that the user understands as "important". Today, all major browsers render strong as bold and em as italics. However, if a browser one day wants to make a text highlighted with the strong feature, it might be cursive for example and not bold!
HTML Headings
HTML headings are defined with the <h1> to <h6> tags.
Example
<h1>This is a heading</h1> <h2>This is a heading</h2> <h3>This is a heading</h3> <h4> This is a heading </h4> <h5> This is a heading </h5> <h6> This is a heading </h6>
HTML Paragraphs
HTML paragraphs are defined with the <p> tag.
HTML Body
The <body> element defines the body of the HTML document.
HTML Links(hyperlinks)
HTML links are defined with the <a> tag. A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another document. The most important attribute of the <a> element is the href attribute, which indicates the links destination. When you move the cursor over a link in a Web page, the arrow will turn into a little hand.
An unvisited link is underlined and blue A visited link is underlined and purple An active link is underlined and red
The target attribute specifies where to open the linked document. The example below will open the linked document in a new browser window or a new tab:
<a href="http://www.w3schools.com/" target="_blank">Visit W3Schools!</a> The example below will open the linked document in the current window:
Example
<a href="http://www.w3schools.com">This is a link</a>
HTML Images
HTML images are defined with the <img> tag.
Example
<img src="w3schools.jpg" width="104" height="142">
Defines smaller text Defines important text Defines subscripted text Defines superscripted text Defines inserted text Defines deleted text
HTML Forms
HTML forms are used to pass data to a server. An HTML form can contain input elements like text fields, checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea, fieldset, legend, and label elements. An HTML form is define by <form> </form> tag pair. An action attribute on the <form> tag gives the URL of the application that is to receive and process the forms data, i.e., where to send the inputs. A method attribute specifies how the browser will return the users inputs to the server. Example:
GET vs POST
method="get" Appends name/value pairs for inputs to the URL. Visible to the user. Normally used for small amounts of data. method="post" Embeds name/value pairs for inputs in the HTTP Request message. Not visible to the user. OK for larger amounts of data. Either method is OK for the web app on the server.
Text Fields
<input type="text"> defines a one-line input field that a user can enter text into: <form> First name: <input type="text" name="firstname"><br> Last name: <input type="text" name="lastname"> </form>
Note: The form itself is not visible. Also note that the default width of a text field is 20 characters.
Password Field
<input type="password"> defines a password field:
Radio Buttons
<input type="radio"> defines a radio button. Radio buttons let a user select ONLY ONE of a limited number of choices: <form> <input type="radio" name="sex" value="male">Male<br> <input type="radio" name="sex" value="female">Female </form> How the HTML code above looks in a browser: Male Female
Checkboxes
<input type="checkbox"> defines a checkbox. Checkboxes let a user select ZERO or MORE options of a limited number of choices. <form> <input type="checkbox" name="vehicle" value="Bike">I have a bike<br> <input type="checkbox" name="vehicle" value="Car">I have a car </form> How the HTML code above looks in a browser: I have a bike I have a car
Submit Button
<input type="submit"> defines a submit button. A submit button is used to send form data to a server. The data is sent to the page specified in the form's action attribute. The file defined in the action attribute usually does something with the received input:
<form name="input" action="html_form_action.asp" method="get"> Username: <input type="text" name="user"> <input type="submit" value="Submit"> </form> How the HTML code above looks in a browser: Username: If you type some characters in the text field above, and click the "Submit" button, the browser will send your input to a page called "html_form_action.asp". The page will show you the received input.
Example of a drop down list: <!DOCTYPE html> <html> <body> <form action=""> <select name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select>
</form> </body> </html> Example of a radio button: <!DOCTYPE html> <html> <body> <form action=""> <input type="radio" name="gender" value="male">Male<br> <input type="radio" name="gender" value="female">Female </form> <p><b>Note:</b> When a user clicks on a radio-button, it becomes checked, and all other radiobuttons with equal name become unchecked.</p> </body> </html> <!DOCTYPE html> <html> <body>
Submit button: <form name="input" action="html_form_action.asp" method="get"> First name: <input type="text" name="FirstName" value="Mickey"><br> Last name: <input type="text" name="LastName" value="Mouse"><br> <input type="submit" value="Submit"> </form> <p>If you click the "Submit" button, the form-data will be sent to a page called "html_form_action.asp".</p> </body> </html> file:///C:/Documents%20and%20Settings/owner/My%20Documents/my %20html/html_form_action.htm? FirstName=Mickey&LastName=Mouse&pwd=hello&cars=volvo&gender=male if method=post
file:///C:/Documents%20and%20Settings/owner/My%20Documents/my %20html/html_form_action.htm
span and div signify no specific meaning besides the generic grouping of content,
and are therefore more appropriate for creating organization or stylistic additions without signifying superfluous meaning.
div
There is one difference between div and span. In standard HTML, a div is a block-level element whereas a span is an inline element. The div block visually isolates a section of a document on the page, in the same way as a paragraph. The span element contains a piece of information inline with the surrounding text. In practice, even this feature can be changed by the use of Cascading Style Sheets (CSS). This means that to use them semantically, divs should be used to wrap sections of a document, while spans should be used to wrap small portions of text, images, etc.
span
and div elements are used purely to imply a logical grouping of enclosed elements.
There are three main reasons to use span and div tags with class or id attributes:
Styling with CSS See also: Cascading Style Sheets and Separation of presentation and content
Perhaps the most common use of span and div elements is to carry class or id attributes in conjunction with CSS to apply layout, typographic, color, and other presentation attributes to parts of the content. CSS does not just apply to visual styling: when spoken out loud by a voice browser, CSS styling can affect speech-rate, stress, richness and even position within a stereophonic image. For these reasons, and for compatibility with the concepts of the semantic web, discussed below, attributes attached to elements within any HTML should describe their semantic purpose, rather than merely their intended display properties in one particular medium. For example, the HTML in <span class="red small">password too short</span> denotes no more meaning than any other text, whereas <em class="warning">password too short</em> uses an em element to signify that the text requires emphasis, and uses a more appropriate class name. Perhaps when spoken they should be given extra stress, and a small reduction in speech-rate. The second example is semantically correct markup, rather than merely presentational.
Semantic clarity
This kind of grouping and labeling of parts of the page content might be introduced purely to make the page more semantically meaningful in general terms. It is impossible to say how and in what ways the World Wide Web will develop in years and decades to come. Web pages designed today may still be in use when information systems that we cannot yet imagine are trawling, processing, and classifying the web. Even today's search engines such as Google and others use proprietary information processing algorithms of considerable complexity.
For some years, the World Wide Web Consortium (W3C) has been running a major Semantic Web project designed to make the whole web increasingly useful and meaningful to today's and the future's information systems. The microformats movement is an attempt to build an idea of semantic classes. For example, microformats-aware software might automatically find an element like <span class="tel">123-456-7890</span> and allow for automatic dialing of the telephone number.
Access from code
Once the HTML or XHTML markup is delivered to a page-visitor's client browser, there is a chance that client-side code will need to navigate the internal structure (or Document Object Model) of the web page. The most common reason for this is that the page is delivered with client-side JavaScript that will produce on-going dynamic behavior after the page is rendered. For example, if rolling the mouse over a 'Buy now' link is meant to make the price, elsewhere on the page, become emphasized, JavaScript code can do this, but JavaScript needs to identify the price element, wherever it is in the markup, in order to affect it. The following markup would suffice: <div id="price">$45.99</div>. Another example is the Ajax programming technique, where, for example, clicking a hypertext link may cause JavaScript code to retrieve the text for a new price quotation to display in place of the current one within the page, without re-loading the whole page. When the new text arrives back from the server, the JavaScript must identify the exact region on the page to replace with the new information. Less common, but just as important examples of code gaining access to final web pages, and having to use span and div elements' class or id attributes to navigate within the page include the use of automatic testing tools. On dynamically generated HTML, this may include the use of automatic page testing tools such as HttpUnit, a member of the xUnit family, and load or stress testing tools such as Apache JMeter when applied to form-driven web sites.
Overuse
The judicious use of div and span is a vital part of HTML and XHTML markup. However, they are sometimes overused.
<div>This a large main division, with <span>a small bit</span> of spanned text!</div>
Note that it is illegal to place a block level element within an inline element, so:
<div>Some <span>text that <div>I want</div> to mark</span> up</div>
...is illegal.
<div id="header"> <div id="userbar"> Hi there, <span class="username">Chris Marasti-Georg</span> | <a href="/edit-profile.html">Profile</a> | <a href="http://www.bowlsk.com/_ah/logout?...">Sign out</a> </div> <h1><a href="/">Bowl<span class="sk">SK</span></a></h1> </div>
BowlSK
Styles/Sections
<style type="text/css"> h1 {color:red;} p {color:blue;} </style> <div>A block-level section in a document</div> <span>An inline section in a document</span>
CSS Syntax:
This syntax has two parts, the selector and the declaration. Selector: Specifies the target of styling. Declaration: Specifies the property and value. Declaration is contained between {" ... "}. Declaration end with a semicolon. p{ color: red; }
Selectors are specify the target of styling. Selectors may range from simple element names to rich contextual representations. Kinds of selector: Type selector Class selector ID selector Grouping A type selector is the name of HTML Tag. Example: [index.html] <p>This is a paragraph</p> <p>This is a paragraph</p> <p>This is a paragraph</p> [style.css] p{ color: red; font-size: 12px; } Class selector is used for one or more elements. It is described the value of class attribute of HTML document with ".(period)" [index.html] <p class="red">This is a paragraph</p> <p class="blue">This is a paragraph</p> <p class="red">This is a paragraph</p> [style.css] p{ font-size: 12px; } .red{ color: red; } .blue{ color: blue; }
ID selector is used for unique element. It is described the value of ID attribute of HTML document with "#" [index.html] <p class="red">This is a paragraph</p> <p class="blue">This is a paragraph</p> <p class="red" id="small">This is a paragraph</p> [style.css] p{ font-size: 12px; } .red{ color: red; } .blue{ color: blue; } #small{ font-size: 9px; } Grouping: A comma-separated list of selectors represents the union of all elements selected by each of the individual selectors in the list [index.html] <h1>This is a heading</h1> <h2>This is a heading</h2> <h3>This is a heading</h3> <h4>This is a heading</h4> [style.css] h1, h2, h3, h4{ color: red; font-size: 12px; }
<link rel="stylesheet" type="text/css" href="example.css"> </head> [example.css] p{ color: red; foto-size: 120%; }
You can put style sheet rules in the head of the document by <style>. [example.html] <head> <style> p { color: red; font-size:120%; } </style> </head> <body> <p>This is a paragraph</p> </body>
The start tags can contain style sheet rules directly in HTML documents by the style attribute. [example.html] <p style="color: red; font-size:120%; "> This is a paragraph</p>
Example
<script> document.write("Hello World!") </script>
Example
<script> document.write("Hello World!") </script> <noscript>Sorry, your browser does not support JavaScript!</noscript>
Sound in HTML
We can add sound to an HTML page very much like we add images. Add to image_example.html: <embed src="hello.wav" autostart="true" loop="false"> </embed>
HTML Entities
Some characters are reserved in HTML. It is not possible to use the less than (<) or greater than (>) signs in your text, because the browser will mix them with tags. To actually display reserved characters, we must use character entities in the HTML source code. A character entity looks like this:
What Is XHTML?
XHTML stands for EXtensible HyperText Markup Language XHTML is almost identical to HTML 4.01 XHTML is a stricter and cleaner version of HTML 4.01 XHTML is HTML defined as an XML application XHTML is supported by all major browsers.
Why XHTML?
Many pages on the internet contain "bad" HTML. The following HTML code will work fine if you view it in a browser (even if it does NOT follow the HTML rules):
<html> <head> <title>This is bad HTML</title> <body> <h1>Bad HTML <p>This is a paragraph </body>
XML is a markup language where documents must be marked up correctly and "well-formed". If you want to study XML, please read our XML tutorial. Today's market consists of different browser technologies. Some browsers run on computers, and some browsers run on mobile phones or other small devices. Smaller devices often lack the resources or power to interpret a "bad" markup language. Therefore - by combining the strengths of HTML and XML, XHTML was developed. XHTML is HTML redesigned as XML.
XHTML Elements XHTML elements must be properly nested XHTML elements must always be closed
XHTML elements must be in lowercase XHTML documents must have one root element
XHTML Attributes Attribute names must be in lower case Attribute values must be quoted
In XHTML, all elements must be properly nested within each other, like this:
<b><i>This text is bold and italic</i></b>
This is correct:
<p>This is a paragraph</p> <p>This is another paragraph</p>
This is correct:
A break: <br /> A horizontal rule: <hr /> An image: <img src="happy.gif" alt="Happy face" />
This is correct:
<body> <p>This is a paragraph</p> </body>
This is correct:
<table width="100%">
This is correct:
<table width="100%">
This is wrong:
<input checked> <input readonly> <input disabled> <option selected>
This is correct:
<input checked="checked"> <input readonly="readonly"> <input disabled="disabled"> <option selected="selected">
********************************