What Is HTML?
What Is HTML?
What Is HTML?
With HTML you can create your own Web site. This tutorial teaches you everything about HTML. HTML is easy to learn - You will enjoy it.
Example
<html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html>
What is HTML?
HTML is a language for describing web pages.
HTML stands for Hyper Text Markup Language HTML is not a programming language, it is a markup language A markup language is a set of markup tags HTML uses markup tags to describe web pages
The purpose of a web browser (like Internet Explorer or Firefox) 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:
You don't need an HTML editor You don't need a web server You don't need a web site
Editing HTML
HTML can be written and edited using many different editors like Dreamweaver and Visual Studio. However, in this tutorial we use a plain text editor (like Notepad) to edit HTML. We believe using a plain text editor is the best way to learn HTML.
BASIC HTML
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>
<html> <body>
<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>
</body> </html>
result:This is heading 1
This is heading 2
This is heading 3 This is heading 4 This is heading 5 This is heading 6
HTML Paragraphs
HTML paragraphs are defined with the <p> tag.
Example
<p>This is a paragraph.</p> <p>This is another paragraph.</p>
<html> <body>
</body>
</html>
Result:-
HTML Links
HTML links are defined with the <a> tag.
Example
<a href="http://www.w3schools.com">This is a link</a>
Result:This is a link
Note: The link address is specified in the href attribute.
HTML Images
HTML images are defined with the <img> tag.
Example
<img src="w3schools.jpg" width="104" height="142" />
Result:-
Note: The name and the size of the image are provided as attributes.
HTML Elements
HTML documents are defined by HTML elements.
An HTML element is everything from the start tag to the end tag:-
End tag *
* The start tag is often called the opening tag. The end tag is often called the closing tag.
Tip: You will learn about attributes in the next chapter of this tutorial.
HTML Attributes
HTML elements can have attributes Attributes provide additional information about an element Attributes are always specified in the start tag Attributes come in name/value pairs like: name="value"
Attribute Example
HTML links are defined with the <a> tag. The link address is specified in the href attribute:
Example
<a href="http://www.w3schools.com">This is a link</a>
<applet> <area /> <b> <base /> <basefont /> <bdo> <big> <blockquote> <body> <br /> <button> <caption> <center> <cite> <code> <col /> <colgroup> <dd> <del> <dfn> <dir> <div> <dl>
Deprecated. Defines an embedded applet Defines an area inside an image-map Defines bold text Defines a default address or a default target for all links on a page Deprecated. Defines a default font, color, or size for the text in a page Defines the text direction Defines big text Defines a long quotation Defines the document's body Defines a single line break Defines a push button Defines a table caption Deprecated. Defines centered text Defines a citation Defines computer code text Defines attribute values for one or more columns in a table Defines a group of columns in a table for formatting Defines a description of a term in a definition list Defines deleted text Defines a definition term Deprecated. Defines a directory list Defines a section in a document Defines a definition list
TF STF STF STF TF STF STF STF STF STF STF STF TF STF STF STF STF STF STF STF TF STF STF
<dt> <em> <fieldset> <font> <form> <frame /> <frameset> <h1> to <h6> <head> <hr /> <html> <i> <iframe> <img /> <input /> <ins> <isindex> <kbd> <label> <legend> <li> <link /> <map>
Defines a term (an item) in a definition list Defines emphasized text Defines a border around elements in a form Deprecated. Defines font, color, and size for text Defines an HTML form for user input Defines a window (a frame) in a frameset Defines a set of frames Defines HTML headings Defines information about the document Defines a horizontal line Defines an HTML document Defines italic text Defines an inline frame Defines an image Defines an input control Defines inserted text Deprecated. Defines a searchable index related to a document Defines keyboard text Defines a label for an input element Defines a caption for a fieldset element Defines a list item Defines the relationship between a document and an external resource Defines an image-map
STF STF STF TF STF F F STF STF STF STF STF TF STF STF STF TF STF STF STF STF STF STF
Deprecated. Defines a menu list Defines metadata about an HTML document Defines an alternate content for users that do not support frames Defines an alternate content for users that do not support client-side scripts Defines an embedded object Defines an ordered list Defines a group of related options in a select list Defines an option in a select list Defines a paragraph Defines a parameter for an object Defines preformatted text Defines a short quotation Deprecated. Defines strikethrough text Defines sample computer code Defines a client-side script Defines a select list (drop-down list) Defines small text Defines a section in a document Deprecated. Defines strikethrough text Defines strong text Defines style information for a document Defines subscripted text
TF STF TF STF
<object> <ol> <optgroup> <option> <p> <param /> <pre> <q> <s> <samp> <script> <select> <small> <span> <strike> <strong> <style> <sub>
STF STF STF STF STF STF STF STF TF STF STF STF STF STF TF STF STF STF
<sup> <table> <tbody> <td> <textarea> <tfoot> <th> <thead> <title> <tr> <tt> <u> <ul> <var> <xmp> Tag Basic <!DOCTYPE> <html> <body> <h1> to <h6> <p> <br />
Defines superscripted text Defines a table Groups the body content in a table Defines a cell in a table Defines a multi-line text input control Groups the footer content in a table Defines a header cell in a table Groups the header content in a table Defines the title of a document Defines a row in a table Defines teletype text Deprecated. Defines underlined text Defines an unordered list Defines a variable part of a text Deprecated. Defines preformatted text Description
STF STF STF STF STF STF STF STF STF STF STF TF STF STF
DTD
Defines the document type Defines an HTML document Defines the document's body Defines HTML headings Defines a paragraph Inserts a single line break
<hr /> <!--...--> Formatting <acronym> <abbr> <address> <b> <bdo> <big> <blockquote> <center> <cite> <code> <del> <dfn> <em> <font> <i> <ins> <kbd> <pre> <q> <s>
STF STF
Defines an acronym Defines an abbreviation Defines contact information for the author/owner of a document Defines bold text Defines the text direction Defines big text Defines a long quotation Deprecated. Defines centered text Defines a citation Defines computer code text Defines deleted text Defines a definition term Defines emphasized text Deprecated. Defines font, color, and size for text Defines italic text Defines inserted text Defines keyboard text Defines preformatted text Defines a short quotation Deprecated. Defines strikethrough text
STF STF STF STF STF STF STF TF STF STF STF STF STF TF STF STF STF STF STF TF
<samp> <small> <strike> <strong> <sub> <sup> <tt> <u> <var> <xmp> Forms <form> <input /> <textarea> <button> <select> <optgroup> <option> <label> <fieldset> <legend> <isindex> Frames
Defines sample computer code Defines small text Deprecated. Defines strikethrough text Defines strong text Defines subscripted text Defines superscripted text Defines teletype text Deprecated. Defines underlined text Defines a variable part of a text Deprecated. Defines preformatted text
Defines an HTML form for user input Defines an input control Defines a multi-line text input control Defines a push button Defines a select list (drop-down list) Defines a group of related options in a select list Defines an option in a select list Defines a label for an input element Defines a border around elements in a form Defines a caption for a fieldset element Deprecated. Defines a searchable index related to a document
STF STF STF STF STF STF STF STF STF STF TF
<frame /> <frameset> <noframes> <iframe> Images <img /> <map> <area /> Links <a> <link /> Lists <ul> <ol> <li> <dir> <dl> <dt> <dd> <menu> Tables <table> <caption>
Defines a window (a frame) in a frameset Defines a set of frames Defines an alternate content for users that do not support frames Defines an inline frame
F F TF TF
Defines an anchor Defines the relationship between a document and an external resource
STF STF
Defines an unordered list Defines an ordered list Defines a list item Deprecated. Defines a directory list Defines a definition list Defines a term (an item) in a definition list Defines a description of a term in a definition list Deprecated. Defines a menu list
STF STF
<th> <tr> <td> <thead> <tbody> <tfoot> <col /> <colgroup> Styles <style> <div> <span> Meta Info <head> <title> <meta> <base /> <basefont /> Programming <script> <noscript>
Defines a header cell in a table Defines a row in a table Defines a cell in a table Groups the header content in a table Groups the body content in a table Groups the footer content in a table Defines attribute values for one or more columns in a table Defines a group of columns in a table for formatting
Defines style information for a document Defines a section in a document Defines a section in a document
Defines information about the document Defines the document title Defines metadata about an HTML document Defines a default address or a default target for all links on a page Deprecated. Defines a default font, color, or size for the text in a page
Defines a client-side script Defines an alternate content for users that do not support client-side scripts Deprecated. Defines an embedded applet
STF STF
<applet>
TF
STF STF
Below is a list of some attributes that are standard for most HTML elements Attribute class id style title Value classname id style_definition tooltip_text Description Specifies a classname for an element Specifies a unique id for an element Specifies an inline style for an element Specifies extra information about an element (displayed as a tool tip)
HTML Headings
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 a heading</h1> <h2>This is a heading</h2> <h3>This is a heading</h3>
<html> <body> <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> </body> </html>
Result:-
This is heading 1
This is heading 2
This is heading 3 This is heading 4 This is heading 5 This is heading 6
Note: Browsers automatically add some empty space (a margin) before and after each heading.
HTML Lines
The <hr /> tag creates a horizontal line in an HTML page. The hr element can be used to separate content:
Example
<p>This is a paragraph</p> <hr /> <p>This is a paragraph</p> <hr /> <p>This is a paragraph</p>
<html> <body> <p>The hr tag defines a horizontal rule:</p> <hr /> <p>This is a paragraph</p> <hr /> <p>This is a paragraph</p> <hr /> <p>This is a paragraph</p> </body> </html>
This is a paragraph
This is a paragraph
This is a paragraph
HTML Comments
Comments can be inserted into the HTML code to make it more readable and understandable. Comments are ignored by the browser and are not displayed. Comments are written like this:
Example
<!-- This is a comment -->
<html> <body> <!--This comment will not be displayed--> <p>This is a regular paragraph</p> </body> </html> Result:-
Hidden comments How to insert comments in the HTML source code. Horizontal lines How to insert a horizontal line.
HTML Paragraphs
Paragraphs are defined with the <p> tag.
Example
<p>This is a paragraph</p> <p>This is another paragraph</p>
Note: Browsers automatically add an empty line before and after a paragraph.
Example
<p>This is a paragraph <p>This is another paragraph
<html> <body> <p>This is a paragraph. <p>This is a paragraph. <p>This is a paragraph. <p>Don't forget to close your HTML tags!</p> </body> </html>
Result:-
This is a paragraph. This is a paragraph. This is a paragraph. Don't forget to close your HTML tags!
The example above will work in most browsers, but don't rely on it. Forgetting the end tag can produce unexpected results or errors. Note: Future version of HTML will not allow you to skip end tags.
Example
<p>This is<br />a para<br />graph with line breaks</p>
<html> <body> <p>This is<br />a para<br />graph with line breaks</p> </body> </html> Result:This is a para graph with line breaks\
The <br /> element is an empty HTML element. It has no end tag.
Result:My Bonnie lies over the ocean. My Bonnie lies over the sea. My Bonnie lies over the ocean. Oh, bring back my Bonnie to me.
superscript
EX:<html> <body> <p><b>This text is bold</b></p> <p><strong>This text is strong</strong></p> <p><big>This text is big</big></p> <p><i>This text is italic</i></p> <p><em>This text is emphasized</em></p> <p><code>This is computer output</code></p> <p>This is<sub> subscript</sub> and <sup>superscript</sup></p>
</body> </html>
Result:-
and line breaks. </pre> <p>The pre tag is good for displaying computer code:</p> <pre> for i = 1 to 10 print i next i </pre> </body> </html> Result:This is preformatted text. It preserves both spaces and line breaks.
<html> <body> <code>Computer code</code> <br /> <kbd>Keyboard input</kbd> <br />
<tt>Teletype text</tt> <br /> <samp>Sample text</samp> <br /> <var>Computer variable</var> <br /> <p><b>Note:</b> These tags are often used to display computer/programming code.</p> </body> </html>
<html> <body> <address> Written by W3Schools.com<br /> <a href="mailto:[email protected]">Email us</a><br /> Address: Box 564, Disneyland<br /> Phone: +12 34 56 78 </address> </body> </html>
Result:Written by W3Schools.com Email us Address: Box 564, Disneyland Phone: +12 34 56 78\
<html> <body> <p>My favorite color is <del>blue</del> <ins>red</ins>!</p> <p>Notice that browsers will strikethrough deleted text and underline inserted text.</p> </body> </html> Result:My favorite color is blue red! Notice that browsers will strikethrough deleted text and underline inserted text.
Defines italic text Defines small text Defines strong text Defines subscripted text Defines superscripted text Defines inserted text Defines deleted text
HTML Fonts
The HTML <font> Tag Should NOT be Used
The <font> tag is deprecated in HTML 4, and removed from HTML5. The World Wide Web Consortium (W3C) has removed the <font> tag from its recommendations. In HTML 4, style sheets (CSS) should be used to define the layout and display properties for many HTML elements. The example below shows how the HTML could look by using the <font> tag:
Example
<p> <font size="5" face="arial" color="red"> This paragraph is in Arial, size 5, and in red text color. </font> </p> <p> <font size="3" face="verdana" color="blue"> This paragraph is in Verdana, size 3, and in blue text color. </font> </p>
<html> <body> <p> <font size="5" face="arial" color="red"> This paragraph is in Arial, size 5, and in red text color.
</font> </p> <p> <font size="3" face="verdana" color="blue"> This paragraph is in Verdana, size 3, and in blue text color. </font> </p> <p>The font element is deprecated in HTML 4. Use CSS instead!</p> </body> </html>
Result:-
<html> <body> <h1 style="font-family:verdana">This is a heading</h1> <p style="font-family:courier">This is a paragraph.</p> </body> </html> Result:-
This is a heading
This is a paragraph.
Set the font color of text:-
<html> <body> <h1 style="color:blue">This is a heading</h1> <p style="color:red">This is a paragraph.</p> </body> </html>
Result:This is a heading
This is a paragraph.
Set the font, font size, and font color of text:<html> <body> <p style="font-family:verdana;font-size:110%;color:green"> This is a paragraph with some text in it. This is a paragraph with some text in it. This is a paragraph with some text in it. This is a paragraph with some text in it. </p> </body> </html> Result:-
This is a paragraph with some text in it. This is a paragraph with some text in it. This is a paragraph with some text in it. This is a paragraph with some text in it.