Introduction to HTML




1. What is HTML anyway?
Developed by scientist Tim Berners-Lee in 1990, HTML is the "hidden" code that helps us communicate with others on the World Wide Web (WWW).
HTML is a language for describing web pages.
  • 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 Example:-
    <!DOCTYPE html>
    <html>
    <body>

    <h1>My First Heading</h1>

    <p>My first paragraph.</p>

    </body>
    </html>

    Example Explained:-

    • The DOCTYPE declaration defines the document type.
    • The text between <html> and </html> describes the web page.
    • The text between <body> and </body> is the visible page content.
    • The text between <h1> and </h1> is displayed as a heading.
    • The text between <p> and </p> is displayed as a paragraph.
    The <!DOCTYPE html> declaration is the doctype for HTML5.

    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.
    <tagname>content</tagname>

    HTML Elements:-

    "HTML tags" and "HTML elements" are often used to describe the same thing.
    But strictly speaking, an HTML element is everything between the start tag and the end tag, including the tags:
    HTML Element:
    <p>This is a paragraph.</p>

    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 determine how the content of the HTML page is to be presented/displayed to the user:

    HTML Page Structure:-

    Below is a visualization of an HTML page structure:

    The <!DOCTYPE> Declaration:-

    The <!DOCTYPE> declaration helps the browser to display a web page correctly.
    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

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

    XHTML 1.0

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

     

    HTML Editors:-


    Writing HTML Using Notepad or TextEdit.

    HTML can be edited by using a professional HTML editor like:
    • Adobe Dreamweaver
    • Microsoft Expression Web
    • CoffeeCup HTML Editor
    However, for learning HTML we recommend a text editor like Notepad (PC) or TextEdit (Mac). We believe 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.

    Step 1: Start Notepad.

    To start Notepad go to:
    Start
        All Programs
            Accessories
                Notepad

    Step 2: Edit Your HTML with Notepad.

    Type your HTML code into your Notepad:
     


    Step 3: Save Your HTML.

    Select Save as. in Notepad's file menu.
    When you save an HTML file, you can use either the .htm or the .html file extension. There is no difference, it is entirely up to you.
    Save the file in a folder that is easy to remember, like My First Code.

    Step 4: Run the HTML in Your Browser.

    Start your web browser and open your html file from the File, Open menu, or just browse the folder and double-click your HTML file.
    The result should look much like this:

    HTML Basic - 4 Examples


    Don't worry if the examples use tags you have not learned.
    You will learn about them in the next sessions.

    Example:-

    <h1>This is a heading</h1>
    <h2>This is a heading</h2>
    <h3>This is a heading</h3>

    HTML Paragraphs:-

    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="http://www.uettaxila.edu.pk">This is a link</a>
    The link address is specified in the href attribute.
    (You will learn about attributes a little later).

    HTML Images:-

    HTML images are defined with the <img> tag.

    Example:-

    <img src="myimage.jpg" alt="My_Picture" width="104" height="142">

    HTML Elements:-

    HTML documents are defined by HTML elements.

    HTML Elements:-

    An HTML element is everything from the start tag to the end tag:
    * The start tag is often called the opening tag. The end tag is often called the closing tag.

    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 attributes
    Note: You will learn about attributes in the sometime.

    Nested HTML Elements:-

    Most HTML elements can be nested (can contain other HTML elements).
    HTML documents consist of nested HTML elements.

    HTML Document Example:-

    <!DOCTYPE html>
    <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.

    HTML Attributes:-

    Attributes provide additional information about HTML elements.

    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.google.com">Google Search</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.

    HTML Tip: Use Lowercase Attributes

    Attribute names and attribute values are case-insensitive.

    HTML Headings

    Headings are important in HTML documents.

    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>
    Note: Browsers automatically add some empty space (a margin) before and after each heading.

    Headings Are Important:-

    Use HTML headings for headings only. Don't use headings to make text BIG or bold.
    Search engines use your headings to index the structure and content of your web pages.
    Since users may skim your pages by its headings, it is important to use headings to show the document structure.
    H1 headings should be used as main headings, followed by H2 headings, then the less important H3 headings, and so on.

    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 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 -->
    Note: There is an exclamation point after the opening bracket, but not before the closing bracket.

    HTML Tip - How to View HTML Source:-

    Have you ever seen a Web page and wondered "Hey! How did they do that?"
    To find out, right-click in the page and select "View Source" (IE) or "View Page Source" (Firefox), or similar for other browsers. This will open a window containing the HTML code of the page.


    HTML Tag Reference Summary:-

    Tag
    Description
    Defines an HTML document
    Defines the document's body
    Defines HTML headings
    Defines a horizontal line
    Defines a comment

     

    HTML Paragraphs:-

    HTML documents are divided into paragraphs.

    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.

    Don't Forget the End Tag:-

    Most browsers will display HTML correctly even if you forget the end tag:

    Example:-

    <p>This is a paragraph
    <p>This is another paragraph
    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.

    HTML Line Breaks:-

    Use the <br> tag if you want a line break (a new line) without starting a new paragraph:

    Example:-

    <p>This is<br>a para<br>graph with line breaks</p>

    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 the following Code:
    <!DOCTYPE html>
    <html>
    <body>
    <p>
        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.
    </p>
    <p>Note that your browser ignores the layout!</p>
    </body>
    </html>

    Try this code:-
    <!DOCTYPE html>
    <html>
    <body>
    <p>
    This paragraph
    contains a lot of lines
    in the source code,
    but the browser
    ignores it.
    </p>

    <p>
    This paragraph
    contains      a lot of spaces
    in the source     code,
    but the    browser
    ignores it.
    </p>
    <p>
    The number of lines in a paragraph depends on the size of your browser window. If you resize the browser window, the number of lines in this paragraph will change.
    </p>
    </body>
    </html>

    HTML Text Formatting:-


    This text is bold

    This text is italic

    This is computer output

    This is subscript and superscript
    The code is:
    <!DOCTYPE html>
    <html>
    <body>

    <p><b>This text is bold</b></p>
    <p><i>This text is italic</i></p>
    <p><code>This is computer output</code></p>
    <p>This is<sub> subscript</sub> and <sup>superscript</sup></p>

    </body>
    </html>

    HTML Formatting Tags:-

    HTML uses tags like <b> and <i> for formatting output, like bold or italic text.
    These HTML tags are called formatting tags
    Pre Formatted Text:-
    <!DOCTYPE html>
    <html>
    <body>
    <pre>
    This is
    preformatted text.
    It preserves      both spaces
    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>
    Address:-
    How to define contact information for the author/owner of an HTML document.
    <!DOCTYPE html>
    <html>
    <body>

    <address>
    Written by Aamir Arsalan<br>
    <a href="aamir.arsalan@uettaxila.edu.pk">Email me</a><br>
    Address: Computer Engineering Department, UET Taxila.<br>
    Phone: 0333-5701845
    </address>
    </body>
    </html>
    Abbreviations and acronyms:-
    How to handle abbreviations and acronyms.
    <!DOCTYPE html>
    <html>
    <body>
    <p>The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>
    <p>Can I get this <abbr title="as soon as possible">ASAP</abbr>?</p>

    <p>The title attribute is used to show the spelled-out version when holding the mouse pointer over the acronym or abbreviation.</p>

    </body>
    </html>
    Text direction:-
    How to change the text direction.
    <!DOCTYPE html>
    <html>
    <body>

    <p>
    If your browser supports bi-directional override (bdo), the next line will be written from the right to the left (rtl):
    </p>
    <bdo dir="rtl">
    My name is Aamir Arsalan

    </bdo>

    </body>
    </html>
    Quotations:-
    How to handle long and short quotations
    .
    <!DOCTYPE html>
    <html>
    <body>
    <h2>The blockquote Element</h2>
    <p>The blockquote element specifies a section that is quoted from another source.</p>
    <p>Here is a quote from WWF's website:</p>
    <blockquote cite="http://www.worldwildlife.org/who/index.html">
    For 50 years, WWF has been protecting the future of nature. The world’s leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
    </blockquote>
    <p><b>Note:</b> Browsers usually indent blockquote elements.</p>

    <h2>The q Element</h2>
    <p>The q element defines a short quotation.</p>

    <p>WWF's goal is to:
    <q>Build a future where people live in harmony with nature.</q>
    We hope they succeed.</p>
    <p><b>Note:</b> Browsers insert quotation marks around the q element.</p>

    </body>
    </html>
    Deleted and inserted text:-
    How to mark deleted and inserted text.
    <!DOCTYPE html>
    <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>
    Marked/Highlighted text:-
    How to mark/highlight text.
    <!DOCTYPE html>
    <html>
    <body>
    <p>Do not forget to buy <mark>milk</mark> today.</p>
    </body>
    </html>

    HTML Text Formatting Tags:-

    Tag
    Description
    Defines bold text
    Defines a part of text in an alternate voice or mood
    Defines smaller text
    Defines subscripted text
    Defines superscripted text
    Defines inserted text
    Defines deleted text
    Defines marked/highlighted text

    HTML "Computer Output" Tags:-

    Tag
    Description
    Defines computer code text
    Defines preformatted text

    HTML Citations, Quotations, and Definition Tags:-

    Tag
    Description
    Defines an abbreviation or acronym
    Defines contact information for the author/owner of a document
    Defines the text direction
    Defines a section that is quoted from another source
    Defines an inline (short) quotation
    Defines the title of a work

    HTML Links

    Links are found in nearly all Web pages. Links allow users to click their way from page to page.
    HTML links:-
    How to create links in an HTML document.

    HTML Hyperlinks (Links)

    The HTML <a> tag defines a hyperlink.
    A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another document.
    When you move the cursor over a link in a Web page, the arrow will turn into a little hand.
    The most important attribute of the <a> element is the href attribute, which indicates the link's destination.
    By default, links will appear as follows in all browsers:
    • An unvisited link is underlined and blue
    • A visited link is underlined and purple
    • An active link is underlined and red

    HTML Link Syntax:-

    The HTML code for a link is simple. It looks like this:
    <a href="url">Link text</a>
    The href attribute specifies the destination of a link.

    Example:-

    <a href="http://www.google.com/">Visit Google</a>
    which will display like this: Visit Google
    Clicking on this hyperlink will send the user to Google page.
    Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element.

    HTML Links - The target Attribute:-

    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:

    Example:-

    <a href="http://www.google.com/" target="_blank">Visit Google!</a>

    HTML Links - The id Attribute:-

    The id attribute can be used to create a bookmark inside an HTML document.
    Tip: Bookmarks are not displayed in any special way. They are invisible to the reader.

    Example:-

    An anchor with an id inside an HTML document:
    <a id="tips">Useful Tips Section</a>
    Create a link to the "Useful Tips Section" inside the same document:
    <a href="#tips">Visit the Useful Tips Section</a>
    Or, create a link to the "Useful Tips Section" from another page:
    <a href="http://www.google.com #tips">
    Visit the Useful Tips Section</a>
    An image as a link:-
    How to use an image as a link.
    <!DOCTYPE html>
    <html>
    <body>
    <p>Create a link of an image:
    <a href="default.asp">
    <img src="smiley.gif" alt="HTML tutorial" width="42" height="42"></a></p>
    <p>No border around the image, but still a link:
    <a href="default.asp">
    <img style="border:0;" src="smiley.gif" alt="HTML tutorial" width="42" height="42"></a></p>
    </body>
    </html>
    Link to a location on the same page:-
    How to link to a bookmark.
    <!DOCTYPE html>
    <html>
    <body>

    <p>
    <a href="#C4">See also Chapter 4.</a>
    </p>

    <h2>Chapter 1</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 2</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 3</h2>
    <p>This chapter explains ba bla bla</p>

    <h2><a id="C4">Chapter 4</a></h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 5</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 6</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 7</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 8</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 9</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 10</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 11</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 12</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 13</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 14</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 15</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 16</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 17</h2>
    <p>This chapter explains ba bla bla</p>

    </body>
    </html>
    Create a mailto link:-
    How to link to a mail message (will only work if you have mail installed).
    <!DOCTYPE html>
    <html>
    <body>
    <p>
    This is an email link:
    <a href="mailto:aamir.arsalan@uettaxila.edu.pk?Subject=Hello again" target="_top">
    Send Mail</a>
    </p>
    </body>
    </html>

    Create a mailto link 2:-
    Another mailto link.
    <!DOCTYPE html>
    <html>
    <body>

    <p>
    This is another mailto link:
    <a href="mailto:someone@example.com?cc=someoneelse@example.com&bcc=andsomeoneelse@example.com&subject=Summer Party&body=You are invited to a big summer party!" target="_top">Send mail!</a>
    </p>
    </body>
    </html>





    HTML <head>:-

     

    The head Element:-

    The head element contains information about the page, but no information that will be displayed on the page itself. For example, it contains the title element, which tells the browser what to display in its title bar (the title bar is the very top part of the browser window—the part with minimize, maximize and close buttons):
    The following tags can be added to the head section: <title>, <style>, <meta>, <link>, <script>, <noscript>, and <base>.
    Example:-
    <head>
    <title>HTML Basic tags</title>
    <meta name="Keywords" content="HTML, Web Pages" />
    <meta name="description" content="HTML Basic Tags" />
    <base href="http://www.tutorialspoint.com" />
    <link rel="stylesheet" type="text/css" href="tp.css" />
    <script type="text/javascript">
    _uacct = "UA-232293";
    urchinTracker();
    </script>
    </head>
    The <title> Element:
    You should specify a title for every page that you write inside the <title> element. This element is a child of the <head> element). It is used in several ways:
    It displays at the very top of a browser window.
    It is used as the default name for a bookmark in browsers such as IE and Netscape.
    It is used by search engines that use its content to help index pages.
    Therefore it is important to use a title that really describes the content of your site. The <title> element should contain only the text for the title and it may not contain any other elements.
    <!DOCTYPE html>
    <html>
    <head>
    <title>Title of the document</title>
    </head>

    <body>
    The content of the document......
    </body>

    </html>
    Example:-
    <!DOCTYPE html>
    <html>
    <head>
    <title>My first HTML page</title>
    </head>
    <body>
    <p>The content of the body element is displayed in the browser.</p>
    <p>The content of the title element is displayed in the browser's title.</p>
    </body>
    </html>

    The HTML <base> Element:-

    The <base> tag specifies the base URL/target for all relative URLs in a page:
    <head>
    <base href="http://www.w3schools.com/images/" target="_blank">
    </head>

    Example:-

    <!DOCTYPE html>

    <html>

    <head>

    <base href="http://www.w3schools.com/images/" target="_blank">

    </head>

     

    <body>

    <img src="stickman.gif" width="24" height="39"> - Notice that we have only specified a relative address for the image. Since we have specified a base URL in the head section, the browser will look for the image at "http://www.w3schools.com/images/stickman.gif"

    <br><br>

    <a href="http://www.w3schools.com">W3Schools</a> - Notice that the link opens in a new window, even if it has no target="_blank" attribute. This is because the target attribute of the base element is set to "_blank".

     

    </body>

    </html>

    The HTML <link> Element:-

    The <link> tag defines the relationship between a document and an external resource. The HTML link element is very similar to the HTML element because it's used to link a document to other resources. But unlike it, the HTML link element can only be defined in the head section of the document (HTML head element) and is used to provide global relational information about the document.

    For example, authors can link to a document that acts as index for the current document, to an alternate version in other language, or an alternate version designed for other media (e.g., a printer).
    A particular and very common use for the HTML link tag is to provide an external style sheets file for the document.
    The <link> tag is most used to link to style sheets:
    <head>
    <link rel="stylesheet" type="text/css" href="mystyle.css">
    </head>

    The HTML <style> Element:-

    The <style> tag is used to define style information for an HTML document.
    Inside the <style> element you specify how HTML elements should render in a browser:
    <head>
    <style type="text/css">
    body {background-color:yellow;}
    p {color:blue;}
    </style>
    </head>

    The HTML <meta> Element:-

    Metadata is data (information) about data.
    The <meta> tag provides metadata about the HTML document. Metadata will not be displayed on the page, but will be machine parsable.
    Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata.
    The metadata can be used by browsers (how to display content or reload page), search engines (keywords), or other web services.
    <meta> tags always go inside the <head> element.
    <html>
    <head>
    <title>Car rental in New York</title>
    <meta name="Author" content="Jhon Doe" />
    <meta name="keywords" lang="en" content="car, rental, rent" />
    <meta name="keywords" lang="es" content="autos, alquiler, alquila" />
    <meta name="description" lang="en" content="Car rental in New York. Cheap prices best insurance. Call now 999-NO-NUMBER." />
    <meta http-equiv="expires" content="Mon, 20 Sep 2006 11:09:00 GMT" />
    </head>
    <body>
    Contents...
    </body>
    </html>

    HTML Styles – CSS:-

    CSS (Cascading Style Sheets) is used to style HTML elements.

    Styling 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:
    • Inline - using the style attribute in HTML elements
    • Internal - using the <style> element in the <head> section
    • External - using an external CSS file
    The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files.
    Example:-
    <!DOCTYPE html>
    <html>
    <head>
    <style type="text/css">
    h1 {color:red;}
    h2 {color:blue;}
    p {color:green;}
    </style>
    </head>
    <body>
    <h1>All header 1 elements will be red</h1>
    <h2>All header 2 elements will be blue</h2>
    <p>All text in paragraphs will be green.</p>
    </body>
    </html>

    Inline Styles:-

    An inline style can be used if a unique style is to be applied to one single occurrence of an element.
    To use inline styles, use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example below shows how to change the text color and the left margin of a paragraph:
    <p style="color:blue;margin-left:20px;">This is a paragraph.</p>

    HTML Style Example - Background Color:-

    The background-color property defines the background color for an element:
    <!DOCTYPE html>
    <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>

    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:
    Example:-
    <!DOCTYPE html>
    <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>

    HTML Style Example - Text Alignment:-

    The text-align property specifies the horizontal alignment of text in an element:

    Example:-

    <!DOCTYPE html>
    <html>

    <body>
    <h1 style="text-align:center;">Center-aligned heading</h1>
    <p>This is a paragraph.</p>
    </body>

    </html>

    Internal Style Sheet:-

    An internal style sheet can be used if one single document has a unique style. Internal styles are defined in the <head> section of an HTML page, by using the <style> tag, like this:
    <head>
    <style type="text/css">
    body {background-color:yellow;}
    p {color:blue;}
    </style>
    </head>

    External Style Sheet:-

    An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the <head> section:
    <head>
    <link rel="stylesheet" type="text/css" href="mystyle.css">
    </head>

    Deprecated Tags and Attributes:-

    In HTML 4, several tags and attributes were used to style documents. These tags are not supported in newer versions of HTML.
    Avoid using the elements: <font>, <center>, and <strike>, and the attributes: color and bgcolor.

    HTML Images:-

    HTML Images - The <img> Tag and the Src Attribute

    In HTML, images are defined with the <img> tag.
    The <img> tag is empty, which means that it contains attributes only, and has no closing tag.
    To display an image on a page, you need to use the src attribute. Src stands for "source". The value of the src attribute is the URL of the image you want to display.
    Syntax for defining an image:
    <img src="url" alt="some_text">
    The URL points to the location where the image is stored. An image named "boat.gif", located in the "images" directory on "www.w3schools.com" has the URL:http://www.w3schools.com/images/boat.gif.
    The browser displays the image where the <img> tag occurs in the document. If you put an image tag between two paragraphs, the browser shows the first paragraph, then the image, and then the second paragraph.

    HTML Images - Set Height and Width of an Image:-

    The height and width attributes are used to specify the height and width of an image.
    The attribute values are specified in pixels by default:
    <img src="smiley.gif" alt="Smiley face" width="42" height="42">
    Tip: It is a good practice to specify both the height and width attributes for an image. If these attributes are set, the space required for the image is reserved when the page is loaded. However, without these attributes, the browser does not know the size of the image. The effect will be that the page layout will change during loading (while the images load).

    Basic Notes - Useful Tips:-

    Note: If an HTML file contains ten images - eleven files are required to display the page right. Loading images takes time, so my best advice is: Use images carefully.
    Note: When a web page is loaded, it is the browser, at that moment that actually gets the image from a web server and inserts it into the page. Therefore, make sure that the images actually stay in the same spot in relation to the web page, otherwise your visitors will get a broken link icon. The broken link icon is shown if the browser cannot find the image.
    Example:-
    <!DOCTYPE html>
    <html>
    <body>
    <p>
    An image:
    <img src="smiley.gif" alt="Smiley face" width="42" height="42"></p>
    <p>
    </body>
    </html>
    <!DOCTYPE html>
    <html>
    <body>
    <p>An image from another folder:</p>
    <img src="/images/chrome.gif" alt="Google Chrome" width="33" height="32"><p>An image from W3Schools:</p>
    <img src="http://www.w3schools.com/images/w3schools_green.jpg" alt="W3Schools.com" width="104" height="142">
    </body>
    </html>
    Let an image float to the left and to the right:-
    <!DOCTYPE html>
    <html>
    <body>
    <p>
    <img src="smiley.gif" alt="Smiley face" style="float:left" width="42" height="42"> A paragraph with an image. The image will float to the left of this text.
    </p>
    <p>
    <img src="smiley.gif" alt="Smiley face" style="float:right" width="42" height="42"> A paragraph with an image. The image will float to the right of this text.
    </p>
    <p><b>Note:</b> Here we have used the CSS "float" property to align the image; as the align attribute is deprecated in HTML 4, and is not supported in HTML5.</p>
    </body>
    </html>
    Make a hyperlink of an image:-
    <!DOCTYPE html>
    <html>
    <body>
    <p>Create a link of an image:
    <a href="default.asp">
    <img src="smiley.gif" alt="HTML tutorial" width="42" height="42"></a></p>
    <p>No border around the image, but still a link:
    <a href="default.asp">
    <img style="border:0;" src="smiley.gif" alt="HTML tutorial" width="42" height="42"></a></p>
    </body>
    </html>

    HTML Image Tags

    Tag
    Description
    Defines an image
    Defines an image-map
    Defines a clickable area inside an image-map

    HTML Tables:-

    HTML Table Example:

    First Name
    Last Name
    Points
    Jill
    Smith
    50
    Eve
    Jackson
    94
    John
    Doe
    80
    Adam
    Johnson
    67

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

    <p>
    Each table starts with a table tag.
    Each table row starts with a tr tag.
    Each table data starts with a td tag.
    </p>

    <h4>One column:</h4>
    <table border="1">
    <tr>
      <td>100</td>
    </tr>
    </table>

    <h4>One row and three columns:</h4>
    <table border="1">
    <tr>
      <td>100</td>
      <td>200</td>
      <td>300</td>
    </tr>
    </table>

    <h4>Two rows and three columns:</h4>
    <table border="1">
    <tr>
      <td>100</td>
      <td>200</td>
      <td>300</td>
    </tr>
    <tr>
      <td>400</td>
      <td>500</td>
      <td>600</td>
    </tr>
    </table>

    </body>
    </html>

    HTML Tables:-

    Tables are defined with the <table> tag.
    A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the <td> tag). td stands for "table data," and holds the content of a data cell. A <td> tag can contain text, links, images, lists, forms, other tables, etc.

    Table Example

    <table border="1">
    <tr>
    <td>row 1, cell 1</td>
    <td>row 1, cell 2</td>
    </tr>
    <tr>
    <td>row 2, cell 1</td>
    <td>row 2, cell 2</td>
    </tr>
    </table>
    How the HTML code above looks in a browser:
    row 1, cell 1
    row 1, cell 2
    row 2, cell 1
    row 2, cell 2

    HTML Tables and the Border Attribute:-

    If you do not specify a border attribute, the table will be displayed without borders. Sometimes this can be useful, but most of the time, we want the borders to show.
    To display a table with borders, specify the border attribute:
    <table border="1">
    <tr>
    <td>Row 1, cell 1</td>
    <td>Row 1, cell 2</td>
    </tr>
    </table>
    HTML Table Headers:-
    Header information in a table are defined with the <th> tag.
    All major browsers display the text in the <th> element as bold and centered.
    <table border="1">
    <tr>
    <th>Header 1</th>
    <th>Header 2</th>
    </tr>
    <tr>
    <td>row 1, cell 1</td>
    <td>row 1, cell 2</td>
    </tr>
    <tr>
    <td>row 2, cell 1</td>
    <td>row 2, cell 2</td>
    </tr>
    </table>
    How the HTML code above looks in your browser:
    Header 1
    Header 2
    row 1, cell 1
    row 1, cell 2
    row 2, cell 1
    row 2, cell 2

    Examples:-
    Tables without borders:-
    How to create tables without borders.
    <!DOCTYPE html>
    <html>
    <body>
    <h4>This table has no borders:</h4>
    <table>
    <tr>
      <td>100</td>
      <td>200</td>
      <td>300</td>
    </tr>
    <tr>
      <td>400</td>
      <td>500</td>
      <td>600</td>
    </tr>
    </table>
    <h4>And this table has no borders:</h4>
    <table border="0">
    <tr>
      <td>100</td>
      <td>200</td>
      <td>300</td>
    </tr>
    <tr>
      <td>400</td>
      <td>500</td>
      <td>600</td>
    </tr>
    </table>
    </body>
    </html>
    Table headers:-
    How to create table headers.
    <!DOCTYPE html>
    <html>
    <body>
    <h4>Table headers:</h4>
    <table border="1">
    <tr>
      <th>Name</th>
      <th>Telephone</th>
      <th>Telephone</th>
    </tr>
    <tr>
      <td>Bill Gates</td>
      <td>555 77 854</td>
      <td>555 77 855</td>
    </tr>
    </table>

    <h4>Vertical headers:</h4>
    <table border="1">
    <tr>
      <th>First Name:</th>
      <td>Bill Gates</td>
    </tr>
    <tr>
      <th>Telephone:</th>
      <td>555 77 854</td>
    </tr>
    <tr>
      <th>Telephone:</th>
      <td>555 77 855</td>
    </tr>
    </table>

    </body>
    </html>
    Table with a caption:-
    How to add a caption to a table.
    <!DOCTYPE html>
    <html>
    <body>

    <table border="1">
      <caption>Monthly savings</caption>
      <tr>
        <th>Month</th>
        <th>Savings</th>
      </tr>
      <tr>
        <td>January</td>
        <td>$100</td>
      </tr>
      <tr>
        <td>February</td>
        <td>$50</td>
      </tr>
    </table>

    </body>
    </html>
    Table cells that span more than one row/column:-
    How to define table cells that span more than one row or one column.
    <!DOCTYPE html>
    <html>
    <body>

    <h4>Cell that spans two columns:</h4>
    <table border="1">
    <tr>
      <th>Name</th>
      <th colspan="2">Telephone</th>
    </tr>
    <tr>
      <td>Bill Gates</td>
      <td>555 77 854</td>
      <td>555 77 855</td>
    </tr>
    </table>

    <h4>Cell that spans two rows:</h4>
    <table border="1">
    <tr>
      <th>First Name:</th>
      <td>Bill Gates</td>
    </tr>
    <tr>
      <th rowspan="2">Telephone:</th>
      <td>555 77 854</td>
    </tr>
    <tr>
      <td>555 77 855</td>
    </tr>
    </table>

    </body>
    </html>
    Tags inside a table:-
    How to display elements inside other elements.
    <!DOCTYPE html>
    <html>
    <body>

    <table border="1">
    <tr>
      <td>
       <p>This is a paragraph</p>
       <p>This is another paragraph</p>
      </td>
      <td>This cell contains a table:
       <table border="1">
       <tr>
         <td>A</td>
         <td>B</td>
       </tr>
       <tr>
         <td>C</td>
         <td>D</td>
       </tr>
       </table>
      </td>
    </tr>
    <tr>
      <td>This cell contains a list
       <ul>
        <li>apples</li>
        <li>bananas</li>
        <li>pineapples</li>
       </ul>
      </td>
      <td>HELLO</td>
    </tr>
    </table>

    </body>
    </html>
    Cell padding:-
    How to use cell padding to create more white space between the cell content and its borders.
    <!DOCTYPE html>
    <html>
    <body>
    <h4>Without cellpadding:</h4>
    <table border="1">
    <tr>
      <td>First</td>
      <td>Row</td>
    </tr>  
    <tr>
      <td>Second</td>
      <td>Row</td>
    </tr>
    </table>

    <h4>With cellpadding:</h4>
    <table border="1"
    cellpadding="10">
    <tr>
      <td>First</td>
      <td>Row</td>
    </tr>  
    <tr>
      <td>Second</td>
      <td>Row</td>
    </tr>
    </table>

    </body>
    </html>
    Cell spacing:-
    How to use cell spacing to increase the distance between the cells.
    <!DOCTYPE html>
    <html>
    <body>

    <h4>Without cellspacing:</h4>
    <table border="1">
    <tr>
      <td>First</td>
      <td>Row</td>
    </tr>
    <tr>
      <td>Second</td>
      <td>Row</td>
    </tr>
    </table>

    <h4>With cellspacing="0":</h4>
    <table border="1" cellspacing="0">
    <tr>
      <td>First</td>
      <td>Row</td>
    </tr>
    <tr>
      <td>Second</td>
      <td>Row</td>
    </tr>
    </table>

    <h4>With cellspacing="10":</h4>
    <table border="1" cellspacing="10">
    <tr>
      <td>First</td>
      <td>Row</td>
    </tr>
    <tr>
      <td>Second</td>
      <td>Row</td>
    </tr>
    </table>

    </body>
    </html>

    HTML Table Tags

    Tag
    Description
    Defines a table
    Defines a header cell in a table
    Defines a row in a table
    Defines a cell in a table
    Defines a table caption
    Specifies a group of one or more columns in a table for formatting
    Specifies column properties for each column within a <colgroup> element
    Groups the header content in a table
    Groups the body content in a table
    Groups the footer content in a table



2 comments:

  1. Very nice article! I'm Preeti, I write for educational blogs. I make a collection of wonderful educational blogs from where I could take inspiration for writing. This article really inspires me though it is a little different from my domain but nonetheless it is a good writing. I sometime write for a education site blogs
    www.clearexam.ac.in Let me know your thoughts if I could contribute to your blog too.

    ReplyDelete