-
tags, links with tags specifying the href attribute, and images with tags, links with tags specifying the href attribute, and images with HTML Basic - : 4 Examples HTML Basic - : 4 Examples HTML Headings Example HTML Paragraphs Example HTML Links Example Note: The link address is specified in the href attribute. (You will learn about attributes in a later chapter of this tutorial). HTML Images Example Note: The name and the size of the image are provided as attributes. HTML Elements HTML Elements 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 Attributes Attributes are always specified in the start tag Attributes come in name/value pairs like: name="value" Attribute Example Example Try it yourself style title style_definition tooltip_text Specifies an inline style for an element Specifies extra information about an element (displayed as a tool tip) For more information about standard attributes: HTML Standard Attributes Reference Example Try it yourself The <br /> element is an empty HTML element. It has no end tag. In XHTML, XML, elements with no end tag (closing tag) are not allowed. Even if <br> works in all browsers, writing <br /> instead works better in XHTML and XML applications. More Examples Previous Next Chapter Try it yourself Defines emphasized text Defines italic text Defines small text Defines strong text Defines subscripted text Defines superscripted text Defines inserted text Defines deleted text HTML Fonts Example Try it yourself in Cascading Style Sheet files (CSS files) in the <style> element in the HTML head section in the style attribute in single HTML elements Example < /html> Try it yourself The background-color property makes the "old" bgcolor attribute obsolete. Try it yourself: Background color the old way Example < /html> Try it yourself The font-family, color, and font-size properties make the old <font> tag obsolete. Example < /html> Try it yourself The text-align property makes the old <center> tag obsolete. Try it yourself: Centered heading the old way These tags and attributes should be avoided: Tags <center> <font> and <basefont> <s> and <strike> <u> Attributes align bgcolor color Description Deprecated. Defines centered content Deprecated. Defines HTML fonts Deprecated. Defines strikethrough text Deprecated. Defines underlined text Description Deprecated. Defines the alignment of text Deprecated. Defines the background color Deprecated. Defines the text color tags specifying the src, width, and height attributes. The examples are intended to help readers learn HTML elements before subsequent chapters cover additional tags and attributes."> -
tags, paragraphs with
tags specifying the src, width, and height attributes. The examples are intended to help readers learn HTML elements before subsequent chapters cover additional tags and attributes.">
Uploaded by
jalalkhalilUploaded by
jalalkhalilHTML Basic - 4 Examples
Previous Next Chapter
Don't worry if the examples use tags you have not learned. You will learn about them in the next chapters.
HTML headings are defined with the <h1> to <h6> tags.
< h1>This is a heading</h1> < h2>This is a heading</h2> < h3>This is a heading</h3>
Try it yourself
HTML paragraphs are defined with the <p> tag.
< p>This is a paragraph.</p> < p>This is another paragraph.</p>
Try it yourself
HTML links are defined with the <a> tag.
< a href="http://www.w3schools.com">This is a link</a>
Try it yourself HTML images are defined with the <img> tag.
< img src="w3schools.jpg" width="104" height="142" />
Try it yourself Previous Next Chapter
Previous Next Chapter HTML documents are defined by HTML elements.
An HTML element is everything from the start tag to the end tag:Start tag * <p> <a href="default.htm" > <br />
Element content This is a paragraph This is a link </p> </a>
HTML Element Syntax
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 attributesNested HTML Elements
Most HTML elements can be nested (can contain other HTML elements). HTML documents consist of nested HTML elements.HTML Document Example
< html> < body> < p>This is my first paragraph.</p> < /body> < /html> The example above contains 3 HTML elements.HTML Example Explained
The <p> element: < p>This is my first paragraph.</p> The <p> element defines a paragraph in the HTML document. The element has a start tag <p> and an end tag </p>. The element content is: This is my first paragraph. The <body> element: < body> < p>This is my first paragraph.</p> < /body> The <body> element defines the body of the HTML document. The element has a start tag <body> and an end tag </body>. The element content is another HTML element (a p element). The <html> element: < html> < body> < p>This is my first paragraph.</p> < /body> < /html> The <html> element defines the whole HTML document. The element has a start tag <html> and an end tag </html>. The element content is another HTML element (the body element).Don't Forget the End Tag
Some HTML elements might display correctly even if you forget the end tag: < p>This is a paragraph < p>This is a paragraph The example above works in most browsers, because the closing tag is considered optional. Never rely on this. Many HTML elements will produce unexpected results and/or errors if you forget the end tag .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). Tip: In XHTML, all elements must be closed. Adding a slash inside the start tag, like <br />, is the proper way of closing empty elements in XHTML (and XML).HTML Tip: Use Lowercase Tags
HTML tags are not case sensitive: <P> means the same as <p>. Many web sites use uppercase HTML tags. W3Schools use lowercase tags because the World Wide Web Consortium (W3C) recommends lowercase in HTML 4, and demands lowercase tags in XHTML. Previous Next Chapter
Previous Next Chapter Attributes provide additional information about HTML elements.
HTML elements can have attributes Attributes provide additional information about an element
HTML links are defined with the <a> tag. The link address is specified in the href attribute:
< a href="http://www.w3schools.com">This is a link</a>Always Quote Attribute Values
Attribute values should always be enclosed in quotes. Double style quotes are the most common, but single style quotes are also allowed. Tip: In some rare situations, when the attribute value itself contains quotes, it is necessary to use single quotes: name='John "ShotGun" Nelson'HTML Tip: Use Lowercase Attributes
Attribute names and attribute values are case-insensitive. However, the World Wide Web Consortium (W3C) recommends lowercase attributes/attribute values in their HTML 4 recommendation. Newer versions of (X)HTML will demand lowercase attributes.HTML Attributes Reference
A complete list of legal attributes for each HTML element is listed in our: Complete HTML Reference Below is a list of some attributes that are standard for most HTML elements: Attribute class id Value classname id Description Specifies a classname for an element Specifies a unique id for an element Previous Next Chapter
HTML Tag Reference
W3Schools' tag reference contains additional information about these tags and their attributes. You will learn more about HTML tags and attributes in the next chapters of this tutorial. 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 commentHTML Line Breaks
Use the <br /> tag if you want a line break (a new line) without starting a new paragraph:
< p>This is<br />a para<br />graph with line breaks</p><br> or <br />
HTML Output - Useful Tips
You cannot be sure how HTML will be displayed. Large or small screens, and resized windows will create different results. With HTML, you cannot change the output by adding extra spaces or extra lines in your HTML code. The browser will remove extra spaces and extra lines when the page is displayed. Any number of lines count as one line, and any number of spaces count as one space. Try it yourself (The example demonstrates some HTML formatting problems)Examples from this page
HTML paragraphs How HTML paragraphs are displayed in a browser. Line breaks The use of line breaks in an HTML document. Poem problems Some problems with HTML formatting.
More paragraphs The default behaviors of paragraphs.HTML Tag Reference
W3Schools' tag reference contains additional information about HTML elements and their attributes. Tag <p> <br /> Description Defines a paragraph Inserts a single line breakHTML Text Formatting
Previous Next Chapter HTML Text Formatting This text is bold
This text is big
This text is italicThis is computer output
This is subscript and
superscriptHTML Formatting Tags
HTML uses tags like <b> and <i> for formatting output, like bold or italictext. These HTML tags are called formatting tags (look at the bottom of this page for a complete reference). 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 Text Formatting Tags
Tag <b> <big> Description Defines bold text Defines big text<em> <i> <small> <strong> <sub> <sup> <ins> <del>
HTML "Computer Output" Tags
Tag <code> <kbd> <samp> <tt> <var> <pre> Description Defines computer code text Defines keyboard text Defines sample computer code Defines teletype text Defines a variable Defines preformatted textHTML Citations, Quotations, and Definition Tags
Tag <abbr> <acronym> <address> <bdo> <blockquote> <q> <cite> <dfn> Description Defines an abbreviation Defines an acronym Defines contact information for the author/owner of a document Defines the text direction Defines a long quotation Defines a short quotation Defines a citation Defines a definition term Previous Next Chapter
Previous Next Chapter 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:
< 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 Styles - CSS
Previous Next Chapter CSS is used to style HTML elements.
Look! Styles and colors
This text is in Verdana and red This text is in Times and blueThis text is 30 pixels high
Try it yourselfStyling HTML with CSS
CSS was introduced together with HTML 4, to provide a better way to style HTML elements. CSS can be added to HTML in the following ways:Using the HTML Style Attribute
It is time consuming and not very practical to style HTML elements using the style attribute. The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files. However, in this HTML tutorial we will introduce you to CSS using the style attribute. This is done to simplify the examples. It also makes it easier for you to edit the code and try it yourself. You can learn everything about CSS in our CSS Tutorial.HTML Style Example - Background Color
The background-color property defines the background color for an element:
< html> < < < < body style="background-color:yellow;"> h2 style="background-color:red;">This is a heading</h2> p style="background-color:green;">This is a paragraph.</p> /body>HTML Style Example - Font, Color and Size
The font-family, color, and font-size properties defines the font, color, and size of the text in an element:
< html> < < < < body> h1 style="font-family:verdana;">A heading</h1> p style="font-family:arial;color:red;font-size:20px;">A paragraph.</p> /body>HTML Style Example - Text Alignment
The text-align property specifies the horizontal alignment of text in an element:
< html> < < < < body> h1 style="text-align:center;">Center-aligned heading</h1> p>This is a paragraph.</p> /body>Deprecated Tags and Attributes
In HTML 4, several tags and attributes were deprecated. Deprecated means that they will not be supported in future versions of HTML. The message is clear: Avoid using deprecated tags and attributes!For all of the above: Use styles instead!
Previous Next Chapter
You might also like